Skip to content

Commit 7549dd0

Browse files
ahmedAlaaInstabugabdelhamid-f-nassera7medev
committed
feat: add more crash scenarios to example app (#1131)
* feat(example): add nested complex views (#1111) Jira ID: MOB-13737 * fix hybrid mode code push version init (#1108) * chore(android): ignore jetbrains ide run configurations (#1110) Jira ID: MOB-13736 * ci: migrate macos machines to m1 (#1114) * feat: support identify user by id (#1115) Jira ID: MOB-13746 * ci: replace d11 cluster url in UploadSourcemaps (#1122) * fix(android): resolve private views through UI manager directly (#1121) * feat: support switching to native network interception (#1120) * feat(example): Add more sdk crashes buttons * chore(android): ignore jetbrains ide run configurations (#1110) Jira ID: MOB-13736 * feat(example): Add more sdk crashes buttons * fix dev merge issue * feat_add_crash_buttons * feat_add_crash_buttons * feat_add_crash_buttons * fix: PlatformListTile typo name --------- Co-authored-by: Abdelhamid Nasser <[email protected]> Co-authored-by: Ahmed Mahmoud <[email protected]> Co-authored-by: AbdElHamid Nasser <[email protected]>
1 parent b66416e commit 7549dd0

File tree

10 files changed

+422
-23
lines changed

10 files changed

+422
-23
lines changed

examples/default/android/app/src/main/java/com/instabug/react/example/MainApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public boolean getUseDeveloperSupport() {
2121

2222
@Override
2323
protected List<ReactPackage> getPackages() {
24-
@SuppressWarnings("UnnecessaryLocalVariable")
2524
List<ReactPackage> packages = new PackageList(this).getPackages();
2625
// Packages that cannot be autolinked yet can be added manually here, for example:
27-
// packages.add(new MyReactNativePackage());
26+
packages.add(new RNInstabugExampleReactnativePackage());
2827
return packages;
2928
}
3029

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.instabug.react.example;
2+
3+
import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod;
4+
5+
import com.facebook.react.bridge.Promise;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
8+
import com.facebook.react.bridge.ReactMethod;
9+
import com.instabug.crash.CrashReporting;
10+
import com.instabug.crash.models.IBGNonFatalException;
11+
import com.instabug.library.Feature;
12+
import com.instabug.reactlibrary.RNInstabugReactnativeModule;
13+
import com.instabug.reactlibrary.utils.MainThreadHandler;
14+
15+
import org.json.JSONObject;
16+
17+
import java.lang.reflect.InvocationTargetException;
18+
import java.lang.reflect.Method;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Random;
22+
23+
import javax.annotation.Nonnull;
24+
import javax.annotation.Nullable;
25+
26+
public class RNInstabugExampleCrashReportingModule extends ReactContextBaseJavaModule {
27+
28+
public RNInstabugExampleCrashReportingModule(ReactApplicationContext reactApplicationContext) {
29+
super(reactApplicationContext);
30+
}
31+
32+
@Nonnull
33+
@Override
34+
public String getName() {
35+
return "CrashReportingExampleModule";
36+
}
37+
38+
@ReactMethod
39+
public void sendNativeNonFatal(final String exceptionObject) {
40+
final IBGNonFatalException exception = new IBGNonFatalException.Builder(new IllegalStateException("Test exception"))
41+
.build();
42+
CrashReporting.report(exception);
43+
44+
}
45+
46+
@ReactMethod
47+
public void sendNativeFatalCrash() {
48+
throw new IllegalStateException("Unhandled IllegalStateException from Instabug Test App");
49+
}
50+
51+
@ReactMethod
52+
public void sendANR() {
53+
try {
54+
Thread.sleep(20000);
55+
} catch (InterruptedException e) {
56+
throw new RuntimeException(e);
57+
}
58+
}
59+
60+
@ReactMethod
61+
public void sendFatalHang() {
62+
try {
63+
Thread.sleep(3000);
64+
} catch (InterruptedException e) {
65+
throw new RuntimeException(e);
66+
}
67+
}
68+
69+
@ReactMethod
70+
public void sendOOM() {
71+
oomCrash();
72+
}
73+
74+
private void oomCrash() {
75+
new Thread(() -> {
76+
List<String> stringList = new ArrayList<>();
77+
for (int i = 0; i < 1_000_000; i++) {
78+
stringList.add(getRandomString(10_000));
79+
}
80+
}).start();
81+
}
82+
83+
private String getRandomString(int length) {
84+
List<Character> charset = new ArrayList<>();
85+
for (char ch = 'a'; ch <= 'z'; ch++) {
86+
charset.add(ch);
87+
}
88+
for (char ch = 'A'; ch <= 'Z'; ch++) {
89+
charset.add(ch);
90+
}
91+
for (char ch = '0'; ch <= '9'; ch++) {
92+
charset.add(ch);
93+
}
94+
95+
StringBuilder randomString = new StringBuilder();
96+
Random random = new Random();
97+
for (int i = 0; i < length; i++) {
98+
char randomChar = charset.get(random.nextInt(charset.size()));
99+
randomString.append(randomChar);
100+
}
101+
102+
return randomString.toString();
103+
}
104+
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.instabug.react.example;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.ReactPackage;
6+
import com.facebook.react.bridge.NativeModule;
7+
import com.facebook.react.bridge.ReactApplicationContext;
8+
import com.facebook.react.uimanager.ViewManager;
9+
import com.instabug.reactlibrary.RNInstabugAPMModule;
10+
import com.instabug.reactlibrary.RNInstabugBugReportingModule;
11+
import com.instabug.reactlibrary.RNInstabugCrashReportingModule;
12+
import com.instabug.reactlibrary.RNInstabugFeatureRequestsModule;
13+
import com.instabug.reactlibrary.RNInstabugReactnativeModule;
14+
import com.instabug.reactlibrary.RNInstabugRepliesModule;
15+
import com.instabug.reactlibrary.RNInstabugSessionReplayModule;
16+
import com.instabug.reactlibrary.RNInstabugSurveysModule;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
public class RNInstabugExampleReactnativePackage implements ReactPackage {
23+
24+
private static final String TAG = RNInstabugExampleReactnativePackage.class.getSimpleName();
25+
26+
public RNInstabugExampleReactnativePackage() {}
27+
28+
@NonNull
29+
@Override
30+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
31+
List<NativeModule> modules = new ArrayList<>();
32+
modules.add(new RNInstabugExampleCrashReportingModule(reactContext));
33+
return modules;
34+
}
35+
36+
@NonNull
37+
@Override
38+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
39+
return Collections.emptyList();
40+
}
41+
}

examples/default/ios/InstabugExample.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
1313
20E556262AC55766007416B1 /* InstabugSessionReplayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 20E556252AC55766007416B1 /* InstabugSessionReplayTests.m */; };
1414
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
15+
C3C8CCF379347A4DF9D2A39D /* CrashReportingExampleModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C8C24386310A3120006604 /* CrashReportingExampleModule.m */; };
1516
CC3DF88E2A1DFC9A003E9914 /* InstabugCrashReportingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF8852A1DFC99003E9914 /* InstabugCrashReportingTests.m */; };
1617
CC3DF88F2A1DFC9A003E9914 /* InstabugBugReportingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF8862A1DFC99003E9914 /* InstabugBugReportingTests.m */; };
1718
CC3DF8902A1DFC9A003E9914 /* InstabugSampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF8872A1DFC99003E9914 /* InstabugSampleTests.m */; };
@@ -51,6 +52,8 @@
5152
9A3D962AB03F97E25566779F /* Pods-InstabugExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InstabugExample.debug.xcconfig"; path = "Target Support Files/Pods-InstabugExample/Pods-InstabugExample.debug.xcconfig"; sourceTree = "<group>"; };
5253
BAED0D0441A708AE2390E153 /* libPods-InstabugExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InstabugExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5354
BD54B44E2DF85672BB2D4DEE /* Pods-InstabugExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InstabugExample.release.xcconfig"; path = "Target Support Files/Pods-InstabugExample/Pods-InstabugExample.release.xcconfig"; sourceTree = "<group>"; };
55+
C3C8C24386310A3120006604 /* CrashReportingExampleModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CrashReportingExampleModule.m; sourceTree = "<group>"; };
56+
C3C8C784EADC037C5A752B94 /* CrashReportingExampleModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrashReportingExampleModule.h; sourceTree = "<group>"; };
5457
CC3DF8852A1DFC99003E9914 /* InstabugCrashReportingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugCrashReportingTests.m; sourceTree = "<group>"; };
5558
CC3DF8862A1DFC99003E9914 /* InstabugBugReportingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugBugReportingTests.m; sourceTree = "<group>"; };
5659
CC3DF8872A1DFC99003E9914 /* InstabugSampleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugSampleTests.m; sourceTree = "<group>"; };
@@ -121,6 +124,7 @@
121124
13B07FB61A68108700A75B9A /* Info.plist */,
122125
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
123126
13B07FB71A68108700A75B9A /* main.m */,
127+
C3C8C1DDCEA91410F27A3683 /* native */,
124128
);
125129
name = InstabugExample;
126130
sourceTree = "<group>";
@@ -177,6 +181,15 @@
177181
path = Pods;
178182
sourceTree = "<group>";
179183
};
184+
C3C8C1DDCEA91410F27A3683 /* native */ = {
185+
isa = PBXGroup;
186+
children = (
187+
C3C8C784EADC037C5A752B94 /* CrashReportingExampleModule.h */,
188+
C3C8C24386310A3120006604 /* CrashReportingExampleModule.m */,
189+
);
190+
path = native;
191+
sourceTree = "<group>";
192+
};
180193
/* End PBXGroup section */
181194

