@@ -182,10 +182,10 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
182
182
}
183
183
184
184
if ( Platform . OS === 'android' ) {
185
- checkNativeInterceptionForAndroid ( config ) ;
185
+ handleInterceptionModeForAndroid ( config ) ;
186
186
config . networkInterceptionMode = NetworkInterceptionMode . javascript ; // Need to enable JS interceptor in all scenarios for Bugs & Crashes network logs
187
187
} else if ( Platform . OS === 'ios' ) {
188
- checkNativeInterceptionForIOS ( config ) ;
188
+ handleInterceptionModeForIOS ( config ) ;
189
189
}
190
190
191
191
if ( config . networkInterceptionMode === NetworkInterceptionMode . javascript ) {
@@ -194,49 +194,64 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
194
194
} ;
195
195
196
196
/**
197
- * Handles the native interception logic for Android.
197
+ * Handles the JS interception logic for Android.
198
198
*/
199
- const checkNativeInterceptionForAndroid = ( config : InstabugConfig ) => {
200
- const { networkInterceptionMode } = config ;
199
+ function handleAndroidJSInterception ( ) {
200
+ if ( isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin ) {
201
+ shouldEnableNativeInterception = true ;
202
+ console . warn (
203
+ InstabugConstants . IBG_APM_TAG + InstabugConstants . SWITCHED_TO_NATIVE_INTERCEPTION_MESSAGE ,
204
+ ) ;
205
+ }
206
+ }
201
207
202
- if ( networkInterceptionMode === NetworkInterceptionMode . javascript ) {
203
- if ( isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin ) {
204
- shouldEnableNativeInterception = true ;
205
- console . warn (
206
- InstabugConstants . IBG_APM_TAG + InstabugConstants . SWITCHED_TO_NATIVE_INTERCEPTION_MESSAGE ,
207
- ) ;
208
+ /**
209
+ * Handles the native interception logic for Android.
210
+ */
211
+ function handleAndroidNativeInterception ( ) {
212
+ if ( isNativeInterceptionFeatureEnabled ) {
213
+ shouldEnableNativeInterception = hasAPMNetworkPlugin ;
214
+ if ( ! hasAPMNetworkPlugin ) {
215
+ console . error ( InstabugConstants . IBG_APM_TAG + InstabugConstants . PLUGIN_NOT_INSTALLED_MESSAGE ) ;
208
216
}
209
217
} else {
210
- if ( isNativeInterceptionFeatureEnabled ) {
211
- shouldEnableNativeInterception = hasAPMNetworkPlugin ;
212
- if ( ! hasAPMNetworkPlugin ) {
213
- console . error (
214
- InstabugConstants . IBG_APM_TAG + InstabugConstants . PLUGIN_NOT_INSTALLED_MESSAGE ,
215
- ) ;
216
- }
218
+ shouldEnableNativeInterception = false ; // rollback to use JS interceptor for APM & Core.
219
+ if ( hasAPMNetworkPlugin ) {
220
+ console . error (
221
+ InstabugConstants . IBG_APM_TAG + InstabugConstants . NATIVE_INTERCEPTION_DISABLED_MESSAGE ,
222
+ ) ;
217
223
} else {
218
- if ( hasAPMNetworkPlugin ) {
219
- console . error (
220
- InstabugConstants . IBG_APM_TAG + InstabugConstants . NATIVE_INTERCEPTION_DISABLED_MESSAGE ,
221
- ) ;
222
- } else {
223
- shouldEnableNativeInterception = false ; // rollback to use JS interceptor for APM & Core.
224
- console . error (
225
- InstabugConstants . IBG_APM_TAG +
226
- InstabugConstants . PLUGIN_NOT_INSTALLED_AND_NATIVE_INTERCEPTION_DISABLED_MESSAGE ,
227
- ) ;
228
- }
224
+ console . error (
225
+ InstabugConstants . IBG_APM_TAG +
226
+ InstabugConstants . PLUGIN_NOT_INSTALLED_AND_NATIVE_INTERCEPTION_DISABLED_MESSAGE ,
227
+ ) ;
229
228
}
230
229
}
230
+ }
231
+
232
+ /**
233
+ * Handles the interception mode logic for Android.
234
+ * By deciding which interception mode should be enabled (Native or JavaScript).
235
+ */
236
+ const handleInterceptionModeForAndroid = ( config : InstabugConfig ) => {
237
+ const { networkInterceptionMode } = config ;
238
+
239
+ if ( networkInterceptionMode === NetworkInterceptionMode . javascript ) {
240
+ handleAndroidJSInterception ( ) ;
241
+ } else {
242
+ handleAndroidNativeInterception ( ) ;
243
+ }
231
244
} ;
232
245
233
246
/**
234
- * Handles the native interception logic for iOS.
247
+ * Handles the interception mode logic for iOS.
248
+ * By deciding which interception mode should be enabled (Native or JavaScript).
235
249
*/
236
- const checkNativeInterceptionForIOS = ( config : InstabugConfig ) => {
250
+ const handleInterceptionModeForIOS = ( config : InstabugConfig ) => {
237
251
if ( config . networkInterceptionMode === NetworkInterceptionMode . native ) {
238
252
if ( isNativeInterceptionFeatureEnabled ) {
239
253
shouldEnableNativeInterception = true ;
254
+ NetworkLogger . setEnabled ( false ) ; // insure JS interceptor is disabled
240
255
} else {
241
256
shouldEnableNativeInterception = false ;
242
257
NetworkLogger . setEnabled ( true ) ; // rollback to JS interceptor
0 commit comments