@@ -43,10 +43,10 @@ let _lastScreen: string | null = null;
43
43
let _isFirstScreen = false ;
44
44
const firstScreen = 'Initial Screen' ;
45
45
let _currentAppState = AppState . currentState ;
46
- let isNativeInterceptionEnabled = false ;
46
+ let isNativeInterceptionFeatureEnabled = false ;
47
47
let hasAPMNetworkPlugin = false ;
48
48
let isAPMNetworkEnabled = false ;
49
- let disableAPMLogging = false ; // used to disable APM logging inside reportNetworkLog() -> NativeAPM.networkLogAndroid()
49
+ let shouldEnableNativeInterception = false ; // used to disable APM logging inside reportNetworkLog() -> NativeAPM.networkLogAndroid()
50
50
51
51
/**
52
52
* Enables or disables Instabug functionality.
@@ -73,6 +73,17 @@ function reportCurrentViewForAndroid(screenName: string | null) {
73
73
}
74
74
}
75
75
76
+ function _logFlags ( ) {
77
+ console . log (
78
+ `Andrew: init -> {
79
+ isNativeInterceptionFeatureEnabled: ${ isNativeInterceptionFeatureEnabled } ,
80
+ hasAPMNetworkPlugin: ${ hasAPMNetworkPlugin } ,
81
+ isApmNetworkEnabled: ${ isAPMNetworkEnabled } ,
82
+ shouldEnableNativeInterception: ${ shouldEnableNativeInterception }
83
+ }` ,
84
+ ) ;
85
+ }
86
+
76
87
/**
77
88
* Initializes the SDK.
78
89
* This is the main SDK method that does all the magic. This is the only
@@ -82,11 +93,12 @@ function reportCurrentViewForAndroid(screenName: string | null) {
82
93
*/
83
94
export const init = async ( config : InstabugConfig ) => {
84
95
// Initialize necessary variables
85
- isNativeInterceptionEnabled = await NativeNetworkLogger . isNativeInterceptionEnabled ( ) ;
96
+ isNativeInterceptionFeatureEnabled = await NativeNetworkLogger . isNativeInterceptionEnabled ( ) ;
86
97
if ( Platform . OS === 'android' ) {
87
98
hasAPMNetworkPlugin = await NativeNetworkLogger . hasAPMNetworkPlugin ( ) ;
88
99
isAPMNetworkEnabled = await NativeNetworkLogger . isAPMNetworkEnabled ( ) ;
89
- disableAPMLogging = config . networkInterceptionMode === NetworkInterceptionMode . native ;
100
+ shouldEnableNativeInterception =
101
+ config . networkInterceptionMode === NetworkInterceptionMode . native ;
90
102
}
91
103
92
104
// Add app state listener to handle background/foreground transitions
@@ -100,21 +112,14 @@ export const init = async (config: InstabugConfig) => {
100
112
handleNetworkInterceptionMode ( config ) ;
101
113
102
114
// Log the current APM network flags and initialize Instabug
103
- console . log (
104
- `Andrew: init -> {
105
- isNativeInterceptionEnabled: ${ isNativeInterceptionEnabled } ,
106
- hasAPMNetworkPlugin: ${ hasAPMNetworkPlugin } ,
107
- isApmNetworkEnabled: ${ isAPMNetworkEnabled } ,
108
- disableAPMLogging: ${ disableAPMLogging }
109
- }` ,
110
- ) ;
115
+ _logFlags ( ) ;
111
116
112
117
//Set APM networking flags for the first time
113
118
setApmNetworkFlagsIfChanged ( {
114
- isNativeInterceptionEnabled : isNativeInterceptionEnabled ,
119
+ isNativeInterceptionFeatureEnabled : isNativeInterceptionFeatureEnabled ,
115
120
hasAPMNetworkPlugin : hasAPMNetworkPlugin ,
116
121
isAPMNetworkEnabled : isAPMNetworkEnabled ,
117
- disableAPMLogging : disableAPMLogging ,
122
+ shouldEnableNativeInterception : shouldEnableNativeInterception ,
118
123
} ) ;
119
124
120
125
// call Instabug native init method
@@ -146,7 +151,7 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
146
151
handleNetworkInterceptionMode ( config ) ;
147
152
initializeNativeInstabug ( config ) ;
148
153
}
149
-
154
+ _logFlags ( ) ;
150
155
console . log ( 'Andrew: App has come to the foreground!' ) ;
151
156
}
152
157
@@ -158,15 +163,17 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
158
163
* Fetches the current APM network flags.
159
164
*/
160
165
const fetchApmNetworkFlags = async ( ) => {
161
- isNativeInterceptionEnabled = await NativeNetworkLogger . isNativeInterceptionEnabled ( ) ;
162
- hasAPMNetworkPlugin = await NativeNetworkLogger . hasAPMNetworkPlugin ( ) ;
163
- isAPMNetworkEnabled = await NativeNetworkLogger . isAPMNetworkEnabled ( ) ;
166
+ isNativeInterceptionFeatureEnabled = await NativeNetworkLogger . isNativeInterceptionEnabled ( ) ;
167
+ if ( Platform . OS === 'android' ) {
168
+ hasAPMNetworkPlugin = await NativeNetworkLogger . hasAPMNetworkPlugin ( ) ;
169
+ isAPMNetworkEnabled = await NativeNetworkLogger . isAPMNetworkEnabled ( ) ;
170
+ }
164
171
165
172
return {
166
- isNativeInterceptionEnabled ,
173
+ isNativeInterceptionFeatureEnabled ,
167
174
hasAPMNetworkPlugin,
168
175
isAPMNetworkEnabled,
169
- disableAPMLogging ,
176
+ shouldEnableNativeInterception ,
170
177
} ;
171
178
} ;
172
179
@@ -198,15 +205,15 @@ const checkNativeInterceptionForAndroid = (config: InstabugConfig) => {
198
205
const { networkInterceptionMode } = config ;
199
206
200
207
if ( networkInterceptionMode === NetworkInterceptionMode . javascript ) {
201
- if ( isNativeInterceptionEnabled && hasAPMNetworkPlugin ) {
202
- disableAPMLogging = true ;
208
+ if ( isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin ) {
209
+ shouldEnableNativeInterception = true ;
203
210
console . warn (
204
211
InstabugConstants . IBG_APM_TAG + 'Switched to Native Interception: Android Plugin Detected' ,
205
212
) ;
206
213
}
207
214
} else {
208
- if ( isNativeInterceptionEnabled ) {
209
- disableAPMLogging = hasAPMNetworkPlugin ;
215
+ if ( isNativeInterceptionFeatureEnabled ) {
216
+ shouldEnableNativeInterception = hasAPMNetworkPlugin ;
210
217
if ( ! hasAPMNetworkPlugin ) {
211
218
console . error (
212
219
InstabugConstants . IBG_APM_TAG +
@@ -230,12 +237,13 @@ const checkNativeInterceptionForAndroid = (config: InstabugConfig) => {
230
237
* Handles the native interception logic for iOS.
231
238
*/
232
239
const checkNativeInterceptionForIOS = ( config : InstabugConfig ) => {
233
- if (
234
- config . networkInterceptionMode === NetworkInterceptionMode . native &&
235
- ! isNativeInterceptionEnabled
236
- ) {
237
- config . networkInterceptionMode = NetworkInterceptionMode . javascript ;
238
- console . error ( InstabugConstants . IBG_APM_TAG + 'Native interception is disabled' ) ;
240
+ if ( config . networkInterceptionMode === NetworkInterceptionMode . native ) {
241
+ if ( isNativeInterceptionFeatureEnabled ) {
242
+ shouldEnableNativeInterception = true ;
243
+ } else {
244
+ shouldEnableNativeInterception = false ;
245
+ console . error ( InstabugConstants . IBG_APM_TAG + 'Native interception is disabled' ) ;
246
+ }
239
247
}
240
248
} ;
241
249
@@ -245,14 +253,16 @@ const checkNativeInterceptionForIOS = (config: InstabugConfig) => {
245
253
const initializeNativeInstabug = ( config : InstabugConfig ) => {
246
254
console . log (
247
255
`Andrew: initializeNativeInstabug -> NativeNetworkInterceptionMode ${
256
+ shouldEnableNativeInterception &&
248
257
config . networkInterceptionMode === NetworkInterceptionMode . native
249
258
} `,
250
259
) ;
251
260
NativeInstabug . init (
252
261
config . token ,
253
262
config . invocationEvents ,
254
263
config . debugLogsLevel ?? LogLevel . error ,
255
- config . networkInterceptionMode === NetworkInterceptionMode . native ,
264
+ shouldEnableNativeInterception &&
265
+ config . networkInterceptionMode === NetworkInterceptionMode . native ,
256
266
config . codePushVersion ,
257
267
) ;
258
268
} ;
0 commit comments