From 59cbb014fbf450243c21ac3415d11f8ed80eccee Mon Sep 17 00:00:00 2001 From: Vladimir Kryachko Date: Fri, 31 Jul 2020 10:36:08 -0400 Subject: [PATCH 1/2] Initialize Firebase in direct boot mode Note that even though `FirebaseApp itself initializes, none of the other SDKs get initialized until the user unlocks the devices. --- firebase-common/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/firebase-common/src/main/AndroidManifest.xml b/firebase-common/src/main/AndroidManifest.xml index d73e9521e1f..cf06353f610 100644 --- a/firebase-common/src/main/AndroidManifest.xml +++ b/firebase-common/src/main/AndroidManifest.xml @@ -23,6 +23,7 @@ Date: Thu, 6 Aug 2020 14:17:18 -0400 Subject: [PATCH 2/2] Add direct boot logging to FirebaseApp. --- .../main/java/com/google/firebase/FirebaseApp.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java b/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java index 00c4bdb5b28..48b1a85d146 100644 --- a/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java +++ b/firebase-common/src/main/java/com/google/firebase/FirebaseApp.java @@ -275,8 +275,8 @@ public static FirebaseApp initializeApp( * @param options represents the global {@link FirebaseOptions} * @param name unique name for the app. It is an error to initialize an app with an already * existing name. Starting and ending whitespace characters in the name are ignored (trimmed). - * @throws IllegalStateException if an app with the same name has already been initialized. * @return an instance of {@link FirebaseApp} + * @throws IllegalStateException if an app with the same name has already been initialized. */ @NonNull public static FirebaseApp initializeApp( @@ -395,8 +395,8 @@ public void setDataCollectionDefaultEnabled(Boolean enabled) { *

Note: this value is respected by all SDKs unless overridden by the developer via SDK * specific mechanisms. * - * @deprecated Use {@link #setDataCollectionDefaultEnabled(Boolean)} instead. * @hide + * @deprecated Use {@link #setDataCollectionDefaultEnabled(Boolean)} instead. */ @KeepForSdk @Deprecated @@ -467,8 +467,8 @@ private void notifyBackgroundStateChangeListeners(boolean background) { *

If automatic resource management is enabled and the app is in the background a callback is * triggered immediately. * - * @see BackgroundStateChangeListener * @hide + * @see BackgroundStateChangeListener */ @KeepForSdk public void addBackgroundStateChangeListener(BackgroundStateChangeListener listener) { @@ -572,9 +572,14 @@ private static List getAllAppNames() { private void initializeAllApis() { boolean inDirectBoot = !UserManagerCompat.isUserUnlocked(applicationContext); if (inDirectBoot) { + Log.i( + LOG_TAG, + "Device in Direct Boot Mode: postponing initialization of Firebase APIs for app " + + getName()); // Ensure that all APIs are initialized once the user unlocks the phone. UserUnlockReceiver.ensureReceiverRegistered(applicationContext); } else { + Log.i(LOG_TAG, "Device unlocked: initializing all Firebase APIs for app " + getName()); componentRuntime.initializeEagerComponents(isDefaultApp()); } } @@ -686,6 +691,7 @@ public void onBackgroundStateChanged(boolean background) { } private static class UiExecutor implements Executor { + private static final Handler HANDLER = new Handler(Looper.getMainLooper()); @Override