Skip to content

Commit

Permalink
feat: add more crash scenarios to example app (#1131)
Browse files Browse the repository at this point in the history
* 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
4 people committed Feb 20, 2024
1 parent bf31031 commit be4715e
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public boolean getUseDeveloperSupport() {

@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new RNInstabugExampleReactnativePackage());
return packages;
}

Expand Down
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();
}

}
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();
}
}
14 changes: 14 additions & 0 deletions examples/default/ios/InstabugExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
20E556262AC55766007416B1 /* InstabugSessionReplayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 20E556252AC55766007416B1 /* InstabugSessionReplayTests.m */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
C3C8CCF379347A4DF9D2A39D /* CrashReportingExampleModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C8C24386310A3120006604 /* CrashReportingExampleModule.m */; };
CC3DF88E2A1DFC9A003E9914 /* InstabugCrashReportingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF8852A1DFC99003E9914 /* InstabugCrashReportingTests.m */; };
CC3DF88F2A1DFC9A003E9914 /* InstabugBugReportingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF8862A1DFC99003E9914 /* InstabugBugReportingTests.m */; };
CC3DF8902A1DFC9A003E9914 /* InstabugSampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF8872A1DFC99003E9914 /* InstabugSampleTests.m */; };
Expand Down Expand Up @@ -51,6 +52,8 @@
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>"; };
BAED0D0441A708AE2390E153 /* libPods-InstabugExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InstabugExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
C3C8C24386310A3120006604 /* CrashReportingExampleModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CrashReportingExampleModule.m; sourceTree = "<group>"; };
C3C8C784EADC037C5A752B94 /* CrashReportingExampleModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrashReportingExampleModule.h; sourceTree = "<group>"; };
CC3DF8852A1DFC99003E9914 /* InstabugCrashReportingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugCrashReportingTests.m; sourceTree = "<group>"; };
CC3DF8862A1DFC99003E9914 /* InstabugBugReportingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugBugReportingTests.m; sourceTree = "<group>"; };
CC3DF8872A1DFC99003E9914 /* InstabugSampleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugSampleTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -121,6 +124,7 @@
13B07FB61A68108700A75B9A /* Info.plist */,
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
13B07FB71A68108700A75B9A /* main.m */,
C3C8C1DDCEA91410F27A3683 /* native */,
);
name = InstabugExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -177,6 +181,15 @@
path = Pods;
sourceTree = "<group>";
};
C3C8C1DDCEA91410F27A3683 /* native */ = {
isa = PBXGroup;
children = (
C3C8C784EADC037C5A752B94 /* CrashReportingExampleModule.h */,
C3C8C24386310A3120006604 /* CrashReportingExampleModule.m */,
);
path = native;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -463,6 +476,7 @@
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
C3C8CCF379347A4DF9D2A39D /* CrashReportingExampleModule.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 12 additions & 0 deletions examples/default/ios/native/CrashReportingExampleModule.h
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
77 changes: 77 additions & 0 deletions examples/default/ios/native/CrashReportingExampleModule.m
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


37 changes: 37 additions & 0 deletions examples/default/src/components/PlatformListTile.tsx
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;
};
13 changes: 13 additions & 0 deletions examples/default/src/native/NativeCrashReporting.ts
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;
9 changes: 9 additions & 0 deletions examples/default/src/native/NativePackage.ts
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;
Loading

0 comments on commit be4715e

Please sign in to comment.