Page MenuHomePhabricator

D5923.id19539.diff
No OneTemporary

D5923.id19539.diff

diff --git a/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java b/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java
--- a/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java
+++ b/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java
@@ -1,16 +1,12 @@
package app.comm.android;
-import android.util.Log;
import app.comm.android.fbjni.CommHybrid;
import app.comm.android.fbjni.CommSecureStore;
import com.facebook.react.bridge.JSIModuleSpec;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.facebook.react.bridge.ReactApplicationContext;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
-import expo.modules.adapters.react.NativeModulesProxy;
-import expo.modules.core.ModuleRegistry;
import expo.modules.securestore.SecureStoreModule;
-import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
@@ -22,7 +18,7 @@
ReactApplicationContext reactApplicationContext,
JavaScriptContextHolder jsContext) {
Supplier<SecureStoreModule> secureStoreModuleSupplier =
- () -> new SecureStoreModule(reactApplicationContext);
+ ExpoUtils.createExpoSecureStoreSupplier(reactApplicationContext);
CommSecureStore.getInstance().initialize(secureStoreModuleSupplier);
CommHybrid.initHybrid(reactApplicationContext);
super.getJSIModules(reactApplicationContext, jsContext);
diff --git a/native/android/app/src/main/java/app/comm/android/CommNotificationsHandler.java b/native/android/app/src/main/java/app/comm/android/CommNotificationsHandler.java
--- a/native/android/app/src/main/java/app/comm/android/CommNotificationsHandler.java
+++ b/native/android/app/src/main/java/app/comm/android/CommNotificationsHandler.java
@@ -10,12 +10,9 @@
import app.comm.android.fbjni.NetworkModule;
import app.comm.android.fbjni.ThreadOperations;
import com.google.firebase.messaging.RemoteMessage;
-import expo.modules.securestore.SecureStoreModule;
import io.invertase.firebase.messaging.RNFirebaseMessagingService;
import java.io.File;
import me.leolin.shortcutbadger.ShortcutBadger;
-import org.json.JSONException;
-import org.json.JSONObject;
/**
* We're extending RNFirebaseMessagingService here instead of
@@ -57,7 +54,7 @@
public void onCreate() {
super.onCreate();
CommSecureStore.getInstance().initialize(
- () -> new SecureStoreModule(this.getApplicationContext()));
+ ExpoUtils.createExpoSecureStoreSupplier(this.getApplicationContext()));
notificationManager = (NotificationManager)this.getSystemService(
Context.NOTIFICATION_SERVICE);
}
diff --git a/native/android/app/src/main/java/app/comm/android/ExpoUtils.java b/native/android/app/src/main/java/app/comm/android/ExpoUtils.java
new file mode 100644
--- /dev/null
+++ b/native/android/app/src/main/java/app/comm/android/ExpoUtils.java
@@ -0,0 +1,40 @@
+package app.comm.android;
+
+import android.content.Context;
+import androidx.annotation.NonNull;
+import com.facebook.react.bridge.ReactContext;
+import expo.modules.adapters.react.services.UIManagerModuleWrapper;
+import expo.modules.core.ModuleRegistry;
+import expo.modules.core.interfaces.InternalModule;
+import expo.modules.securestore.SecureStoreModule;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Supplier;
+
+public class ExpoUtils {
+ public static Supplier<SecureStoreModule>
+ createExpoSecureStoreSupplier(@NonNull Context context) {
+ return () -> {
+ List<InternalModule> expoInternalModules = new ArrayList<>(1);
+ if (context instanceof ReactContext) {
+ // We can only provide the UIManager module if provided context is a
+ // React context. If this is called from non-react activity, like
+ // CommNotificationsHandler, we skip adding this module. This is fine,
+ // unless we use the `requiresAuthentication` option when dealing with
+ // expo-secure-store (at this moment we don't use it anywhere)
+ expoInternalModules.add(
+ new UIManagerModuleWrapper((ReactContext)context));
+ }
+
+ ModuleRegistry expoModuleRegistry = new ModuleRegistry(
+ expoInternalModules,
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList());
+ SecureStoreModule secureStoreModule = new SecureStoreModule(context);
+ secureStoreModule.onCreate(expoModuleRegistry);
+ return secureStoreModule;
+ };
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 9:56 AM (18 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2494033
Default Alt Text
D5923.id19539.diff (4 KB)

Event Timeline