1
1
package com .instabug .reactlibrary ;
2
2
3
+ import android .annotation .SuppressLint ;
3
4
import android .app .Application ;
4
5
import android .net .Uri ;
5
6
import android .os .Handler ;
6
7
import android .os .Looper ;
7
8
import android .util .Log ;
8
9
9
10
import com .facebook .react .bridge .Arguments ;
11
+ import com .facebook .react .bridge .Promise ;
10
12
import com .facebook .react .bridge .ReactApplicationContext ;
11
13
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
12
14
import com .facebook .react .bridge .ReactMethod ;
51
53
import com .instabug .library .visualusersteps .State ;
52
54
53
55
import com .instabug .reactlibrary .utils .ArrayUtil ;
56
+ import com .instabug .reactlibrary .utils .ReportUtil ;
54
57
import com .instabug .reactlibrary .utils .InstabugUtil ;
55
58
import com .instabug .reactlibrary .utils .MapUtil ;
56
59
import com .instabug .survey .OnDismissCallback ;
@@ -212,6 +215,7 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
212
215
private Instabug mInstabug ;
213
216
private InstabugInvocationEvent invocationEvent ;
214
217
private InstabugCustomTextPlaceHolder placeHolders ;
218
+ private Report currentReport ;
215
219
216
220
/**
217
221
* Instantiates a new Rn instabug reactnative module.
@@ -259,6 +263,7 @@ public void run() {
259
263
* @param invocationMode the invocation mode
260
264
* @param invocationOptions the array of invocation options
261
265
*/
266
+ @ SuppressLint ("WrongConstant" )
262
267
@ ReactMethod
263
268
public void invokeWithInvocationModeAndOptions (String invocationMode , ReadableArray invocationOptions ) {
264
269
@@ -333,7 +338,7 @@ public void appendTags(ReadableArray tags) {
333
338
@ ReactMethod
334
339
public void setAutoScreenRecordingEnabled (boolean autoScreenRecordingEnabled ) {
335
340
try {
336
- Instabug .setAutoScreenRecordingEnabled (autoScreenRecordingEnabled );
341
+ BugReporting .setAutoScreenRecordingEnabled (autoScreenRecordingEnabled );
337
342
} catch (Exception e ) {
338
343
e .printStackTrace ();
339
344
}
@@ -401,10 +406,9 @@ public void setExtendedBugReportMode(String extendedBugReportMode) {
401
406
public void setViewHierarchyEnabled (boolean enabled ) {
402
407
try {
403
408
if (enabled ) {
404
- Instabug .setViewHierarchyState (Feature .State .ENABLED );
409
+ BugReporting .setViewHierarchyState (Feature .State .ENABLED );
405
410
} else {
406
-
407
- Instabug .setViewHierarchyState (Feature .State .DISABLED );
411
+ BugReporting .setViewHierarchyState (Feature .State .DISABLED );
408
412
}
409
413
} catch (Exception e ) {
410
414
e .printStackTrace ();
@@ -452,7 +456,8 @@ public void setFileAttachment(String fileUri, String fileNameWithExtension) {
452
456
@ ReactMethod
453
457
public void sendJSCrash (String exceptionObject ) {
454
458
try {
455
- sendJSCrashByReflection (exceptionObject , false );
459
+ JSONObject jsonObject = new JSONObject (exceptionObject );
460
+ sendJSCrashByReflection (jsonObject , false , null );
456
461
} catch (Exception e ) {
457
462
e .printStackTrace ();
458
463
}
@@ -466,7 +471,8 @@ public void sendJSCrash(String exceptionObject) {
466
471
@ ReactMethod
467
472
public void sendHandledJSCrash (String exceptionObject ) {
468
473
try {
469
- sendJSCrashByReflection (exceptionObject , true );
474
+ JSONObject jsonObject = new JSONObject (exceptionObject );
475
+ sendJSCrashByReflection (jsonObject , true , null );
470
476
} catch (Exception e ) {
471
477
e .printStackTrace ();
472
478
}
@@ -490,23 +496,20 @@ public void setCrashReportingEnabled(boolean isEnabled) {
490
496
}
491
497
}
492
498
493
- private void sendJSCrashByReflection (String exceptionObject , boolean isHandled ) {
499
+ private void sendJSCrashByReflection (JSONObject exceptionObject , boolean isHandled , Report report ) {
494
500
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 );
497
502
if (method != null ) {
498
- method .invoke (null , newJSONObject , isHandled );
503
+ method .invoke (null , exceptionObject , isHandled , currentReport );
504
+ currentReport = null ;
499
505
}
500
506
} catch (ClassNotFoundException e ) {
501
507
e .printStackTrace ();
502
- } catch (InvocationTargetException e ) {
503
- e .printStackTrace ();
504
508
} catch (IllegalAccessException e ) {
505
509
e .printStackTrace ();
506
- } catch (JSONException e ) {
510
+ } catch (InvocationTargetException e ) {
507
511
e .printStackTrace ();
508
512
}
509
-
510
513
}
511
514
512
515
/**
@@ -1185,25 +1188,144 @@ public void onInvoke() {
1185
1188
*/
1186
1189
@ ReactMethod
1187
1190
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 ) {
1188
1305
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
+ }
1189
1318
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 );
1204
1325
}
1205
1326
}
1206
1327
1328
+
1207
1329
private WritableMap convertFromHashMapToWriteableMap (HashMap hashMap ) {
1208
1330
WritableMap writableMap = new WritableNativeMap ();
1209
1331
for (int i = 0 ; i < hashMap .size (); i ++) {
@@ -1427,14 +1549,11 @@ public void setReproStepsMode(String reproStepsMode) {
1427
1549
case ENABLED_WITH_NO_SCREENSHOTS :
1428
1550
Instabug .setReproStepsState (State .ENABLED_WITH_NO_SCREENSHOTS );
1429
1551
break ;
1430
- case ENABLED :
1431
- Instabug .setReproStepsState (State .ENABLED );
1432
- break ;
1433
1552
case DISABLED :
1434
1553
Instabug .setReproStepsState (State .DISABLED );
1435
1554
break ;
1436
1555
default :
1437
- Instabug .setReproStepsState (State .ENABLED );
1556
+ Instabug .setReproStepsState (State .ENABLED_WITH_NO_SCREENSHOTS );
1438
1557
}
1439
1558
1440
1559
} catch (Exception e ) {
@@ -1602,6 +1721,7 @@ public void show() {
1602
1721
Instabug .show ();
1603
1722
}
1604
1723
1724
+ @ SuppressLint ("WrongConstant" )
1605
1725
@ ReactMethod
1606
1726
public void setReportTypes (ReadableArray types ) {
1607
1727
Object [] objectArray = ArrayUtil .toArray (types );
@@ -1861,6 +1981,7 @@ public void setShouldShowSurveysWelcomeScreen(boolean shouldShow) {
1861
1981
* @param isEmailRequired set true to make email field required
1862
1982
* @param actionTypes Bitwise-or of actions
1863
1983
*/
1984
+ @ SuppressLint ("WrongConstant" )
1864
1985
@ ReactMethod
1865
1986
public void setEmailFieldRequiredForFeatureRequests (boolean isEmailRequired , ReadableArray actionTypes ) {
1866
1987
try {
@@ -1907,6 +2028,7 @@ public void networkLog(String jsonObject) throws JSONException {
1907
2028
networkLog .setResponseCode (newJSONObject .getInt ("responseCode" ));
1908
2029
networkLog .setRequestHeaders (newJSONObject .getString ("requestHeaders" ));
1909
2030
networkLog .setResponseHeaders (newJSONObject .getString ("responseHeaders" ));
2031
+ networkLog .setTotalDuration (newJSONObject .getLong ("duration" ));
1910
2032
networkLog .insert ();
1911
2033
}
1912
2034
0 commit comments