Skip to content

Commit c9223ca

Browse files
feat: support ignore flag secure on android. (#1412)
* feat: support ignore flag secure on android. --------- Co-authored-by: Andrew Amin <160974398+AndrewAminInstabug@users.noreply.github.com>
1 parent 3e05d88 commit c9223ca

File tree

11 files changed

+88
-30
lines changed

11 files changed

+88
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## [15.0.2](https://github.com/Instabug/Instabug-React-Native/compare/v15.0.1...v15.0.2)
3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v15.1.0...dev)
4+
5+
### Added
6+
7+
- Add support for ignoreFlagSecure to bypass SDK screenshot security protocols on Android. ([#1394](https://github.com/Instabug/Instabug-React-Native/pull/1394))
48

59
- Rollout support for network spans. ([#1427](https://github.com/Instabug/Instabug-React-Native/pull/1427))
610

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class RNInstabug {
1919

2020
private static RNInstabug instance;
2121

22-
private RNInstabug() {}
22+
private RNInstabug() {
23+
}
2324

2425

2526
public static RNInstabug getInstance() {
@@ -36,14 +37,13 @@ public static RNInstabug getInstance() {
3637
/**
3738
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
3839
*
39-
* @param application The application context.
40+
* @param application The application context.
4041
* @param applicationToken The app's identifying token, available on your dashboard.
41-
* @param logLevel The level of detail in logs that you want to print.
42-
* <p>Pick one of the log levels described in {@link LogLevel}.
43-
* default logLevel is {@link LogLevel#ERROR}</p>
44-
* @param InvocationEvent The events that trigger the SDK's user interface.
45-
* Choose from the available events listed in {@link InstabugInvocationEvent}.
46-
*
42+
* @param logLevel The level of detail in logs that you want to print.
43+
* <p>Pick one of the log levels described in {@link LogLevel}.
44+
* default logLevel is {@link LogLevel#ERROR}</p>
45+
* @param InvocationEvent The events that trigger the SDK's user interface.
46+
* Choose from the available events listed in {@link InstabugInvocationEvent}.
4747
* @example <p>Here's an example usage: </p>
4848
* <blockquote><pre>
4949
* RNInstabug.getInstance().init(
@@ -59,17 +59,24 @@ public void init(
5959
@NonNull Application application,
6060
@NonNull String applicationToken,
6161
int logLevel,
62+
Boolean ignoreSecureFlag,
6263
@NonNull InstabugInvocationEvent... InvocationEvent
63-
) {
64+
) {
6465
try {
6566

6667
setBaseUrlForDeprecationLogs();
6768
setCurrentPlatform();
6869

69-
new Instabug.Builder(application, applicationToken)
70+
Instabug.Builder builder = new Instabug.Builder(application, applicationToken)
7071
.setInvocationEvents(InvocationEvent)
71-
.setSdkDebugLogsLevel(logLevel)
72-
.build();
72+
.setSdkDebugLogsLevel(logLevel);
73+
74+
if (ignoreSecureFlag != null) {
75+
builder.ignoreFlagSecure(ignoreSecureFlag);
76+
}
77+
78+
builder.build();
79+
7380

7481
// Temporarily disabling APM hot launches
7582
APM.setHotAppLaunchEnabled(false);
@@ -80,15 +87,13 @@ public void init(
8087
}
8188

8289

83-
8490
/**
8591
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
8692
*
87-
* @param application The application context.
93+
* @param application The application context.
8894
* @param applicationToken The app's identifying token, available on your dashboard.
89-
* @param invocationEvent The events that trigger the SDK's user interface.
90-
* Choose from the available events listed in {@link InstabugInvocationEvent}.
91-
*
95+
* @param invocationEvent The events that trigger the SDK's user interface.
96+
* Choose from the available events listed in {@link InstabugInvocationEvent}.
9297
* @example <p>Here's an example usage: </p>
9398
* <blockquote><pre>
9499
* RNInstabug.getInstance().init(
@@ -104,7 +109,7 @@ public void init(
104109
@NonNull String applicationToken,
105110
@NonNull InstabugInvocationEvent... invocationEvent
106111
) {
107-
init(application, applicationToken, LogLevel.ERROR, invocationEvent);
112+
init(application, applicationToken, LogLevel.ERROR,null, invocationEvent);
108113
}
109114

110115
@VisibleForTesting
@@ -160,6 +165,7 @@ public static class Builder {
160165
* The events that trigger the SDK's user interface.
161166
*/
162167
private InstabugInvocationEvent[] invocationEvents;
168+
private Boolean ignoreFlagSecure;
163169

164170

165171
/**
@@ -210,6 +216,16 @@ public Builder setCodePushVersion(String codePushVersion) {
210216
return this;
211217
}
212218

219+
/**
220+
* Sets flag to override SDK screenshot security behavior.
221+
*
222+
* @param ignoreFlagSecure flag to override SDK screenshot security behavior.
223+
*/
224+
public Builder ignoreFlagSecure(boolean ignoreFlagSecure) {
225+
this.ignoreFlagSecure = ignoreFlagSecure;
226+
return this;
227+
}
228+
213229
/**
214230
* Sets the invocation triggering events for the SDK's user interface
215231
*
@@ -237,6 +253,10 @@ public void build() {
237253
instabugBuilder.setCodePushVersion(codePushVersion);
238254
}
239255

256+
if (ignoreFlagSecure != null) {
257+
instabugBuilder.ignoreFlagSecure(ignoreFlagSecure);
258+
}
259+
240260
instabugBuilder.build();
241261

242262
// Temporarily disabling APM hot launches

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public void init(
148148
final ReadableArray invocationEventValues,
149149
final String logLevel,
150150
final boolean useNativeNetworkInterception,
151-
@Nullable final String codePushVersion
151+
@Nullable final String codePushVersion,
152+
final ReadableMap map
152153
) {
153154
MainThreadHandler.runOnMainThread(new Runnable() {
154155
@Override
@@ -166,6 +167,10 @@ public void run() {
166167
.setInvocationEvents(invocationEvents)
167168
.setLogLevel(parsedLogLevel);
168169

170+
if (map!=null&&map.hasKey("ignoreFlagSecure")) {
171+
builder.ignoreFlagSecure(map.getBoolean("ignoreFlagSecure"));
172+
}
173+
169174
if (codePushVersion != null) {
170175
if (Instabug.isBuilt()) {
171176
Instabug.setCodePushVersion(codePushVersion);

android/src/test/java/com/instabug/reactlibrary/RNInstabugTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.instabug.reactlibrary.util.GlobalMocks.reflected;
55
import static org.junit.Assert.assertEquals;
66
import static org.mockito.ArgumentMatchers.any;
7+
import static org.mockito.ArgumentMatchers.anyBoolean;
78
import static org.mockito.ArgumentMatchers.anyInt;
89
import static org.mockito.Mockito.mock;
910
import static org.mockito.Mockito.mockConstruction;
@@ -62,18 +63,20 @@ public void testInitWithLogLevel() {
6263
// Initializes Instabug with the correct token
6364
assertEquals(token, actualToken);
6465
when(mock.setSdkDebugLogsLevel(anyInt())).thenReturn(mock);
66+
when(mock.ignoreFlagSecure(anyBoolean())).thenReturn(mock);
6567
when(mock.setInvocationEvents(any())).thenReturn(mock);
6668
});
6769

68-
sut.init(mContext, token, logLevel, invocationEvents);
70+
sut.init(mContext, token, logLevel, true, invocationEvents);
6971

7072
Instabug.Builder builder = mInstabugBuilder.constructed().get(0);
7173

7274
// Here we check that it has changed to verbose value of the `logLevel` property
7375
verify(builder).setSdkDebugLogsLevel(LogLevel.VERBOSE);
7476
verify(builder).setInvocationEvents(invocationEvents);
75-
verify(builder).build();
77+
verify(builder).ignoreFlagSecure(true);
7678

79+
verify(builder).build();
7780

7881

7982
verify(sut).setBaseUrlForDeprecationLogs();
@@ -95,7 +98,7 @@ public void testInitWithoutLogLevel() {
9598

9699
sut.init(mContext, token, invocationEvents);
97100

98-
verify(sut).init(mContext, token, defaultLogLevel, invocationEvents);
101+
verify(sut).init(mContext, token, defaultLogLevel, null,invocationEvents);
99102
mInstabugBuilder.close();
100103
}
101104

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ - (void)testInit {
7575

7676
OCMStub([mock setCodePushVersion:codePushVersion]);
7777

78-
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion];
78+
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion
79+
options:nil
80+
];
7981
OCMVerify([mock setCodePushVersion:codePushVersion]);
8082

8183
OCMVerify([self.mRNInstabug initWithToken:appToken invocationEvents:floatingButtonInvocationEvent debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception]);
@@ -610,18 +612,18 @@ - (void) testIsW3CaughtHeaderEnabled {
610612

611613
- (void)testEnableAutoMasking {
612614
id mock = OCMClassMock([Instabug class]);
613-
615+
614616
NSArray *autoMaskingTypes = [NSArray arrayWithObjects:
615617
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionLabels],
616618
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionTextInputs],
617619
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMedia],
618620
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMaskNothing],
619621
nil];
620-
622+
621623
OCMStub([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
622-
624+
623625
[self.instabugBridge enableAutoMasking:autoMaskingTypes];
624-
626+
625627
OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
626628
}
627629

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
- (void)setEnabled:(BOOL)isEnabled;
2828

29-
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion;
29+
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion
30+
options:(nullable NSDictionary *)options;
3031

3132
- (void)setCodePushVersion:(NSString *)version;
3233

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ - (dispatch_queue_t)methodQueue {
4141
invocationEvents:(NSArray *)invocationEventsArray
4242
debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel
4343
useNativeNetworkInterception:(BOOL)useNativeNetworkInterception
44-
codePushVersion:(NSString *)codePushVersion) {
44+
codePushVersion:(NSString *)codePushVersion
45+
options:(nullable NSDictionary *)options
46+
) {
4547
IBGInvocationEvent invocationEvents = 0;
4648

4749
for (NSNumber *boxedValue in invocationEventsArray) {

src/models/InstabugConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export interface InstabugConfig {
1919
*/
2020
codePushVersion?: string;
2121

22+
/**
23+
* An optional flag to override SDK screenshot security behavior.
24+
*/
25+
ignoreAndroidSecureFlag?: boolean;
26+
2227
/**
2328
* An optional network interception mode, this determines whether network interception
2429
* is done in the JavaScript side or in the native Android and iOS SDK side.

src/modules/Instabug.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ const initializeNativeInstabug = (config: InstabugConfig) => {
273273
shouldEnableNativeInterception &&
274274
config.networkInterceptionMode === NetworkInterceptionMode.native,
275275
config.codePushVersion,
276+
config.ignoreAndroidSecureFlag != null
277+
? {
278+
ignoreAndroidSecureFlag: config.ignoreAndroidSecureFlag,
279+
}
280+
: undefined,
276281
);
277282
};
278283

src/native/NativeInstabug.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export interface InstabugNativeModule extends NativeModule {
2626
debugLogsLevel: LogLevel,
2727
useNativeNetworkInterception: boolean,
2828
codePushVersion?: string,
29+
options?: {
30+
ignoreAndroidSecureFlag?: boolean;
31+
},
2932
): void;
3033
show(): void;
3134

0 commit comments

Comments
 (0)