diff --git a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java index b56db804d6..428d989f62 100644 --- a/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java +++ b/android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java @@ -17,6 +17,7 @@ import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition; import com.instabug.library.sessionreplay.model.SessionMetadata; import com.instabug.library.ui.onboarding.WelcomeMessage; +import com.instabug.library.MaskingType; import java.util.ArrayList; import java.util.HashMap; @@ -60,6 +61,7 @@ static Map getAll() { putAll(locales); putAll(placeholders); putAll(launchType); + putAll(autoMaskingTypes); }}; } @@ -253,5 +255,10 @@ static Map getAll() { put(SessionMetadata.LaunchType.COLD,"cold"); put(SessionMetadata.LaunchType.WARM,"warm" ); }}; - + public static final ArgsMap autoMaskingTypes = new ArgsMap() {{ + put("labels", MaskingType.LABELS); + put("textInputs", MaskingType.TEXT_INPUTS); + put("media", MaskingType.MEDIA); + put("none", MaskingType.MASK_NOTHING); + }}; } diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 9c901cb7a5..8644dda7c5 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -120,7 +120,7 @@ public void setEnabled(final boolean isEnabled) { @Override public void run() { try { - if(isEnabled) + if (isEnabled) Instabug.enable(); else Instabug.disable(); @@ -133,10 +133,11 @@ public void run() { /** * Initializes the SDK. - * @param token The token that identifies the app. You can find it on your dashboard. + * + * @param token The token that identifies the app. You can find it on your dashboard. * @param invocationEventValues The events that invoke the SDK's UI. - * @param logLevel The level of detail in logs that you want to print. - * @param codePushVersion The Code Push version to be used for all reports. + * @param logLevel The level of detail in logs that you want to print. + * @param codePushVersion The Code Push version to be used for all reports. */ @ReactMethod public void init( @@ -162,8 +163,8 @@ public void run() { .setInvocationEvents(invocationEvents) .setLogLevel(parsedLogLevel); - if(codePushVersion != null) { - if(Instabug.isBuilt()) { + if (codePushVersion != null) { + if (Instabug.isBuilt()) { Instabug.setCodePushVersion(codePushVersion); } else { builder.setCodePushVersion(codePushVersion); @@ -329,7 +330,7 @@ public void run() { * * @param userEmail User's default email * @param userName Username. - * @param userId User's ID + * @param userId User's ID */ @ReactMethod public void identifyUser( @@ -749,15 +750,15 @@ public void addFileAttachmentWithDataToReport(String data, String fileName) { private WritableMap convertFromHashMapToWriteableMap(HashMap hashMap) { WritableMap writableMap = new WritableNativeMap(); - for(int i = 0; i < hashMap.size(); i++) { + for (int i = 0; i < hashMap.size(); i++) { Object key = hashMap.keySet().toArray()[i]; Object value = hashMap.get(key); - writableMap.putString((String) key,(String) value); + writableMap.putString((String) key, (String) value); } return writableMap; } - private static JSONObject objectToJSONObject(Object object){ + private static JSONObject objectToJSONObject(Object object) { Object json = null; JSONObject jsonObject = null; try { @@ -774,13 +775,12 @@ private static JSONObject objectToJSONObject(Object object){ private WritableArray convertArrayListToWritableArray(List arrayList) { WritableArray writableArray = new WritableNativeArray(); - for(int i = 0; i < arrayList.size(); i++) { + for (int i = 0; i < arrayList.size(); i++) { Object object = arrayList.get(i); - if(object instanceof String) { + if (object instanceof String) { writableArray.pushString((String) object); - } - else { + } else { JSONObject jsonObject = objectToJSONObject(object); writableArray.pushMap((WritableMap) jsonObject); } @@ -836,7 +836,7 @@ public void run() { * Shows the welcome message in a specific mode. * * @param welcomeMessageMode An enum to set the welcome message mode to - * live, or beta. + * live, or beta. */ @ReactMethod public void showWelcomeMessageWithMode(final String welcomeMessageMode) { @@ -858,7 +858,7 @@ public void run() { * Sets the welcome message mode to live, beta or disabled. * * @param welcomeMessageMode An enum to set the welcome message mode to - * live, beta or disabled. + * live, beta or disabled. */ @ReactMethod public void setWelcomeMessageMode(final String welcomeMessageMode) { @@ -993,7 +993,6 @@ public void run() { * Reports that the screen name been changed (Current View). * * @param screenName string containing the screen name - * */ @ReactMethod public void reportCurrentViewChange(final String screenName) { @@ -1016,7 +1015,6 @@ public void run() { * Reports that the screen has been changed (Repro Steps) the screen sent to this method will be the 'current view' on the dashboard * * @param screenName string containing the screen name - * */ @ReactMethod public void reportScreenChange(final String screenName) { @@ -1026,7 +1024,7 @@ public void run() { try { Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "reportScreenChange", Bitmap.class, String.class); if (method != null) { - method.invoke(null , null, screenName); + method.invoke(null, null, screenName); } } catch (Exception e) { e.printStackTrace(); @@ -1120,7 +1118,7 @@ public void removeFeatureFlags(final ReadableArray featureFlags) { @Override public void run() { try { - ArrayList stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags); + ArrayList stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags); Instabug.removeFeatureFlag(stringArray); } catch (Exception e) { e.printStackTrace(); @@ -1156,11 +1154,12 @@ public void run() { } }); } + /** * Register a listener for W3C flags value change */ @ReactMethod - public void registerW3CFlagsChangeListener(){ + public void registerW3CFlagsChangeListener() { MainThreadHandler.runOnMainThread(new Runnable() { @Override @@ -1177,8 +1176,7 @@ public void invoke(@NonNull CoreFeaturesState featuresState) { sendEvent(Constants.IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK, params); } }); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } @@ -1189,18 +1187,17 @@ public void invoke(@NonNull CoreFeaturesState featuresState) { /** - * Get first time Value of W3ExternalTraceID flag + * Get first time Value of W3ExternalTraceID flag */ @ReactMethod - public void isW3ExternalTraceIDEnabled(Promise promise){ + public void isW3ExternalTraceIDEnabled(Promise promise) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_EXTERNAL_TRACE_ID)); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); promise.resolve(false); } @@ -1212,18 +1209,17 @@ public void run() { /** - * Get first time Value of W3ExternalGeneratedHeader flag + * Get first time Value of W3ExternalGeneratedHeader flag */ @ReactMethod - public void isW3ExternalGeneratedHeaderEnabled(Promise promise){ + public void isW3ExternalGeneratedHeaderEnabled(Promise promise) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_ATTACHING_GENERATED_HEADER)); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); promise.resolve(false); } @@ -1234,18 +1230,17 @@ public void run() { } /** - * Get first time Value of W3CaughtHeader flag + * Get first time Value of W3CaughtHeader flag */ @ReactMethod - public void isW3CaughtHeaderEnabled(Promise promise){ + public void isW3CaughtHeaderEnabled(Promise promise) { MainThreadHandler.runOnMainThread(new Runnable() { @Override public void run() { try { promise.resolve(InternalCore.INSTANCE._isFeatureEnabled(CoreFeature.W3C_ATTACHING_CAPTURED_HEADER)); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); promise.resolve(false); } @@ -1274,4 +1269,29 @@ public Map getConstants() { return constants; } + + /** + * Sets the auto mask screenshots types. + * + * @param autoMaskingTypes The masking type to be applied. + */ + @ReactMethod + public void enableAutoMasking(@NonNull ReadableArray autoMaskingTypes) { + MainThreadHandler.runOnMainThread(new Runnable() { + + @Override + public void run() { + int[] autoMassingTypesArray = new int[autoMaskingTypes.size()]; + for (int i = 0; i < autoMaskingTypes.size(); i++) { + String key = autoMaskingTypes.getString(i); + + autoMassingTypesArray[i] = ArgsRegistry.autoMaskingTypes.get(key); + + } + + Instabug.setAutoMaskScreenshotsTypes(autoMassingTypesArray); + } + + }); + } } diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java index e8aad5b0c5..7f289b610d 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java @@ -25,6 +25,7 @@ import com.instabug.library.internal.module.InstabugLocale; import com.instabug.library.ui.onboarding.WelcomeMessage; import com.instabug.reactlibrary.utils.MainThreadHandler; +import com.instabug.library.MaskingType; import org.junit.After; import org.junit.Assert; @@ -662,4 +663,17 @@ public void testW3CCaughtHeaderFlag(){ boolean expected=internalAPM._isFeatureEnabled(CoreFeature.W3C_ATTACHING_CAPTURED_HEADER); verify(promise).resolve(expected); } + + @Test + public void testEnableAutoMasking(){ + + String maskLabel = "labels"; + String maskTextInputs = "textInputs"; + String maskMedia = "media"; + String maskNone = "none"; + + rnModule.enableAutoMasking(JavaOnlyArray.of(maskLabel, maskMedia, maskTextInputs,maskNone)); + + mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING)); + } } diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 8744ce4eb8..4dc32729cc 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -608,5 +608,21 @@ - (void) testIsW3CaughtHeaderEnabled { OCMVerify([mock w3CaughtHeaderEnabled]); } +- (void)testEnableAutoMasking { + id mock = OCMClassMock([Instabug class]); + + NSArray *autoMaskingTypes = [NSArray arrayWithObjects: + [NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionLabels], + [NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionTextInputs], + [NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMedia], + [NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMaskNothing], + nil]; + + OCMStub([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]); + + [self.instabugBridge enableAutoMasking:autoMaskingTypes]; + + OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]); +} @end diff --git a/ios/RNInstabug/ArgsRegistry.h b/ios/RNInstabug/ArgsRegistry.h index c7720e38fb..52c1562f78 100644 --- a/ios/RNInstabug/ArgsRegistry.h +++ b/ios/RNInstabug/ArgsRegistry.h @@ -25,5 +25,6 @@ typedef NSDictionary ArgsDictionary; + (ArgsDictionary *) launchType; + (NSDictionary *) placeholders; ++ (ArgsDictionary *)autoMaskingTypes; @end diff --git a/ios/RNInstabug/ArgsRegistry.m b/ios/RNInstabug/ArgsRegistry.m index bc14302ac1..08494b1ddf 100644 --- a/ios/RNInstabug/ArgsRegistry.m +++ b/ios/RNInstabug/ArgsRegistry.m @@ -21,6 +21,8 @@ + (NSMutableDictionary *) getAll { [all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel]; [all addEntriesFromDictionary:ArgsRegistry.placeholders]; [all addEntriesFromDictionary:ArgsRegistry.launchType]; + [all addEntriesFromDictionary:ArgsRegistry.autoMaskingTypes]; + return all; } @@ -249,4 +251,12 @@ + (ArgsDictionary *) launchType { }; } ++ (ArgsDictionary *)autoMaskingTypes { + return @{ + @"labels" : @(IBGAutoMaskScreenshotOptionLabels), + @"textInputs" : @(IBGAutoMaskScreenshotOptionTextInputs), + @"media" : @(IBGAutoMaskScreenshotOptionMedia), + @"none" : @(IBGAutoMaskScreenshotOptionMaskNothing) + }; +} @end diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index bca04ddfd0..a65b8a0fe5 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -138,4 +138,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes; - (void)addFeatureFlags:(NSDictionary *)featureFlagsMap; - (void)removeFeatureFlags:(NSArray *)featureFlags; - (void)removeAllFeatureFlags; +- (void)enableAutoMasking:(NSArray *)autoMaskingTypes; + @end diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index e7ca15600e..38e3ed68d1 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -439,5 +439,16 @@ + (BOOL)requiresMainQueueSetup + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion { return [iOSVersion compare:[UIDevice currentDevice].systemVersion options:NSNumericSearch] == NSOrderedDescending; }; +RCT_EXPORT_METHOD(enableAutoMasking:(NSArray *)autoMaskingTypes) { + IBGAutoMaskScreenshotOption autoMaskingOptions = 0; + + for (NSNumber *event in autoMaskingTypes) { + + autoMaskingOptions |= [event intValue]; + } + + [Instabug setAutoMaskScreenshots: autoMaskingOptions]; + +}; @end diff --git a/ios/RNInstabug/RCTConvert+InstabugEnums.m b/ios/RNInstabug/RCTConvert+InstabugEnums.m index 3e675ca2fa..4cf497c595 100644 --- a/ios/RNInstabug/RCTConvert+InstabugEnums.m +++ b/ios/RNInstabug/RCTConvert+InstabugEnums.m @@ -109,4 +109,10 @@ @implementation RCTConvert (InstabugEnums) integerValue ); +RCT_ENUM_CONVERTER( + IBGAutoMaskScreenshotOption, + ArgsRegistry.autoMaskingTypes, + IBGAutoMaskScreenshotOptionMaskNothing, + integerValue +); @end diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index 91f6c5c127..9d2adb8f8b 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -13,6 +13,7 @@ import Report from '../models/Report'; import { emitter, NativeEvents, NativeInstabug } from '../native/NativeInstabug'; import { registerW3CFlagsListener } from '../utils/FeatureFlags'; import { + AutoMaskingType, ColorTheme, Locale, LogLevel, @@ -678,3 +679,11 @@ export const _registerW3CFlagsChangeListener = ( }); NativeInstabug.registerW3CFlagsChangeListener(); }; + +/** + * Sets the auto mask screenshots types. + * @param autoMaskingTypes The masking type to be applied. + */ +export const enableAutoMasking = (autoMaskingTypes: AutoMaskingType[]) => { + NativeInstabug.enableAutoMasking(autoMaskingTypes); +}; diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts index a4e98e2c86..4d93e84ff4 100644 --- a/src/native/NativeConstants.ts +++ b/src/native/NativeConstants.ts @@ -13,8 +13,8 @@ export type NativeConstants = NativeSdkDebugLogsLevel & NativeLocale & NativeNonFatalErrorLevel & NativeStringKey & - NativeLaunchType; - + NativeLaunchType & + NativeAutoMaskingType; interface NativeSdkDebugLogsLevel { sdkDebugLogsLevelVerbose: any; sdkDebugLogsLevelDebug: any; @@ -195,3 +195,10 @@ interface NativeLaunchType { warm: any; unknown: any; } + +interface NativeAutoMaskingType { + labels: any; + textInputs: any; + media: any; + none: any; +} diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 5f0628ef71..6c4170f86e 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -2,6 +2,7 @@ import { NativeEventEmitter, NativeModule, ProcessedColorValue } from 'react-nat import type Report from '../models/Report'; import type { + AutoMaskingType, ColorTheme, InvocationEvent, Locale, @@ -152,6 +153,7 @@ export interface InstabugNativeModule extends NativeModule { // W3C Feature Flags Listener for Android registerW3CFlagsChangeListener(): void; + enableAutoMasking(autoMaskingTypes: AutoMaskingType[]): void; } export const NativeInstabug = NativeModules.Instabug; diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index 37ffa33ce3..14864351ba 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -241,3 +241,9 @@ export enum LaunchType { */ warm = constants.warm, } +export enum AutoMaskingType { + labels = constants.labels, + textInputs = constants.textInputs, + media = constants.media, + none = constants.none, +} diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 7b3cf2e695..c0655cb775 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -73,6 +73,7 @@ const mockInstabug: InstabugNativeModule = { isW3ExternalGeneratedHeaderEnabled: jest.fn(), isW3CaughtHeaderEnabled: jest.fn(), registerW3CFlagsChangeListener: jest.fn(), + enableAutoMasking: jest.fn(), }; export default mockInstabug;