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