Skip to content

Commit f9c5bd8

Browse files
ahmedAlaaInstabugAyaMahmoud148
authored andcommitted
run automask in main thread
1 parent 8e2e776 commit f9c5bd8

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

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

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void setEnabled(final boolean isEnabled) {
120120
@Override
121121
public void run() {
122122
try {
123-
if(isEnabled)
123+
if (isEnabled)
124124
Instabug.enable();
125125
else
126126
Instabug.disable();
@@ -133,10 +133,11 @@ public void run() {
133133

134134
/**
135135
* Initializes the SDK.
136-
* @param token The token that identifies the app. You can find it on your dashboard.
136+
*
137+
* @param token The token that identifies the app. You can find it on your dashboard.
137138
* @param invocationEventValues The events that invoke the SDK's UI.
138-
* @param logLevel The level of detail in logs that you want to print.
139-
* @param codePushVersion The Code Push version to be used for all reports.
139+
* @param logLevel The level of detail in logs that you want to print.
140+
* @param codePushVersion The Code Push version to be used for all reports.
140141
*/
141142
@ReactMethod
142143
public void init(
@@ -162,8 +163,8 @@ public void run() {
162163
.setInvocationEvents(invocationEvents)
163164
.setLogLevel(parsedLogLevel);
164165

165-
if(codePushVersion != null) {
166-
if(Instabug.isBuilt()) {
166+
if (codePushVersion != null) {
167+
if (Instabug.isBuilt()) {
167168
Instabug.setCodePushVersion(codePushVersion);
168169
} else {
169170
builder.setCodePushVersion(codePushVersion);
@@ -329,7 +330,7 @@ public void run() {
329330
*
330331
* @param userEmail User's default email
331332
* @param userName Username.
332-
* @param userId User's ID
333+
* @param userId User's ID
333334
*/
334335
@ReactMethod
335336
public void identifyUser(
@@ -749,15 +750,15 @@ public void addFileAttachmentWithDataToReport(String data, String fileName) {
749750

750751
private WritableMap convertFromHashMapToWriteableMap(HashMap hashMap) {
751752
WritableMap writableMap = new WritableNativeMap();
752-
for(int i = 0; i < hashMap.size(); i++) {
753+
for (int i = 0; i < hashMap.size(); i++) {
753754
Object key = hashMap.keySet().toArray()[i];
754755
Object value = hashMap.get(key);
755-
writableMap.putString((String) key,(String) value);
756+
writableMap.putString((String) key, (String) value);
756757
}
757758
return writableMap;
758759
}
759760

760-
private static JSONObject objectToJSONObject(Object object){
761+
private static JSONObject objectToJSONObject(Object object) {
761762
Object json = null;
762763
JSONObject jsonObject = null;
763764
try {
@@ -774,13 +775,12 @@ private static JSONObject objectToJSONObject(Object object){
774775
private WritableArray convertArrayListToWritableArray(List arrayList) {
775776
WritableArray writableArray = new WritableNativeArray();
776777

777-
for(int i = 0; i < arrayList.size(); i++) {
778+
for (int i = 0; i < arrayList.size(); i++) {
778779
Object object = arrayList.get(i);
779780

780-
if(object instanceof String) {
781+
if (object instanceof String) {
781782
writableArray.pushString((String) object);
782-
}
783-
else {
783+
} else {
784784
JSONObject jsonObject = objectToJSONObject(object);
785785
writableArray.pushMap((WritableMap) jsonObject);
786786
}
@@ -836,7 +836,7 @@ public void run() {
836836
* Shows the welcome message in a specific mode.
837837
*
838838
* @param welcomeMessageMode An enum to set the welcome message mode to
839-
* live, or beta.
839+
* live, or beta.
840840
*/
841841
@ReactMethod
842842
public void showWelcomeMessageWithMode(final String welcomeMessageMode) {
@@ -858,7 +858,7 @@ public void run() {
858858
* Sets the welcome message mode to live, beta or disabled.
859859
*
860860
* @param welcomeMessageMode An enum to set the welcome message mode to
861-
* live, beta or disabled.
861+
* live, beta or disabled.
862862
*/
863863
@ReactMethod
864864
public void setWelcomeMessageMode(final String welcomeMessageMode) {
@@ -993,7 +993,6 @@ public void run() {
993993
* Reports that the screen name been changed (Current View).
994994
*
995995
* @param screenName string containing the screen name
996-
*
997996
*/
998997
@ReactMethod
999998
public void reportCurrentViewChange(final String screenName) {
@@ -1016,7 +1015,6 @@ public void run() {
10161015
* Reports that the screen has been changed (Repro Steps) the screen sent to this method will be the 'current view' on the dashboard
10171016
*
10181017
* @param screenName string containing the screen name
1019-
*
10201018
*/
10211019
@ReactMethod
10221020
public void reportScreenChange(final String screenName) {
@@ -1026,7 +1024,7 @@ public void run() {
10261024
try {
10271025
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "reportScreenChange", Bitmap.class, String.class);
10281026
if (method != null) {
1029-
method.invoke(null , null, screenName);
1027+
method.invoke(null, null, screenName);
10301028
}
10311029
} catch (Exception e) {
10321030
e.printStackTrace();
@@ -1120,7 +1118,7 @@ public void removeFeatureFlags(final ReadableArray featureFlags) {
11201118
@Override
11211119
public void run() {
11221120
try {
1123-
ArrayList<String> stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags);
1121+
ArrayList<String> stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags);
11241122
Instabug.removeFeatureFlag(stringArray);
11251123
} catch (Exception e) {
11261124
e.printStackTrace();
@@ -1156,11 +1154,12 @@ public void run() {
11561154
}
11571155
});
11581156
}
1157+
11591158
/**
11601159
* Register a listener for W3C flags value change
11611160
*/
11621161
@ReactMethod
1163-
public void registerW3CFlagsChangeListener(){
1162+
public void registerW3CFlagsChangeListener() {
11641163

11651164
MainThreadHandler.runOnMainThread(new Runnable() {
11661165
@Override
@@ -1177,8 +1176,7 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11771176
sendEvent(Constants.IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK, params);
11781177
}
11791178
});
1180-
}
1181-
catch (Exception e) {
1179+
} catch (Exception e) {
11821180
e.printStackTrace();
11831181
}
11841182

@@ -1189,18 +1187,17 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11891187

11901188

11911189
/**
1192-
* Get first time Value of W3ExternalTraceID flag
1190+
* Get first time Value of W3ExternalTraceID flag
11931191
*/
11941192
@ReactMethod
1195-
public void isW3ExternalTraceIDEnabled(Promise promise){
1193+
public void isW3ExternalTraceIDEnabled(Promise promise) {
11961194

11971195
MainThreadHandler.runOnMainThread(new Runnable() {
11981196
@Override
11991197
public void run() {
12001198
try {
12011199
promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_EXTERNAL_TRACE_ID));
1202-
}
1203-
catch (Exception e) {
1200+
} catch (Exception e) {
12041201
e.printStackTrace();
12051202
promise.resolve(false);
12061203
}
@@ -1212,18 +1209,17 @@ public void run() {
12121209

12131210

12141211
/**
1215-
* Get first time Value of W3ExternalGeneratedHeader flag
1212+
* Get first time Value of W3ExternalGeneratedHeader flag
12161213
*/
12171214
@ReactMethod
1218-
public void isW3ExternalGeneratedHeaderEnabled(Promise promise){
1215+
public void isW3ExternalGeneratedHeaderEnabled(Promise promise) {
12191216

12201217
MainThreadHandler.runOnMainThread(new Runnable() {
12211218
@Override
12221219
public void run() {
12231220
try {
12241221
promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_ATTACHING_GENERATED_HEADER));
1225-
}
1226-
catch (Exception e) {
1222+
} catch (Exception e) {
12271223
e.printStackTrace();
12281224
promise.resolve(false);
12291225
}
@@ -1234,18 +1230,17 @@ public void run() {
12341230
}
12351231

12361232
/**
1237-
* Get first time Value of W3CaughtHeader flag
1233+
* Get first time Value of W3CaughtHeader flag
12381234
*/
12391235
@ReactMethod
1240-
public void isW3CaughtHeaderEnabled(Promise promise){
1236+
public void isW3CaughtHeaderEnabled(Promise promise) {
12411237

12421238
MainThreadHandler.runOnMainThread(new Runnable() {
12431239
@Override
12441240
public void run() {
12451241
try {
12461242
promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_ATTACHING_CAPTURED_HEADER));
1247-
}
1248-
catch (Exception e) {
1243+
} catch (Exception e) {
12491244
e.printStackTrace();
12501245
promise.resolve(false);
12511246
}
@@ -1274,21 +1269,29 @@ public Map<String, Object> getConstants() {
12741269

12751270
return constants;
12761271
}
1277-
/**
1272+
1273+
/**
12781274
* Sets the auto mask screenshots types.
1275+
*
12791276
* @param autoMaskingTypes The masking type to be applied.
12801277
*/
12811278
@ReactMethod
12821279
public void enableAutoMasking(@NonNull ReadableArray autoMaskingTypes) {
1283-
int[] autoMassingTypesArray = new int[autoMaskingTypes.size()];
1284-
for (int i=0;i< autoMaskingTypes.size();i++)
1285-
{
1286-
String key = autoMaskingTypes.getString(i);
1287-
1288-
autoMassingTypesArray[i]= ArgsRegistry.autoMaskingTypes.get(key);
1289-
1290-
}
1291-
1292-
Instabug.setAutoMaskScreenshotsTypes(autoMassingTypesArray);
1280+
MainThreadHandler.runOnMainThread(new Runnable() {
1281+
1282+
@Override
1283+
public void run() {
1284+
int[] autoMassingTypesArray = new int[autoMaskingTypes.size()];
1285+
for (int i = 0; i < autoMaskingTypes.size(); i++) {
1286+
String key = autoMaskingTypes.getString(i);
1287+
1288+
autoMassingTypesArray[i] = ArgsRegistry.autoMaskingTypes.get(key);
1289+
1290+
}
1291+
1292+
Instabug.setAutoMaskScreenshotsTypes(autoMassingTypesArray);
1293+
}
1294+
1295+
});
12931296
}
12941297
}

0 commit comments

Comments
 (0)