1
1
package com .instabug .reactlibrary ;
2
2
3
+ import static com .instabug .apm .configuration .cp .APMFeature .APM_NETWORK_PLUGIN_INSTALLED ;
4
+ import static com .instabug .apm .configuration .cp .APMFeature .CP_NATIVE_INTERCEPTION_ENABLED ;
3
5
import static com .instabug .reactlibrary .utils .InstabugUtil .getMethod ;
4
6
5
7
import android .app .Application ;
22
24
import com .facebook .react .bridge .WritableNativeArray ;
23
25
import com .facebook .react .bridge .WritableNativeMap ;
24
26
import com .facebook .react .uimanager .UIManagerModule ;
27
+ import com .instabug .apm .InternalAPM ;
25
28
import com .instabug .library .Feature ;
26
29
import com .instabug .library .Instabug ;
27
30
import com .instabug .library .InstabugColorTheme ;
31
34
import com .instabug .library .ReproConfigurations ;
32
35
import com .instabug .library .core .InstabugCore ;
33
36
import com .instabug .library .featuresflags .model .IBGFeatureFlag ;
37
+ import com .instabug .library .internal .crossplatform .InternalCore ;
38
+ import com .instabug .library .internal .crossplatform .OnFeaturesUpdatedListener ;
34
39
import com .instabug .library .internal .module .InstabugLocale ;
35
40
import com .instabug .library .invocation .InstabugInvocationEvent ;
36
41
import com .instabug .library .logging .InstabugLog ;
37
42
import com .instabug .library .model .NetworkLog ;
38
43
import com .instabug .library .model .Report ;
39
44
import com .instabug .library .ui .onboarding .WelcomeMessage ;
40
- import com .instabug .library .util .InstabugSDKLogger ;
41
45
import com .instabug .reactlibrary .utils .ArrayUtil ;
42
46
import com .instabug .reactlibrary .utils .EventEmitterModule ;
43
47
import com .instabug .reactlibrary .utils .MainThreadHandler ;
@@ -104,6 +108,7 @@ public void removeListeners(Integer count) {
104
108
105
109
/**
106
110
* Enables or disables Instabug functionality.
111
+ *
107
112
* @param isEnabled A boolean to enable/disable Instabug.
108
113
*/
109
114
@ ReactMethod
@@ -112,7 +117,7 @@ public void setEnabled(final boolean isEnabled) {
112
117
@ Override
113
118
public void run () {
114
119
try {
115
- if (isEnabled )
120
+ if (isEnabled )
116
121
Instabug .enable ();
117
122
else
118
123
Instabug .disable ();
@@ -125,10 +130,11 @@ public void run() {
125
130
126
131
/**
127
132
* Initializes the SDK.
128
- * @param token The token that identifies the app. You can find it on your dashboard.
133
+ *
134
+ * @param token The token that identifies the app. You can find it on your dashboard.
129
135
* @param invocationEventValues The events that invoke the SDK's UI.
130
- * @param logLevel The level of detail in logs that you want to print.
131
- * @param codePushVersion The Code Push version to be used for all reports.
136
+ * @param logLevel The level of detail in logs that you want to print.
137
+ * @param codePushVersion The Code Push version to be used for all reports.
132
138
*/
133
139
@ ReactMethod
134
140
public void init (
@@ -154,8 +160,8 @@ public void run() {
154
160
.setInvocationEvents (invocationEvents )
155
161
.setLogLevel (parsedLogLevel );
156
162
157
- if (codePushVersion != null ) {
158
- if (Instabug .isBuilt ()) {
163
+ if (codePushVersion != null ) {
164
+ if (Instabug .isBuilt ()) {
159
165
Instabug .setCodePushVersion (codePushVersion );
160
166
} else {
161
167
builder .setCodePushVersion (codePushVersion );
@@ -321,7 +327,7 @@ public void run() {
321
327
*
322
328
* @param userEmail User's default email
323
329
* @param userName Username.
324
- * @param userId User's ID
330
+ * @param userId User's ID
325
331
*/
326
332
@ ReactMethod
327
333
public void identifyUser (
@@ -741,15 +747,15 @@ public void addFileAttachmentWithDataToReport(String data, String fileName) {
741
747
742
748
private WritableMap convertFromHashMapToWriteableMap (HashMap hashMap ) {
743
749
WritableMap writableMap = new WritableNativeMap ();
744
- for (int i = 0 ; i < hashMap .size (); i ++) {
750
+ for (int i = 0 ; i < hashMap .size (); i ++) {
745
751
Object key = hashMap .keySet ().toArray ()[i ];
746
752
Object value = hashMap .get (key );
747
- writableMap .putString ((String ) key ,(String ) value );
753
+ writableMap .putString ((String ) key , (String ) value );
748
754
}
749
755
return writableMap ;
750
756
}
751
757
752
- private static JSONObject objectToJSONObject (Object object ){
758
+ private static JSONObject objectToJSONObject (Object object ) {
753
759
Object json = null ;
754
760
JSONObject jsonObject = null ;
755
761
try {
@@ -766,13 +772,12 @@ private static JSONObject objectToJSONObject(Object object){
766
772
private WritableArray convertArrayListToWritableArray (List arrayList ) {
767
773
WritableArray writableArray = new WritableNativeArray ();
768
774
769
- for (int i = 0 ; i < arrayList .size (); i ++) {
775
+ for (int i = 0 ; i < arrayList .size (); i ++) {
770
776
Object object = arrayList .get (i );
771
777
772
- if (object instanceof String ) {
778
+ if (object instanceof String ) {
773
779
writableArray .pushString ((String ) object );
774
- }
775
- else {
780
+ } else {
776
781
JSONObject jsonObject = objectToJSONObject (object );
777
782
writableArray .pushMap ((WritableMap ) jsonObject );
778
783
}
@@ -828,7 +833,7 @@ public void run() {
828
833
* Shows the welcome message in a specific mode.
829
834
*
830
835
* @param welcomeMessageMode An enum to set the welcome message mode to
831
- * live, or beta.
836
+ * live, or beta.
832
837
*/
833
838
@ ReactMethod
834
839
public void showWelcomeMessageWithMode (final String welcomeMessageMode ) {
@@ -850,7 +855,7 @@ public void run() {
850
855
* Sets the welcome message mode to live, beta or disabled.
851
856
*
852
857
* @param welcomeMessageMode An enum to set the welcome message mode to
853
- * live, beta or disabled.
858
+ * live, beta or disabled.
854
859
*/
855
860
@ ReactMethod
856
861
public void setWelcomeMessageMode (final String welcomeMessageMode ) {
@@ -985,7 +990,6 @@ public void run() {
985
990
* Reports that the screen name been changed (Current View).
986
991
*
987
992
* @param screenName string containing the screen name
988
- *
989
993
*/
990
994
@ ReactMethod
991
995
public void reportCurrentViewChange (final String screenName ) {
@@ -1008,7 +1012,6 @@ public void run() {
1008
1012
* Reports that the screen has been changed (Repro Steps) the screen sent to this method will be the 'current view' on the dashboard
1009
1013
*
1010
1014
* @param screenName string containing the screen name
1011
- *
1012
1015
*/
1013
1016
@ ReactMethod
1014
1017
public void reportScreenChange (final String screenName ) {
@@ -1018,7 +1021,7 @@ public void run() {
1018
1021
try {
1019
1022
Method method = getMethod (Class .forName ("com.instabug.library.Instabug" ), "reportScreenChange" , Bitmap .class , String .class );
1020
1023
if (method != null ) {
1021
- method .invoke (null , null , screenName );
1024
+ method .invoke (null , null , screenName );
1022
1025
}
1023
1026
} catch (Exception e ) {
1024
1027
e .printStackTrace ();
@@ -1112,7 +1115,7 @@ public void removeFeatureFlags(final ReadableArray featureFlags) {
1112
1115
@ Override
1113
1116
public void run () {
1114
1117
try {
1115
- ArrayList <String > stringArray = ArrayUtil .parseReadableArrayOfStrings (featureFlags );
1118
+ ArrayList <String > stringArray = ArrayUtil .parseReadableArrayOfStrings (featureFlags );
1116
1119
Instabug .removeFeatureFlag (stringArray );
1117
1120
} catch (Exception e ) {
1118
1121
e .printStackTrace ();
@@ -1153,7 +1156,7 @@ public void run() {
1153
1156
* Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
1154
1157
* The constant name and the arg key should match to be able to resolve the
1155
1158
* constant with its actual value from the {@link ArgsRegistry} maps.
1156
- *
1159
+ * <p>
1157
1160
* This is a workaround, because RN cannot resolve enums in the constants map.
1158
1161
*/
1159
1162
@ Override
@@ -1167,4 +1170,20 @@ public Map<String, Object> getConstants() {
1167
1170
1168
1171
return constants ;
1169
1172
}
1173
+
1174
+ @ ReactMethod
1175
+ public void setOnFeaturesUpdatedListener () {
1176
+ InternalCore .INSTANCE ._setOnFeaturesUpdatedListener (new OnFeaturesUpdatedListener () {
1177
+ @ Override
1178
+ public void invoke () {
1179
+ final boolean cpNativeInterceptionEnabled = InternalAPM ._isFeatureEnabledCP (CP_NATIVE_INTERCEPTION_ENABLED , "" );
1180
+ final boolean hasAPMPlugin = InternalAPM ._isFeatureEnabledCP (APM_NETWORK_PLUGIN_INSTALLED , "" );
1181
+
1182
+ WritableMap params = Arguments .createMap ();
1183
+ params .putBoolean ("cpNativeInterceptionEnabled" , cpNativeInterceptionEnabled );
1184
+ params .putBoolean ("hasAPMPlugin" , hasAPMPlugin );
1185
+ sendEvent (Constants .IBG_ON_FEATURES_UPDATED_CALLBACK , params );
1186
+ }
1187
+ });
1188
+ }
1170
1189
}
0 commit comments