11package com .instabug .reactlibrary ;
22
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 ;
35import static com .instabug .reactlibrary .utils .InstabugUtil .getMethod ;
46
57import android .app .Application ;
2224import com .facebook .react .bridge .WritableNativeArray ;
2325import com .facebook .react .bridge .WritableNativeMap ;
2426import com .facebook .react .uimanager .UIManagerModule ;
27+ import com .instabug .apm .InternalAPM ;
2528import com .instabug .library .Feature ;
2629import com .instabug .library .Instabug ;
2730import com .instabug .library .InstabugColorTheme ;
3134import com .instabug .library .ReproConfigurations ;
3235import com .instabug .library .core .InstabugCore ;
3336import com .instabug .library .featuresflags .model .IBGFeatureFlag ;
37+ import com .instabug .library .internal .crossplatform .InternalCore ;
38+ import com .instabug .library .internal .crossplatform .OnFeaturesUpdatedListener ;
3439import com .instabug .library .internal .module .InstabugLocale ;
3540import com .instabug .library .invocation .InstabugInvocationEvent ;
3641import com .instabug .library .logging .InstabugLog ;
3742import com .instabug .library .model .NetworkLog ;
3843import com .instabug .library .model .Report ;
3944import com .instabug .library .ui .onboarding .WelcomeMessage ;
40- import com .instabug .library .util .InstabugSDKLogger ;
4145import com .instabug .reactlibrary .utils .ArrayUtil ;
4246import com .instabug .reactlibrary .utils .EventEmitterModule ;
4347import com .instabug .reactlibrary .utils .MainThreadHandler ;
@@ -104,6 +108,7 @@ public void removeListeners(Integer count) {
104108
105109 /**
106110 * Enables or disables Instabug functionality.
111+ *
107112 * @param isEnabled A boolean to enable/disable Instabug.
108113 */
109114 @ ReactMethod
@@ -112,7 +117,7 @@ public void setEnabled(final boolean isEnabled) {
112117 @ Override
113118 public void run () {
114119 try {
115- if (isEnabled )
120+ if (isEnabled )
116121 Instabug .enable ();
117122 else
118123 Instabug .disable ();
@@ -125,10 +130,11 @@ public void run() {
125130
126131 /**
127132 * 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.
129135 * @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.
132138 */
133139 @ ReactMethod
134140 public void init (
@@ -154,8 +160,8 @@ public void run() {
154160 .setInvocationEvents (invocationEvents )
155161 .setLogLevel (parsedLogLevel );
156162
157- if (codePushVersion != null ) {
158- if (Instabug .isBuilt ()) {
163+ if (codePushVersion != null ) {
164+ if (Instabug .isBuilt ()) {
159165 Instabug .setCodePushVersion (codePushVersion );
160166 } else {
161167 builder .setCodePushVersion (codePushVersion );
@@ -321,7 +327,7 @@ public void run() {
321327 *
322328 * @param userEmail User's default email
323329 * @param userName Username.
324- * @param userId User's ID
330+ * @param userId User's ID
325331 */
326332 @ ReactMethod
327333 public void identifyUser (
@@ -741,15 +747,15 @@ public void addFileAttachmentWithDataToReport(String data, String fileName) {
741747
742748 private WritableMap convertFromHashMapToWriteableMap (HashMap hashMap ) {
743749 WritableMap writableMap = new WritableNativeMap ();
744- for (int i = 0 ; i < hashMap .size (); i ++) {
750+ for (int i = 0 ; i < hashMap .size (); i ++) {
745751 Object key = hashMap .keySet ().toArray ()[i ];
746752 Object value = hashMap .get (key );
747- writableMap .putString ((String ) key ,(String ) value );
753+ writableMap .putString ((String ) key , (String ) value );
748754 }
749755 return writableMap ;
750756 }
751757
752- private static JSONObject objectToJSONObject (Object object ){
758+ private static JSONObject objectToJSONObject (Object object ) {
753759 Object json = null ;
754760 JSONObject jsonObject = null ;
755761 try {
@@ -766,13 +772,12 @@ private static JSONObject objectToJSONObject(Object object){
766772 private WritableArray convertArrayListToWritableArray (List arrayList ) {
767773 WritableArray writableArray = new WritableNativeArray ();
768774
769- for (int i = 0 ; i < arrayList .size (); i ++) {
775+ for (int i = 0 ; i < arrayList .size (); i ++) {
770776 Object object = arrayList .get (i );
771777
772- if (object instanceof String ) {
778+ if (object instanceof String ) {
773779 writableArray .pushString ((String ) object );
774- }
775- else {
780+ } else {
776781 JSONObject jsonObject = objectToJSONObject (object );
777782 writableArray .pushMap ((WritableMap ) jsonObject );
778783 }
@@ -828,7 +833,7 @@ public void run() {
828833 * Shows the welcome message in a specific mode.
829834 *
830835 * @param welcomeMessageMode An enum to set the welcome message mode to
831- * live, or beta.
836+ * live, or beta.
832837 */
833838 @ ReactMethod
834839 public void showWelcomeMessageWithMode (final String welcomeMessageMode ) {
@@ -850,7 +855,7 @@ public void run() {
850855 * Sets the welcome message mode to live, beta or disabled.
851856 *
852857 * @param welcomeMessageMode An enum to set the welcome message mode to
853- * live, beta or disabled.
858+ * live, beta or disabled.
854859 */
855860 @ ReactMethod
856861 public void setWelcomeMessageMode (final String welcomeMessageMode ) {
@@ -985,7 +990,6 @@ public void run() {
985990 * Reports that the screen name been changed (Current View).
986991 *
987992 * @param screenName string containing the screen name
988- *
989993 */
990994 @ ReactMethod
991995 public void reportCurrentViewChange (final String screenName ) {
@@ -1008,7 +1012,6 @@ public void run() {
10081012 * Reports that the screen has been changed (Repro Steps) the screen sent to this method will be the 'current view' on the dashboard
10091013 *
10101014 * @param screenName string containing the screen name
1011- *
10121015 */
10131016 @ ReactMethod
10141017 public void reportScreenChange (final String screenName ) {
@@ -1018,7 +1021,7 @@ public void run() {
10181021 try {
10191022 Method method = getMethod (Class .forName ("com.instabug.library.Instabug" ), "reportScreenChange" , Bitmap .class , String .class );
10201023 if (method != null ) {
1021- method .invoke (null , null , screenName );
1024+ method .invoke (null , null , screenName );
10221025 }
10231026 } catch (Exception e ) {
10241027 e .printStackTrace ();
@@ -1112,7 +1115,7 @@ public void removeFeatureFlags(final ReadableArray featureFlags) {
11121115 @ Override
11131116 public void run () {
11141117 try {
1115- ArrayList <String > stringArray = ArrayUtil .parseReadableArrayOfStrings (featureFlags );
1118+ ArrayList <String > stringArray = ArrayUtil .parseReadableArrayOfStrings (featureFlags );
11161119 Instabug .removeFeatureFlag (stringArray );
11171120 } catch (Exception e ) {
11181121 e .printStackTrace ();
@@ -1153,7 +1156,7 @@ public void run() {
11531156 * Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
11541157 * The constant name and the arg key should match to be able to resolve the
11551158 * constant with its actual value from the {@link ArgsRegistry} maps.
1156- *
1159+ * <p>
11571160 * This is a workaround, because RN cannot resolve enums in the constants map.
11581161 */
11591162 @ Override
@@ -1167,4 +1170,20 @@ public Map<String, Object> getConstants() {
11671170
11681171 return constants ;
11691172 }
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+ }
11701189}
0 commit comments