-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <38096011+abdelhamid-f-nasser@users.noreply.github.com> Co-authored-by: Ahmed Mahmoud <68241710+a7medev@users.noreply.github.com> Co-authored-by: AbdElHamid Nasser <anasser@instabug.com>
- Loading branch information
1 parent
bf31031
commit be4715e
Showing
10 changed files
with
316 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...d/app/src/main/java/com/instabug/react/example/RNInstabugExampleCrashReportingModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.instabug.react.example; | ||
|
||
import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.instabug.crash.CrashReporting; | ||
import com.instabug.crash.models.IBGNonFatalException; | ||
import com.instabug.library.Feature; | ||
import com.instabug.reactlibrary.RNInstabugReactnativeModule; | ||
import com.instabug.reactlibrary.utils.MainThreadHandler; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
public class RNInstabugExampleCrashReportingModule extends ReactContextBaseJavaModule { | ||
|
||
public RNInstabugExampleCrashReportingModule(ReactApplicationContext reactApplicationContext) { | ||
super(reactApplicationContext); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getName() { | ||
return "CrashReportingExampleModule"; | ||
} | ||
|
||
@ReactMethod | ||
public void sendNativeNonFatal(final String exceptionObject) { | ||
final IBGNonFatalException exception = new IBGNonFatalException.Builder(new IllegalStateException("Test exception")) | ||
.build(); | ||
CrashReporting.report(exception); | ||
|
||
} | ||
|
||
@ReactMethod | ||
public void sendNativeFatalCrash() { | ||
throw new IllegalStateException("Unhandled IllegalStateException from Instabug Test App"); | ||
} | ||
|
||
@ReactMethod | ||
public void sendANR() { | ||
try { | ||
Thread.sleep(20000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@ReactMethod | ||
public void sendFatalHang() { | ||
try { | ||
Thread.sleep(3000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@ReactMethod | ||
public void sendOOM() { | ||
oomCrash(); | ||
} | ||
|
||
private void oomCrash() { | ||
new Thread(() -> { | ||
List<String> stringList = new ArrayList<>(); | ||
for (int i = 0; i < 1_000_000; i++) { | ||
stringList.add(getRandomString(10_000)); | ||
} | ||
}).start(); | ||
} | ||
|
||
private String getRandomString(int length) { | ||
List<Character> charset = new ArrayList<>(); | ||
for (char ch = 'a'; ch <= 'z'; ch++) { | ||
charset.add(ch); | ||
} | ||
for (char ch = 'A'; ch <= 'Z'; ch++) { | ||
charset.add(ch); | ||
} | ||
for (char ch = '0'; ch <= '9'; ch++) { | ||
charset.add(ch); | ||
} | ||
|
||
StringBuilder randomString = new StringBuilder(); | ||
Random random = new Random(); | ||
for (int i = 0; i < length; i++) { | ||
char randomChar = charset.get(random.nextInt(charset.size())); | ||
randomString.append(randomChar); | ||
} | ||
|
||
return randomString.toString(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...oid/app/src/main/java/com/instabug/react/example/RNInstabugExampleReactnativePackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.instabug.react.example; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.instabug.reactlibrary.RNInstabugAPMModule; | ||
import com.instabug.reactlibrary.RNInstabugBugReportingModule; | ||
import com.instabug.reactlibrary.RNInstabugCrashReportingModule; | ||
import com.instabug.reactlibrary.RNInstabugFeatureRequestsModule; | ||
import com.instabug.reactlibrary.RNInstabugReactnativeModule; | ||
import com.instabug.reactlibrary.RNInstabugRepliesModule; | ||
import com.instabug.reactlibrary.RNInstabugSessionReplayModule; | ||
import com.instabug.reactlibrary.RNInstabugSurveysModule; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RNInstabugExampleReactnativePackage implements ReactPackage { | ||
|
||
private static final String TAG = RNInstabugExampleReactnativePackage.class.getSimpleName(); | ||
|
||
public RNInstabugExampleReactnativePackage() {} | ||
|
||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new RNInstabugExampleCrashReportingModule(reactContext)); | ||
return modules; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
|
||
@interface CrashReportingExampleModule : RCTEventEmitter <RCTBridgeModule> | ||
|
||
- (void)sendNativeNonFatal; | ||
- (void)sendNativeFatalCrash; | ||
- (void)sendFatalHang; | ||
- (void)sendOOM; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#import "CrashReportingExampleModule.h" | ||
#import <Instabug/IBGCrashReporting.h> | ||
#import <Instabug/Instabug.h> | ||
|
||
@interface CrashReportingExampleModule() | ||
@property (nonatomic, strong) NSMutableArray *oomBelly; | ||
@property (nonatomic, strong) dispatch_queue_t serialQueue; | ||
@end | ||
|
||
@implementation CrashReportingExampleModule | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
self.serialQueue = dispatch_queue_create("QUEUE>SERIAL", DISPATCH_QUEUE_SERIAL); | ||
} | ||
return self; | ||
} | ||
|
||
- (dispatch_queue_t)methodQueue { | ||
return dispatch_get_main_queue(); | ||
} | ||
|
||
+ (BOOL)requiresMainQueueSetup | ||
{ | ||
return NO; | ||
} | ||
|
||
|
||
- (void)oomCrash { | ||
dispatch_async(self.serialQueue, ^{ | ||
self.oomBelly = [NSMutableArray array]; | ||
[UIApplication.sharedApplication beginBackgroundTaskWithName:@"OOM Crash" expirationHandler:nil]; | ||
while (true) { | ||
unsigned long dinnerLength = 1024 * 1024 * 10; | ||
char *dinner = malloc(sizeof(char) * dinnerLength); | ||
for (int i=0; i < dinnerLength; i++) | ||
{ | ||
//write to each byte ensure that the memory pages are actually allocated | ||
dinner[i] = '0'; | ||
} | ||
NSData *plate = [NSData dataWithBytesNoCopy:dinner length:dinnerLength freeWhenDone:YES]; | ||
[self.oomBelly addObject:plate]; | ||
} | ||
}); | ||
} | ||
|
||
RCT_EXPORT_MODULE(CrashReportingExampleModule) | ||
|
||
|
||
RCT_EXPORT_METHOD(sendNativeNonFatal) { | ||
IBGNonFatalException *nonFatalException = [IBGCrashReporting exception:[NSException exceptionWithName:@"native Handled NS Exception" reason:@"Test iOS Handled Crash" userInfo:@{@"Key": @"Value"}]]; | ||
|
||
[nonFatalException report]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(sendNativeFatalCrash) { | ||
NSException *exception = [NSException exceptionWithName:@"native Unhandled NS Exception" reason:@"Test iOS Unhandled Crash" userInfo:nil]; | ||
@throw exception; | ||
} | ||
RCT_EXPORT_METHOD(sendFatalHang) { | ||
[NSThread sleepForTimeInterval:3.0f]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(sendOOM) { | ||
[self oomCrash]; | ||
} | ||
|
||
@synthesize description; | ||
|
||
@synthesize hash; | ||
|
||
@synthesize superclass; | ||
|
||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
|
||
import { Box, HStack, Pressable, Text } from 'native-base'; | ||
import { Platform } from 'react-native'; | ||
|
||
interface PlatformListTileProps extends PropsWithChildren { | ||
title: string; | ||
onPress?: () => void; | ||
platform?: 'ios' | 'android'; | ||
} | ||
|
||
export const PlatformListTile: React.FC<PlatformListTileProps> = ({ | ||
title, | ||
onPress, | ||
platform, | ||
children, | ||
}) => { | ||
if (Platform.OS === platform || !platform) { | ||
return ( | ||
<Pressable | ||
onPress={onPress} | ||
p="4" | ||
rounded="2" | ||
shadow="1" | ||
borderBottomWidth="1" | ||
borderColor="coolGray.300" | ||
bg="coolGray.100" | ||
_pressed={{ bg: 'coolGray.200' }}> | ||
<HStack justifyContent="space-between" alignItems="center"> | ||
<Text>{title}</Text> | ||
<Box width={160}>{children}</Box> | ||
</HStack> | ||
</Pressable> | ||
); | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { NativeModule } from 'react-native'; | ||
|
||
import { NativeExampleModules } from './NativePackage'; | ||
|
||
export interface CrashReportingExampleNativeModule extends NativeModule { | ||
sendNativeNonFatal(): Promise<void>; | ||
sendNativeFatalCrash(): Promise<void>; | ||
sendFatalHang(): Promise<void>; | ||
sendANR(): Promise<void>; | ||
sendOOM(): Promise<void>; | ||
} | ||
|
||
export const NativeExampleCrashReporting = NativeExampleModules.CrashReportingExampleModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NativeModules as ReactNativeModules } from 'react-native'; | ||
|
||
import type { CrashReportingExampleNativeModule } from './NativeCrashReporting'; | ||
|
||
export interface InstabugExampleNativePackage { | ||
CrashReportingExampleModule: CrashReportingExampleNativeModule; | ||
} | ||
|
||
export const NativeExampleModules = ReactNativeModules as InstabugExampleNativePackage; |
Oops, something went wrong.