182195
/* Begin PBXNativeTarget section */
@@ -463,6 +476,7 @@
463476
files = (
464477
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
465478
13B07FC11A68108700A75B9A /* main.m in Sources */,
479+
C3C8CCF379347A4DF9D2A39D /* CrashReportingExampleModule.m in Sources */,
466480
);
467481
runOnlyForDeploymentPostprocessing = 0;
468482
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <Foundation/Foundation.h>
2+
#import <React/RCTBridgeModule.h>
3+
#import <React/RCTEventEmitter.h>
4+
5+
@interface CrashReportingExampleModule : RCTEventEmitter <RCTBridgeModule>
6+
7+
- (void)sendNativeNonFatal;
8+
- (void)sendNativeFatalCrash;
9+
- (void)sendFatalHang;
10+
- (void)sendOOM;
11+
12+
@end
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#import "CrashReportingExampleModule.h"
2+
#import <Instabug/IBGCrashReporting.h>
3+
#import <Instabug/Instabug.h>
4+
5+
@interface CrashReportingExampleModule()
6+
@property (nonatomic, strong) NSMutableArray *oomBelly;
7+
@property (nonatomic, strong) dispatch_queue_t serialQueue;
8+
@end
9+
10+
@implementation CrashReportingExampleModule
11+
12+
- (instancetype)init {
13+
self = [super init];
14+
if (self) {
15+
self.serialQueue = dispatch_queue_create("QUEUE>SERIAL", DISPATCH_QUEUE_SERIAL);
16+
}
17+
return self;
18+
}
19+
20+
- (dispatch_queue_t)methodQueue {
21+
return dispatch_get_main_queue();
22+
}
23+
24+
+ (BOOL)requiresMainQueueSetup
25+
{
26+
return NO;
27+
}
28+
29+
30+
- (void)oomCrash {
31+
dispatch_async(self.serialQueue, ^{
32+
self.oomBelly = [NSMutableArray array];
33+
[UIApplication.sharedApplication beginBackgroundTaskWithName:@"OOM Crash" expirationHandler:nil];
34+
while (true) {
35+
unsigned long dinnerLength = 1024 * 1024 * 10;
36+
char *dinner = malloc(sizeof(char) * dinnerLength);
37+
for (int i=0; i < dinnerLength; i++)
38+
{
39+
//write to each byte ensure that the memory pages are actually allocated
40+
dinner[i] = '0';
41+
}
42+
NSData *plate = [NSData dataWithBytesNoCopy:dinner length:dinnerLength freeWhenDone:YES];
43+
[self.oomBelly addObject:plate];
44+
}
45+
});
46+
}
47+
48+
RCT_EXPORT_MODULE(CrashReportingExampleModule)
49+
50+
51+
RCT_EXPORT_METHOD(sendNativeNonFatal) {
52+
IBGNonFatalException *nonFatalException = [IBGCrashReporting exception:[NSException exceptionWithName:@"native Handled NS Exception" reason:@"Test iOS Handled Crash" userInfo:@{@"Key": @"Value"}]];
53+
54+
[nonFatalException report];
55+
}
56+
57+
RCT_EXPORT_METHOD(sendNativeFatalCrash) {
58+
NSException *exception = [NSException exceptionWithName:@"native Unhandled NS Exception" reason:@"Test iOS Unhandled Crash" userInfo:nil];
59+
@throw exception;
60+
}
61+
RCT_EXPORT_METHOD(sendFatalHang) {
62+
[NSThread sleepForTimeInterval:3.0f];
63+
}
64+
65+
RCT_EXPORT_METHOD(sendOOM) {
66+
[self oomCrash];
67+
}
68+
69+
@synthesize description;
70+
71+
@synthesize hash;
72+
73+
@synthesize superclass;
74+
75+
@end
76+
77+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { PropsWithChildren } from 'react';
2+
3+
import { Box, HStack, Pressable, Text } from 'native-base';
4+
import { Platform } from 'react-native';
5+
6+
interface PlatformListTileProps extends PropsWithChildren {
7+
title: string;
8+
onPress?: () => void;
9+
platform?: 'ios' | 'android';
10+
}
11+
12+
export const PlatformListTile: React.FC<PlatformListTileProps> = ({
13+
title,
14+
onPress,
15+
platform,
16+
children,
17+
}) => {
18+
if (Platform.OS === platform || !platform) {
19+
return (
20+
<Pressable
21+
onPress={onPress}
22+
p="4"
23+
rounded="2"
24+
shadow="1"
25+
borderBottomWidth="1"
26+
borderColor="coolGray.300"
27+
bg="coolGray.100"
28+
_pressed={{ bg: 'coolGray.200' }}>
29+
<HStack justifyContent="space-between" alignItems="center">
30+
<Text>{title}</Text>
31+
<Box width={160}>{children}</Box>
32+
</HStack>
33+
</Pressable>
34+
);
35+
}
36+
return null;
37+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { NativeModule } from 'react-native';
2+
3+
import { NativeExampleModules } from './NativePackage';
4+
5+
export interface CrashReportingExampleNativeModule extends NativeModule {
6+
sendNativeNonFatal(): Promise<void>;
7+
sendNativeFatalCrash(): Promise<void>;
8+
sendFatalHang(): Promise<void>;
9+
sendANR(): Promise<void>;
10+
sendOOM(): Promise<void>;
11+
}
12+
13+
export const NativeExampleCrashReporting = NativeExampleModules.CrashReportingExampleModule;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NativeModules as ReactNativeModules } from 'react-native';
2+
3+
import type { CrashReportingExampleNativeModule } from './NativeCrashReporting';
4+
5+
export interface InstabugExampleNativePackage {
6+
CrashReportingExampleModule: CrashReportingExampleNativeModule;
7+
}
8+
9+
export const NativeExampleModules = ReactNativeModules as InstabugExampleNativePackage;

0 commit comments

Comments
 (0)