Skip to content

Commit cee5a8e

Browse files
authored
Merge pull request #282 from Instabug/8.3-release
8.3.0 release
2 parents 3eaba8d + 5c87032 commit cee5a8e

File tree

75 files changed

+952
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+952
-313
lines changed

android/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ android {
2020
}
2121
lintOptions {
2222
warning 'InvalidPackage'
23+
abortOnError true
24+
// SuppressLint WrongConstant was used to suppress errors when using arrays of ints to represent annotations.
2325
}
2426
}
2527

2628
dependencies {
2729
implementation 'com.facebook.react:react-native:+'
28-
api ('com.instabug.library:instabug:8.2.2.0'){
30+
api ('com.instabug.library:instabug:8.3.0.0'){
2931
exclude group: 'com.android.support:appcompat-v7'
3032
}
3133
}

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 154 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.instabug.reactlibrary;
22

3+
import android.annotation.SuppressLint;
34
import android.app.Application;
45
import android.net.Uri;
56
import android.os.Handler;
67
import android.os.Looper;
78
import android.util.Log;
89

910
import com.facebook.react.bridge.Arguments;
11+
import com.facebook.react.bridge.Promise;
1012
import com.facebook.react.bridge.ReactApplicationContext;
1113
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1214
import com.facebook.react.bridge.ReactMethod;
@@ -51,6 +53,7 @@
5153
import com.instabug.library.visualusersteps.State;
5254

5355
import com.instabug.reactlibrary.utils.ArrayUtil;
56+
import com.instabug.reactlibrary.utils.ReportUtil;
5457
import com.instabug.reactlibrary.utils.InstabugUtil;
5558
import com.instabug.reactlibrary.utils.MapUtil;
5659
import com.instabug.survey.OnDismissCallback;
@@ -212,6 +215,7 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
212215
private Instabug mInstabug;
213216
private InstabugInvocationEvent invocationEvent;
214217
private InstabugCustomTextPlaceHolder placeHolders;
218+
private Report currentReport;
215219

216220
/**
217221
* Instantiates a new Rn instabug reactnative module.
@@ -259,6 +263,7 @@ public void run() {
259263
* @param invocationMode the invocation mode
260264
* @param invocationOptions the array of invocation options
261265
*/
266+
@SuppressLint("WrongConstant")
262267
@ReactMethod
263268
public void invokeWithInvocationModeAndOptions(String invocationMode, ReadableArray invocationOptions) {
264269

@@ -333,7 +338,7 @@ public void appendTags(ReadableArray tags) {
333338
@ReactMethod
334339
public void setAutoScreenRecordingEnabled(boolean autoScreenRecordingEnabled) {
335340
try {
336-
Instabug.setAutoScreenRecordingEnabled(autoScreenRecordingEnabled);
341+
BugReporting.setAutoScreenRecordingEnabled(autoScreenRecordingEnabled);
337342
} catch (Exception e) {
338343
e.printStackTrace();
339344
}
@@ -401,10 +406,9 @@ public void setExtendedBugReportMode(String extendedBugReportMode) {
401406
public void setViewHierarchyEnabled(boolean enabled) {
402407
try {
403408
if (enabled) {
404-
Instabug.setViewHierarchyState(Feature.State.ENABLED);
409+
BugReporting.setViewHierarchyState(Feature.State.ENABLED);
405410
} else {
406-
407-
Instabug.setViewHierarchyState(Feature.State.DISABLED);
411+
BugReporting.setViewHierarchyState(Feature.State.DISABLED);
408412
}
409413
} catch (Exception e) {
410414
e.printStackTrace();
@@ -452,7 +456,8 @@ public void setFileAttachment(String fileUri, String fileNameWithExtension) {
452456
@ReactMethod
453457
public void sendJSCrash(String exceptionObject) {
454458
try {
455-
sendJSCrashByReflection(exceptionObject, false);
459+
JSONObject jsonObject = new JSONObject(exceptionObject);
460+
sendJSCrashByReflection(jsonObject, false, null);
456461
} catch (Exception e) {
457462
e.printStackTrace();
458463
}
@@ -466,7 +471,8 @@ public void sendJSCrash(String exceptionObject) {
466471
@ReactMethod
467472
public void sendHandledJSCrash(String exceptionObject) {
468473
try {
469-
sendJSCrashByReflection(exceptionObject, true);
474+
JSONObject jsonObject = new JSONObject(exceptionObject);
475+
sendJSCrashByReflection(jsonObject, true, null);
470476
} catch (Exception e) {
471477
e.printStackTrace();
472478
}
@@ -490,23 +496,20 @@ public void setCrashReportingEnabled(boolean isEnabled) {
490496
}
491497
}
492498

493-
private void sendJSCrashByReflection(String exceptionObject, boolean isHandled) {
499+
private void sendJSCrashByReflection(JSONObject exceptionObject, boolean isHandled, Report report) {
494500
try {
495-
JSONObject newJSONObject = new JSONObject(exceptionObject);
496-
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class);
501+
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class, Report.class);
497502
if (method != null) {
498-
method.invoke(null, newJSONObject, isHandled);
503+
method.invoke(null, exceptionObject, isHandled, currentReport);
504+
currentReport = null;
499505
}
500506
} catch (ClassNotFoundException e) {
501507
e.printStackTrace();
502-
} catch (InvocationTargetException e) {
503-
e.printStackTrace();
504508
} catch (IllegalAccessException e) {
505509
e.printStackTrace();
506-
} catch (JSONException e) {
510+
} catch (InvocationTargetException e) {
507511
e.printStackTrace();
508512
}
509-
510513
}
511514

512515
/**
@@ -1185,25 +1188,144 @@ public void onInvoke() {
11851188
*/
11861189
@ReactMethod
11871190
public void setPreSendingHandler(final Callback preSendingHandler) {
1191+
Report.OnReportCreatedListener listener = new Report.OnReportCreatedListener() {
1192+
@Override
1193+
public void onReportCreated(Report report) {
1194+
WritableMap reportParam = Arguments.createMap();
1195+
reportParam.putArray("tagsArray", convertArrayListToWritableArray(report.getTags()));
1196+
reportParam.putArray("consoleLogs", convertArrayListToWritableArray(report.getConsoleLog()));
1197+
reportParam.putString("userData", report.getUserData());
1198+
reportParam.putMap("userAttributes", convertFromHashMapToWriteableMap(report.getUserAttributes()));
1199+
reportParam.putMap("fileAttachments", convertFromHashMapToWriteableMap(report.getFileAttachments()));
1200+
sendEvent(getReactApplicationContext(), "IBGpreSendingHandler", reportParam);
1201+
currentReport = report;
1202+
}
1203+
};
1204+
1205+
Method method = getMethod(Instabug.class, "onReportSubmitHandler_Private", Report.OnReportCreatedListener.class);
1206+
if (method != null) {
1207+
try {
1208+
method.invoke(null, listener);
1209+
} catch (IllegalAccessException e) {
1210+
e.printStackTrace();
1211+
} catch (InvocationTargetException e) {
1212+
e.printStackTrace();
1213+
}
1214+
}
1215+
}
1216+
1217+
@ReactMethod
1218+
public void appendTagToReport(String tag) {
1219+
if (currentReport != null) {
1220+
currentReport.addTag(tag);
1221+
}
1222+
}
1223+
1224+
@ReactMethod
1225+
public void appendConsoleLogToReport(String consoleLog) {
1226+
if (currentReport != null) {
1227+
currentReport.appendToConsoleLogs(consoleLog);
1228+
}
1229+
}
1230+
1231+
@ReactMethod
1232+
public void setUserAttributeToReport(String key, String value) {
1233+
if (currentReport != null) {
1234+
currentReport.setUserAttribute(key, value);
1235+
}
1236+
}
1237+
1238+
@ReactMethod
1239+
public void logDebugToReport(String log) {
1240+
if (currentReport != null) {
1241+
currentReport.logDebug(log);
1242+
}
1243+
}
1244+
1245+
@ReactMethod
1246+
public void logVerboseToReport(String log) {
1247+
if (currentReport != null) {
1248+
currentReport.logVerbose(log);
1249+
}
1250+
}
1251+
1252+
@ReactMethod
1253+
public void logWarnToReport(String log) {
1254+
if (currentReport != null) {
1255+
currentReport.logWarn(log);
1256+
}
1257+
}
1258+
1259+
@ReactMethod
1260+
public void logErrorToReport(String log) {
1261+
if (currentReport != null) {
1262+
currentReport.logError(log);
1263+
}
1264+
}
1265+
1266+
@ReactMethod
1267+
public void logInfoToReport(String log) {
1268+
if (currentReport != null) {
1269+
currentReport.logInfo(log);
1270+
}
1271+
}
1272+
1273+
@ReactMethod
1274+
public void addFileAttachmentWithURLToReport(String urlString, String fileName) {
1275+
if (currentReport != null) {
1276+
Uri uri = Uri.parse(urlString);
1277+
currentReport.addFileAttachment(uri, fileName);
1278+
}
1279+
}
1280+
1281+
@ReactMethod
1282+
public void addFileAttachmentWithDataToReport(String data, String fileName) {
1283+
if (currentReport != null) {
1284+
currentReport.addFileAttachment(data.getBytes(), fileName);
1285+
}
1286+
}
1287+
1288+
@ReactMethod
1289+
public void submitReport() {
1290+
Method method = getMethod(Instabug.class, "setReport", Report.class);
1291+
if (method != null) {
1292+
try {
1293+
method.invoke(null, currentReport);
1294+
currentReport = null;
1295+
} catch (IllegalAccessException e) {
1296+
e.printStackTrace();
1297+
} catch (InvocationTargetException e) {
1298+
e.printStackTrace();
1299+
}
1300+
}
1301+
}
1302+
1303+
@ReactMethod
1304+
public void getReport(Promise promise) {
11881305
try {
1306+
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "getReport");
1307+
if (method != null) {
1308+
Report report = (Report) method.invoke(null);
1309+
WritableMap reportParam = Arguments.createMap();
1310+
reportParam.putArray("tagsArray", convertArrayListToWritableArray(report.getTags()));
1311+
reportParam.putArray("consoleLogs", ReportUtil.parseConsoleLogs(report.getConsoleLog()));
1312+
reportParam.putString("userData", report.getUserData());
1313+
reportParam.putMap("userAttributes", convertFromHashMapToWriteableMap(report.getUserAttributes()));
1314+
reportParam.putMap("fileAttachments", convertFromHashMapToWriteableMap(report.getFileAttachments()));
1315+
promise.resolve(reportParam);
1316+
currentReport = report;
1317+
}
11891318

1190-
Instabug.onReportSubmitHandler(new Report.OnReportCreatedListener() {
1191-
@Override
1192-
public void onReportCreated(Report report) {
1193-
WritableMap reportParam = Arguments.createMap();
1194-
reportParam.putArray("tagsArray", convertArrayListToWritableArray(report.getTags()));
1195-
reportParam.putArray("consoleLogs", convertArrayListToWritableArray(report.getConsoleLog()));
1196-
reportParam.putString("userData", report.getUserData());
1197-
reportParam.putMap("userAttributes", convertFromHashMapToWriteableMap(report.getUserAttributes()));
1198-
reportParam.putMap("fileAttachments", convertFromHashMapToWriteableMap(report.getFileAttachments()));
1199-
sendEvent(getReactApplicationContext(), "IBGpreSendingHandler", reportParam);
1200-
}
1201-
});
1202-
} catch (java.lang.Exception exception) {
1203-
exception.printStackTrace();
1319+
} catch (ClassNotFoundException e) {
1320+
promise.reject(e);
1321+
} catch (IllegalAccessException e) {
1322+
promise.reject(e);
1323+
} catch (InvocationTargetException e) {
1324+
promise.reject(e);
12041325
}
12051326
}
12061327

1328+
12071329
private WritableMap convertFromHashMapToWriteableMap(HashMap hashMap) {
12081330
WritableMap writableMap = new WritableNativeMap();
12091331
for(int i = 0; i < hashMap.size(); i++) {
@@ -1427,14 +1549,11 @@ public void setReproStepsMode(String reproStepsMode) {
14271549
case ENABLED_WITH_NO_SCREENSHOTS:
14281550
Instabug.setReproStepsState(State.ENABLED_WITH_NO_SCREENSHOTS);
14291551
break;
1430-
case ENABLED:
1431-
Instabug.setReproStepsState(State.ENABLED);
1432-
break;
14331552
case DISABLED:
14341553
Instabug.setReproStepsState(State.DISABLED);
14351554
break;
14361555
default:
1437-
Instabug.setReproStepsState(State.ENABLED);
1556+
Instabug.setReproStepsState(State.ENABLED_WITH_NO_SCREENSHOTS);
14381557
}
14391558

14401559
} catch (Exception e) {
@@ -1602,6 +1721,7 @@ public void show() {
16021721
Instabug.show();
16031722
}
16041723

1724+
@SuppressLint("WrongConstant")
16051725
@ReactMethod
16061726
public void setReportTypes(ReadableArray types) {
16071727
Object[] objectArray = ArrayUtil.toArray(types);
@@ -1861,6 +1981,7 @@ public void setShouldShowSurveysWelcomeScreen(boolean shouldShow) {
18611981
* @param isEmailRequired set true to make email field required
18621982
* @param actionTypes Bitwise-or of actions
18631983
*/
1984+
@SuppressLint("WrongConstant")
18641985
@ReactMethod
18651986
public void setEmailFieldRequiredForFeatureRequests(boolean isEmailRequired, ReadableArray actionTypes) {
18661987
try {
@@ -1907,6 +2028,7 @@ public void networkLog(String jsonObject) throws JSONException {
19072028
networkLog.setResponseCode(newJSONObject.getInt("responseCode"));
19082029
networkLog.setRequestHeaders(newJSONObject.getString("requestHeaders"));
19092030
networkLog.setResponseHeaders(newJSONObject.getString("responseHeaders"));
2031+
networkLog.setTotalDuration(newJSONObject.getLong("duration"));
19102032
networkLog.insert();
19112033
}
19122034

android/src/main/java/com/instabug/reactlibrary/utils/ArrayUtil.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.facebook.react.bridge.ReadableType;
1111
import com.facebook.react.bridge.WritableArray;
1212

13+
import java.util.ArrayList;
1314
import java.util.Map;
1415

1516
import org.json.JSONArray;
@@ -130,4 +131,15 @@ public static WritableArray toWritableArray(Object[] array) {
130131

131132
return writableArray;
132133
}
133-
}
134+
135+
public static ArrayList<String> parseReadableArrayOfStrings(ReadableArray readableArray) {
136+
ArrayList<String> array = new ArrayList<>();
137+
for (int i = 0; i < readableArray.size(); i++) {
138+
ReadableType type = readableArray.getType(i);
139+
if (type == ReadableType.String) {
140+
array.add(readableArray.getString(i));
141+
}
142+
}
143+
return array;
144+
}
145+
}

android/src/main/java/com/instabug/reactlibrary/utils/InstabugUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ public static Method getMethod(Class clazz, String methodName, Class... paramete
99
for (Method method : methods) {
1010
if (method.getName().equals(methodName) && method.getParameterTypes().length ==
1111
parameterType.length) {
12-
for (int i = 0; i < 2; i++) {
12+
if (parameterType.length == 0) {
13+
method.setAccessible(true);
14+
return method;
15+
}
16+
for (int i = 0; i < parameterType.length; i++) {
1317
if (method.getParameterTypes()[i] == parameterType[i]) {
1418
if (i == method.getParameterTypes().length - 1) {
1519
method.setAccessible(true);

0 commit comments

Comments
 (0)