Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(example): fix fatal hangs and ANR crash buttons #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package com.instabug.react.example;

import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod;

import com.facebook.react.bridge.Promise;
import android.content.Context;
import android.os.Handler;
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.library.Instabug;
import com.instabug.react.example.nativeLibs.CppNativeLib;
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 javax.annotation.Nonnull;
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) {
Expand Down Expand Up @@ -51,20 +42,28 @@ public void sendNativeFatalCrash() {

@ReactMethod
public void sendANR() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
sendHang(20000);
}

@ReactMethod
public void sendFatalHang() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
sendHang(3000);
}

private void sendHang(long duration) {
Context applicationContext = Instabug.getApplicationContext();
if (applicationContext == null)
return;

Handler handler = new Handler(applicationContext.getMainLooper());

handler.post(() -> {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}

@ReactMethod
Expand Down