@@ -182,10 +182,10 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
182182 }
183183
184184 if ( Platform . OS === 'android' ) {
185- checkNativeInterceptionForAndroid ( config ) ;
185+ handleInterceptionModeForAndroid ( config ) ;
186186 config . networkInterceptionMode = NetworkInterceptionMode . javascript ; // Need to enable JS interceptor in all scenarios for Bugs & Crashes network logs
187187 } else if ( Platform . OS === 'ios' ) {
188- checkNativeInterceptionForIOS ( config ) ;
188+ handleInterceptionModeForIOS ( config ) ;
189189 }
190190
191191 if ( config . networkInterceptionMode === NetworkInterceptionMode . javascript ) {
@@ -194,49 +194,64 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
194194} ;
195195
196196/**
197- * Handles the native interception logic for Android.
197+ * Handles the JS interception logic for Android.
198198 */
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+ }
201207
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 ) ;
208216 }
209217 } 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+ ) ;
217223 } 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+ ) ;
229228 }
230229 }
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+ }
231244} ;
232245
233246/**
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).
235249 */
236- const checkNativeInterceptionForIOS = ( config : InstabugConfig ) => {
250+ const handleInterceptionModeForIOS = ( config : InstabugConfig ) => {
237251 if ( config . networkInterceptionMode === NetworkInterceptionMode . native ) {
238252 if ( isNativeInterceptionFeatureEnabled ) {
239253 shouldEnableNativeInterception = true ;
254+ NetworkLogger . setEnabled ( false ) ; // insure JS interceptor is disabled
240255 } else {
241256 shouldEnableNativeInterception = false ;
242257 NetworkLogger . setEnabled ( true ) ; // rollback to JS interceptor
0 commit comments