Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tive-private into gradle-fix-+-typescript

# Conflicts:
#	android/build.gradle
#	index.js
#	link_gradle.js
#	modules/CrashReporting.js
  • Loading branch information
alyezz committed May 9, 2019
2 parents 3eaba8d + 8de88fc commit 0f4f416
Show file tree
Hide file tree
Showing 74 changed files with 951 additions and 312 deletions.
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ android {
}
lintOptions {
warning 'InvalidPackage'
abortOnError true
// SuppressLint WrongConstant was used to suppress errors when using arrays of ints to represent annotations.
}
}

dependencies {
implementation 'com.facebook.react:react-native:+'
api ('com.instabug.library:instabug:8.2.2.0'){
api ('com.instabug.library:instabug:8.3.0.0'){
exclude group: 'com.android.support:appcompat-v7'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.instabug.reactlibrary;

import android.annotation.SuppressLint;
import android.app.Application;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
Expand Down Expand Up @@ -51,6 +53,7 @@
import com.instabug.library.visualusersteps.State;

import com.instabug.reactlibrary.utils.ArrayUtil;
import com.instabug.reactlibrary.utils.ReportUtil;
import com.instabug.reactlibrary.utils.InstabugUtil;
import com.instabug.reactlibrary.utils.MapUtil;
import com.instabug.survey.OnDismissCallback;
Expand Down Expand Up @@ -212,6 +215,7 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
private Instabug mInstabug;
private InstabugInvocationEvent invocationEvent;
private InstabugCustomTextPlaceHolder placeHolders;
private Report currentReport;

/**
* Instantiates a new Rn instabug reactnative module.
Expand Down Expand Up @@ -259,6 +263,7 @@ public void run() {
* @param invocationMode the invocation mode
* @param invocationOptions the array of invocation options
*/
@SuppressLint("WrongConstant")
@ReactMethod
public void invokeWithInvocationModeAndOptions(String invocationMode, ReadableArray invocationOptions) {

Expand Down Expand Up @@ -333,7 +338,7 @@ public void appendTags(ReadableArray tags) {
@ReactMethod
public void setAutoScreenRecordingEnabled(boolean autoScreenRecordingEnabled) {
try {
Instabug.setAutoScreenRecordingEnabled(autoScreenRecordingEnabled);
BugReporting.setAutoScreenRecordingEnabled(autoScreenRecordingEnabled);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -401,10 +406,9 @@ public void setExtendedBugReportMode(String extendedBugReportMode) {
public void setViewHierarchyEnabled(boolean enabled) {
try {
if (enabled) {
Instabug.setViewHierarchyState(Feature.State.ENABLED);
BugReporting.setViewHierarchyState(Feature.State.ENABLED);
} else {

Instabug.setViewHierarchyState(Feature.State.DISABLED);
BugReporting.setViewHierarchyState(Feature.State.DISABLED);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -452,7 +456,8 @@ public void setFileAttachment(String fileUri, String fileNameWithExtension) {
@ReactMethod
public void sendJSCrash(String exceptionObject) {
try {
sendJSCrashByReflection(exceptionObject, false);
JSONObject jsonObject = new JSONObject(exceptionObject);
sendJSCrashByReflection(jsonObject, false, null);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -466,7 +471,8 @@ public void sendJSCrash(String exceptionObject) {
@ReactMethod
public void sendHandledJSCrash(String exceptionObject) {
try {
sendJSCrashByReflection(exceptionObject, true);
JSONObject jsonObject = new JSONObject(exceptionObject);
sendJSCrashByReflection(jsonObject, true, null);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -490,23 +496,20 @@ public void setCrashReportingEnabled(boolean isEnabled) {
}
}

private void sendJSCrashByReflection(String exceptionObject, boolean isHandled) {
private void sendJSCrashByReflection(JSONObject exceptionObject, boolean isHandled, Report report) {
try {
JSONObject newJSONObject = new JSONObject(exceptionObject);
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class);
Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class, Report.class);
if (method != null) {
method.invoke(null, newJSONObject, isHandled);
method.invoke(null, exceptionObject, isHandled, currentReport);
currentReport = null;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (InvocationTargetException e) {
e.printStackTrace();
}

}

/**
Expand Down Expand Up @@ -1185,25 +1188,144 @@ public void onInvoke() {
*/
@ReactMethod
public void setPreSendingHandler(final Callback preSendingHandler) {
Report.OnReportCreatedListener listener = new Report.OnReportCreatedListener() {
@Override
public void onReportCreated(Report report) {
WritableMap reportParam = Arguments.createMap();
reportParam.putArray("tagsArray", convertArrayListToWritableArray(report.getTags()));
reportParam.putArray("consoleLogs", convertArrayListToWritableArray(report.getConsoleLog()));
reportParam.putString("userData", report.getUserData());
reportParam.putMap("userAttributes", convertFromHashMapToWriteableMap(report.getUserAttributes()));
reportParam.putMap("fileAttachments", convertFromHashMapToWriteableMap(report.getFileAttachments()));
sendEvent(getReactApplicationContext(), "IBGpreSendingHandler", reportParam);
currentReport = report;
}
};

Method method = getMethod(Instabug.class, "onReportSubmitHandler_Private", Report.OnReportCreatedListener.class);
if (method != null) {
try {
method.invoke(null, listener);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}

@ReactMethod
public void appendTagToReport(String tag) {
if (currentReport != null) {
currentReport.addTag(tag);
}
}

@ReactMethod
public void appendConsoleLogToReport(String consoleLog) {
if (currentReport != null) {
currentReport.appendToConsoleLogs(consoleLog);
}
}

@ReactMethod
public void setUserAttributeToReport(String key, String value) {
if (currentReport != null) {
currentReport.setUserAttribute(key, value);
}
}

@ReactMethod
public void logDebugToReport(String log) {
if (currentReport != null) {
currentReport.logDebug(log);
}
}

@ReactMethod
public void logVerboseToReport(String log) {
if (currentReport != null) {
currentReport.logVerbose(log);
}
}

@ReactMethod
public void logWarnToReport(String log) {
if (currentReport != null) {
currentReport.logWarn(log);
}
}

@ReactMethod
public void logErrorToReport(String log) {
if (currentReport != null) {
currentReport.logError(log);
}
}

@ReactMethod
public void logInfoToReport(String log) {
if (currentReport != null) {
currentReport.logInfo(log);
}
}

@ReactMethod
public void addFileAttachmentWithURLToReport(String urlString, String fileName) {
if (currentReport != null) {
Uri uri = Uri.parse(urlString);
currentReport.addFileAttachment(uri, fileName);
}
}

@ReactMethod
public void addFileAttachmentWithDataToReport(String data, String fileName) {
if (currentReport != null) {
currentReport.addFileAttachment(data.getBytes(), fileName);
}
}

@ReactMethod
public void submitReport() {
Method method = getMethod(Instabug.class, "setReport", Report.class);
if (method != null) {
try {
method.invoke(null, currentReport);
currentReport = null;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}

@ReactMethod
public void getReport(Promise promise) {
try {
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "getReport");
if (method != null) {
Report report = (Report) method.invoke(null);
WritableMap reportParam = Arguments.createMap();
reportParam.putArray("tagsArray", convertArrayListToWritableArray(report.getTags()));
reportParam.putArray("consoleLogs", ReportUtil.parseConsoleLogs(report.getConsoleLog()));
reportParam.putString("userData", report.getUserData());
reportParam.putMap("userAttributes", convertFromHashMapToWriteableMap(report.getUserAttributes()));
reportParam.putMap("fileAttachments", convertFromHashMapToWriteableMap(report.getFileAttachments()));
promise.resolve(reportParam);
currentReport = report;
}

Instabug.onReportSubmitHandler(new Report.OnReportCreatedListener() {
@Override
public void onReportCreated(Report report) {
WritableMap reportParam = Arguments.createMap();
reportParam.putArray("tagsArray", convertArrayListToWritableArray(report.getTags()));
reportParam.putArray("consoleLogs", convertArrayListToWritableArray(report.getConsoleLog()));
reportParam.putString("userData", report.getUserData());
reportParam.putMap("userAttributes", convertFromHashMapToWriteableMap(report.getUserAttributes()));
reportParam.putMap("fileAttachments", convertFromHashMapToWriteableMap(report.getFileAttachments()));
sendEvent(getReactApplicationContext(), "IBGpreSendingHandler", reportParam);
}
});
} catch (java.lang.Exception exception) {
exception.printStackTrace();
} catch (ClassNotFoundException e) {
promise.reject(e);
} catch (IllegalAccessException e) {
promise.reject(e);
} catch (InvocationTargetException e) {
promise.reject(e);
}
}


private WritableMap convertFromHashMapToWriteableMap(HashMap hashMap) {
WritableMap writableMap = new WritableNativeMap();
for(int i = 0; i < hashMap.size(); i++) {
Expand Down Expand Up @@ -1427,14 +1549,11 @@ public void setReproStepsMode(String reproStepsMode) {
case ENABLED_WITH_NO_SCREENSHOTS:
Instabug.setReproStepsState(State.ENABLED_WITH_NO_SCREENSHOTS);
break;
case ENABLED:
Instabug.setReproStepsState(State.ENABLED);
break;
case DISABLED:
Instabug.setReproStepsState(State.DISABLED);
break;
default:
Instabug.setReproStepsState(State.ENABLED);
Instabug.setReproStepsState(State.ENABLED_WITH_NO_SCREENSHOTS);
}

} catch (Exception e) {
Expand Down Expand Up @@ -1602,6 +1721,7 @@ public void show() {
Instabug.show();
}

@SuppressLint("WrongConstant")
@ReactMethod
public void setReportTypes(ReadableArray types) {
Object[] objectArray = ArrayUtil.toArray(types);
Expand Down Expand Up @@ -1861,6 +1981,7 @@ public void setShouldShowSurveysWelcomeScreen(boolean shouldShow) {
* @param isEmailRequired set true to make email field required
* @param actionTypes Bitwise-or of actions
*/
@SuppressLint("WrongConstant")
@ReactMethod
public void setEmailFieldRequiredForFeatureRequests(boolean isEmailRequired, ReadableArray actionTypes) {
try {
Expand Down Expand Up @@ -1907,6 +2028,7 @@ public void networkLog(String jsonObject) throws JSONException {
networkLog.setResponseCode(newJSONObject.getInt("responseCode"));
networkLog.setRequestHeaders(newJSONObject.getString("requestHeaders"));
networkLog.setResponseHeaders(newJSONObject.getString("responseHeaders"));
networkLog.setTotalDuration(newJSONObject.getLong("duration"));
networkLog.insert();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.bridge.WritableArray;

import java.util.ArrayList;
import java.util.Map;

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

return writableArray;
}
}

public static ArrayList<String> parseReadableArrayOfStrings(ReadableArray readableArray) {
ArrayList<String> array = new ArrayList<>();
for (int i = 0; i < readableArray.size(); i++) {
ReadableType type = readableArray.getType(i);
if (type == ReadableType.String) {
array.add(readableArray.getString(i));
}
}
return array;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ public static Method getMethod(Class clazz, String methodName, Class... paramete
for (Method method : methods) {
if (method.getName().equals(methodName) && method.getParameterTypes().length ==
parameterType.length) {
for (int i = 0; i < 2; i++) {
if (parameterType.length == 0) {
method.setAccessible(true);
return method;
}
for (int i = 0; i < parameterType.length; i++) {
if (method.getParameterTypes()[i] == parameterType[i]) {
if (i == method.getParameterTypes().length - 1) {
method.setAccessible(true);
Expand Down
Loading

0 comments on commit 0f4f416

Please sign in to comment.