This repository was archived by the owner on Dec 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathCrashReportingApi.java
More file actions
81 lines (68 loc) · 3.03 KB
/
CrashReportingApi.java
File metadata and controls
81 lines (68 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.instabug.flutter.modules;
import static com.instabug.crash.CrashReporting.getFingerprintObject;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.instabug.crash.CrashReporting;
import com.instabug.crash.models.IBGNonFatalException;
import com.instabug.flutter.generated.CrashReportingPigeon;
import com.instabug.flutter.util.ArgsRegistry;
import com.instabug.flutter.util.Reflection;
import com.instabug.library.Feature;
import org.json.JSONObject;
import java.lang.reflect.Method;
import java.util.Map;
import io.flutter.plugin.common.BinaryMessenger;
public class CrashReportingApi implements CrashReportingPigeon.CrashReportingHostApi {
private final String TAG = CrashReportingApi.class.getName();
public static void init(BinaryMessenger messenger) {
final CrashReportingApi api = new CrashReportingApi();
CrashReportingPigeon.CrashReportingHostApi.setup(messenger, api);
}
@Override
public void setEnabled(@NonNull Boolean isEnabled) {
if (isEnabled) {
CrashReporting.setState(Feature.State.ENABLED);
} else {
CrashReporting.setState(Feature.State.DISABLED);
}
}
@Override
public void send(@NonNull String jsonCrash, @NonNull Boolean isHandled) {
try {
final JSONObject exceptionObject = new JSONObject(jsonCrash);
Method method = Reflection.getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException",
JSONObject.class, boolean.class);
if (method != null) {
method.invoke(null, exceptionObject, isHandled);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void sendNonFatalError(@NonNull String jsonCrash, @Nullable Map<String, String> userAttributes, @Nullable String fingerprint, @NonNull String nonFatalExceptionLevel) {
try {
Method method = Reflection.getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class,
Map.class, JSONObject.class, IBGNonFatalException.Level.class);
final JSONObject exceptionObject = new JSONObject(jsonCrash);
JSONObject fingerprintObj = null;
if (fingerprint != null) {
fingerprintObj = getFingerprintObject(fingerprint);
}
IBGNonFatalException.Level nonFatalExceptionLevelType = ArgsRegistry.nonFatalExceptionLevel.get(nonFatalExceptionLevel);
if (method != null) {
method.invoke(null, exceptionObject, true, userAttributes, fingerprintObj, nonFatalExceptionLevelType);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void setNDKEnabled(@NonNull Boolean isEnabled) {
if (isEnabled) {
CrashReporting.setNDKCrashesState(Feature.State.ENABLED);
} else {
CrashReporting.setNDKCrashesState(Feature.State.DISABLED);
}
}
}