From 2ea18fdb93a598a2b75cc94cb16548a01fdc7f1a Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 15 Nov 2024 14:06:47 -0500 Subject: [PATCH 1/4] fix(android): rn74 forward-port onCatalystInstanceDestroy -> invalidate onCatalystInstanceDestroy is no longer calld as of rn74, so our teardown methods were not being called so we were orphaning listeners on rn 74+ this forward ports to the new invalidate API for rn74+ but leaves in place the old hook as an override for people on rn73- and just delegates to the new implementation --- .../ReactNativeFirebaseAppCheckModule.java | 4 ++-- .../common/ReactNativeFirebaseModule.java | 21 +++++++++++++++++-- .../auth/ReactNativeFirebaseAuthModule.java | 4 ++-- ...eactNativeFirebaseDatabaseQueryModule.java | 4 ++-- ...ReactNativeFirebaseDynamicLinksModule.java | 4 ++-- ...tiveFirebaseFirestoreCollectionModule.java | 4 ++-- ...NativeFirebaseFirestoreDocumentModule.java | 4 ++-- ...iveFirebaseFirestoreTransactionModule.java | 4 ++-- .../perf/ReactNativeFirebasePerfModule.java | 4 ++-- .../ReactNativeFirebaseConfigModule.java | 4 ++-- .../ReactNativeFirebaseStorageModule.java | 4 ++-- 11 files changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java index 9789917cf6..3c9b61dff4 100644 --- a/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java +++ b/packages/app-check/android/src/main/java/io/invertase/firebase/appcheck/ReactNativeFirebaseAppCheckModule.java @@ -100,8 +100,8 @@ private boolean isAppDebuggable() throws Exception { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Log.d(TAG, "instance-destroyed"); Iterator appCheckListenerIterator = mAppCheckListeners.entrySet().iterator(); diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java index 353a4bf4ad..57850abd23 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java @@ -92,9 +92,26 @@ public final ExecutorService getTransactionalExecutor(String identifier) { return executorService.getTransactionalExecutor(identifier); } - @Override - @CallSuper + + // This is no longer called as of react-native 0.74 and is only here for + // compatibility with older versions. It delegates to thew new `invalidate` + // method, which all modules should implement now + // Remove this method when minimum supported react-native is 0.74 + /** @noinspection removal*/ + @SuppressWarnings({"deprecation", "removal"}) + @Deprecated public void onCatalystInstanceDestroy() { + // This should call the child class invalidate, which will then call super.invalidate, + // and everything will work correctly up and down the inheritance hierarchy to shut down + invalidate(); + } + + // This should have an @Override annotation but we cannot do + // that until our minimum supported react-native version is 0.74, since the + // method did not exist before then + @CallSuper + public void invalidate() { + super.invalidate(); executorService.shutdown(); } diff --git a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java index c92ffd6412..06c73c7698 100644 --- a/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +++ b/packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java @@ -123,8 +123,8 @@ public void initialize() { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Log.d(TAG, "instance-destroyed"); Iterator authListenerIterator = mAuthListeners.entrySet().iterator(); diff --git a/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java b/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java index e8a397c2ac..6a016b128c 100644 --- a/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java +++ b/packages/database/android/src/reactnative/java/io/invertase/firebase/database/ReactNativeFirebaseDatabaseQueryModule.java @@ -42,8 +42,8 @@ public class ReactNativeFirebaseDatabaseQueryModule extends ReactNativeFirebaseM } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Iterator refIterator = queryMap.entrySet().iterator(); while (refIterator.hasNext()) { diff --git a/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java b/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java index 4dc402cec7..9e9e63caef 100644 --- a/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java +++ b/packages/dynamic-links/android/src/main/java/io/invertase/firebase/dynamiclinks/ReactNativeFirebaseDynamicLinksModule.java @@ -71,10 +71,10 @@ public class ReactNativeFirebaseDynamicLinksModule extends ReactNativeFirebaseMo } @Override - public void onCatalystInstanceDestroy() { + public void invalidate() { getReactApplicationContext().removeActivityEventListener(this); getReactApplicationContext().addLifecycleEventListener(this); - super.onCatalystInstanceDestroy(); + super.invalidate(); } @ReactMethod diff --git a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java index b44b87170f..ecf8e21e42 100644 --- a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java +++ b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java @@ -42,8 +42,8 @@ public class ReactNativeFirebaseFirestoreCollectionModule extends ReactNativeFir } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); for (int i = 0, size = collectionSnapshotListeners.size(); i < size; i++) { int key = collectionSnapshotListeners.keyAt(i); diff --git a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java index e99531b3f9..43c956cd9a 100644 --- a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java +++ b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java @@ -43,8 +43,8 @@ public class ReactNativeFirebaseFirestoreDocumentModule extends ReactNativeFireb } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); for (int i = 0, size = documentSnapshotListeners.size(); i < size; i++) { int key = documentSnapshotListeners.keyAt(i); diff --git a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java index fd92061a09..e22c0b4950 100644 --- a/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java +++ b/packages/firestore/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java @@ -45,7 +45,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi } @Override - public void onCatalystInstanceDestroy() { + public void invalidate() { for (int i = 0, size = transactionHandlers.size(); i < size; i++) { int key = transactionHandlers.keyAt(i); ReactNativeFirebaseFirestoreTransactionHandler transactionHandler = @@ -57,7 +57,7 @@ public void onCatalystInstanceDestroy() { } transactionHandlers.clear(); - super.onCatalystInstanceDestroy(); + super.invalidate(); } @ReactMethod diff --git a/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java b/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java index b6468d7838..7deef885f6 100644 --- a/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java +++ b/packages/perf/android/src/reactnative/java/io/invertase/firebase/perf/ReactNativeFirebasePerfModule.java @@ -36,8 +36,8 @@ public class ReactNativeFirebasePerfModule extends ReactNativeFirebaseModule { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); module.onTearDown(); } diff --git a/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java b/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java index 9a439dd7af..530ae5b6b1 100644 --- a/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java +++ b/packages/remote-config/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java @@ -45,8 +45,8 @@ public class ReactNativeFirebaseConfigModule extends ReactNativeFirebaseModule { } @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); + public void invalidate() { + super.invalidate(); Iterator> configRegistrationsIterator = mConfigUpdateRegistrations.entrySet().iterator(); diff --git a/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java b/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java index 27f4cddaec..7bd81c2152 100644 --- a/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java +++ b/packages/storage/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java @@ -51,9 +51,9 @@ public class ReactNativeFirebaseStorageModule extends ReactNativeFirebaseModule } @Override - public void onCatalystInstanceDestroy() { + public void invalidate() { ReactNativeFirebaseStorageTask.destroyAllTasks(); - super.onCatalystInstanceDestroy(); + super.invalidate(); } /** From e5ec77c5a4d9e45c52c006ef57c6b85b89f17d09 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 15 Nov 2024 14:08:41 -0500 Subject: [PATCH 2/4] fix(android): forward-port to non-deprecated data collection API available since 2020, so should have no affect on consumers --- .../java/io/invertase/firebase/common/RCTConvertFirebase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java index 8914bff2af..8627e4ce45 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java @@ -98,7 +98,7 @@ public static FirebaseApp readableMapToFirebaseApp( if (appConfig.hasKey("automaticDataCollectionEnabled")) { firebaseApp.setDataCollectionDefaultEnabled( - appConfig.getBoolean("automaticDataCollectionEnabled")); + Boolean.valueOf(appConfig.getBoolean("automaticDataCollectionEnabled"))); } if (appConfig.hasKey("automaticResourceManagement")) { From 76371d2a042fa6c6a514bbae5fc3fc5a985d96c7 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 15 Nov 2024 14:09:55 -0500 Subject: [PATCH 3/4] style(lint): ignore two discouraged api lints one is never used apparently but shouldn't be removed in case brownfield apps are using it as it is public static the other is required in order to support resource load by name functionality for remote config --- .../java/io/invertase/firebase/common/SharedUtils.java | 2 ++ .../firebase/config/UniversalFirebaseConfigModule.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java index c1eb8e10e5..b98134068b 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java @@ -17,6 +17,7 @@ * */ +import android.annotation.SuppressLint; import android.app.ActivityManager; import android.content.Context; import android.graphics.Point; @@ -181,6 +182,7 @@ public static boolean isAppInForeground(Context context) { return false; } + @SuppressLint("DiscouragedApi") public static int getResId(Context ctx, String resName) { int resourceId = ctx.getResources().getIdentifier(resName, "string", ctx.getPackageName()); diff --git a/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java b/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java index cfcc443508..5dc3d4c1ca 100644 --- a/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java +++ b/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java @@ -19,6 +19,7 @@ import static com.google.firebase.remoteconfig.FirebaseRemoteConfig.*; +import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Resources; import android.content.res.XmlResourceParser; @@ -154,6 +155,7 @@ Map getAllValuesForApp(String appName) { return configValuesMap; } + @SuppressLint("DiscouragedApi") private int getXmlResourceIdByName(String name) { String packageName = getApplicationContext().getPackageName(); return getApplicationContext().getResources().getIdentifier(name, "xml", packageName); From acad2bdb8ef33bfa70a9074544a0f7b6df31a933 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Fri, 15 Nov 2024 14:10:56 -0500 Subject: [PATCH 4/4] test(android): enable gradle deprecation warnings, fix jacoco deprecation this prepares the e2e app for gradle 9 --- tests/.detoxrc.js | 2 +- tests/android/app/jacoco.gradle | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/.detoxrc.js b/tests/.detoxrc.js index 594d16f357..a7a3e1b5ff 100644 --- a/tests/.detoxrc.js +++ b/tests/.detoxrc.js @@ -23,7 +23,7 @@ module.exports = { 'android.debug': { type: 'android.apk', binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk', - build: 'cd android && ./gradlew assembleDebug assembleAndroidTest lintDebug -DtestBuildType=debug && cd ..', + build: 'cd android && ./gradlew assembleDebug assembleAndroidTest lintDebug -DtestBuildType=debug --warning-mode all && cd ..', reversePorts: [ 8080, 8081, diff --git a/tests/android/app/jacoco.gradle b/tests/android/app/jacoco.gradle index 56ec7fc716..e0d687109f 100644 --- a/tests/android/app/jacoco.gradle +++ b/tests/android/app/jacoco.gradle @@ -68,7 +68,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'conn reports { xml.required = true - html.destination htmlOutDir + html.outputLocation = htmlOutDir } def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] @@ -98,7 +98,7 @@ task jacocoUnitTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) reports { xml.required = true - html.destination htmlOutDir + html.outputLocation = htmlOutDir } def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] @@ -123,7 +123,7 @@ task jacocoAndroidTestReport(type: JacocoReport) { reports { xml.required = true - html.destination htmlOutDir + html.outputLocation = htmlOutDir } def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']