|
1 | 1 | package com.instabug.react.example; |
2 | 2 |
|
3 | | -import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod; |
4 | | - |
5 | | -import com.facebook.react.bridge.Promise; |
| 3 | +import android.content.Context; |
| 4 | +import android.os.Handler; |
6 | 5 | import com.facebook.react.bridge.ReactApplicationContext; |
7 | 6 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
8 | 7 | import com.facebook.react.bridge.ReactMethod; |
9 | 8 | import com.instabug.crash.CrashReporting; |
10 | 9 | import com.instabug.crash.models.IBGNonFatalException; |
11 | | -import com.instabug.library.Feature; |
| 10 | +import com.instabug.library.Instabug; |
12 | 11 | import com.instabug.react.example.nativeLibs.CppNativeLib; |
13 | | -import com.instabug.reactlibrary.RNInstabugReactnativeModule; |
14 | | -import com.instabug.reactlibrary.utils.MainThreadHandler; |
15 | | - |
16 | | -import org.json.JSONObject; |
17 | 12 |
|
18 | | -import java.lang.reflect.InvocationTargetException; |
19 | | -import java.lang.reflect.Method; |
| 13 | +import javax.annotation.Nonnull; |
20 | 14 | import java.util.ArrayList; |
21 | 15 | import java.util.List; |
22 | 16 | import java.util.Random; |
23 | 17 |
|
24 | | -import javax.annotation.Nonnull; |
25 | | -import javax.annotation.Nullable; |
26 | | - |
27 | 18 | public class RNInstabugExampleCrashReportingModule extends ReactContextBaseJavaModule { |
28 | 19 |
|
29 | 20 | public RNInstabugExampleCrashReportingModule(ReactApplicationContext reactApplicationContext) { |
@@ -51,20 +42,28 @@ public void sendNativeFatalCrash() { |
51 | 42 |
|
52 | 43 | @ReactMethod |
53 | 44 | public void sendANR() { |
54 | | - try { |
55 | | - Thread.sleep(20000); |
56 | | - } catch (InterruptedException e) { |
57 | | - throw new RuntimeException(e); |
58 | | - } |
| 45 | + sendHang(20000); |
59 | 46 | } |
60 | 47 |
|
61 | 48 | @ReactMethod |
62 | 49 | public void sendFatalHang() { |
63 | | - try { |
64 | | - Thread.sleep(3000); |
65 | | - } catch (InterruptedException e) { |
66 | | - throw new RuntimeException(e); |
67 | | - } |
| 50 | + sendHang(3000); |
| 51 | + } |
| 52 | + |
| 53 | + private void sendHang(long duration) { |
| 54 | + Context applicationContext = Instabug.getApplicationContext(); |
| 55 | + if (applicationContext == null) |
| 56 | + return; |
| 57 | + |
| 58 | + Handler handler = new Handler(applicationContext.getMainLooper()); |
| 59 | + |
| 60 | + handler.post(() -> { |
| 61 | + try { |
| 62 | + Thread.sleep(duration); |
| 63 | + } catch (InterruptedException e) { |
| 64 | + throw new RuntimeException(e); |
| 65 | + } |
| 66 | + }); |
68 | 67 | } |
69 | 68 |
|
70 | 69 | @ReactMethod |
|
0 commit comments