Skip to content

Commit 739dd16

Browse files
authored
Initialize Firebase in direct boot mode (#1840)
* 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. * Add direct boot logging to FirebaseApp.
1 parent 975bb59 commit 739dd16

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

firebase-common/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<provider
2424
android:name="com.google.firebase.provider.FirebaseInitProvider"
2525
android:authorities="${applicationId}.firebaseinitprovider"
26+
android:directBootAware="true"
2627
android:exported="false"
2728
android:initOrder="100" />
2829
<service

firebase-common/src/main/java/com/google/firebase/FirebaseApp.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ public static FirebaseApp initializeApp(
275275
* @param options represents the global {@link FirebaseOptions}
276276
* @param name unique name for the app. It is an error to initialize an app with an already
277277
* existing name. Starting and ending whitespace characters in the name are ignored (trimmed).
278-
* @throws IllegalStateException if an app with the same name has already been initialized.
279278
* @return an instance of {@link FirebaseApp}
279+
* @throws IllegalStateException if an app with the same name has already been initialized.
280280
*/
281281
@NonNull
282282
public static FirebaseApp initializeApp(
@@ -395,8 +395,8 @@ public void setDataCollectionDefaultEnabled(Boolean enabled) {
395395
* <p>Note: this value is respected by all SDKs unless overridden by the developer via SDK
396396
* specific mechanisms.
397397
*
398-
* @deprecated Use {@link #setDataCollectionDefaultEnabled(Boolean)} instead.
399398
* @hide
399+
* @deprecated Use {@link #setDataCollectionDefaultEnabled(Boolean)} instead.
400400
*/
401401
@KeepForSdk
402402
@Deprecated
@@ -467,8 +467,8 @@ private void notifyBackgroundStateChangeListeners(boolean background) {
467467
* <p>If automatic resource management is enabled and the app is in the background a callback is
468468
* triggered immediately.
469469
*
470-
* @see BackgroundStateChangeListener
471470
* @hide
471+
* @see BackgroundStateChangeListener
472472
*/
473473
@KeepForSdk
474474
public void addBackgroundStateChangeListener(BackgroundStateChangeListener listener) {
@@ -572,9 +572,14 @@ private static List<String> getAllAppNames() {
572572
private void initializeAllApis() {
573573
boolean inDirectBoot = !UserManagerCompat.isUserUnlocked(applicationContext);
574574
if (inDirectBoot) {
575+
Log.i(
576+
LOG_TAG,
577+
"Device in Direct Boot Mode: postponing initialization of Firebase APIs for app "
578+
+ getName());
575579
// Ensure that all APIs are initialized once the user unlocks the phone.
576580
UserUnlockReceiver.ensureReceiverRegistered(applicationContext);
577581
} else {
582+
Log.i(LOG_TAG, "Device unlocked: initializing all Firebase APIs for app " + getName());
578583
componentRuntime.initializeEagerComponents(isDefaultApp());
579584
}
580585
}
@@ -686,6 +691,7 @@ public void onBackgroundStateChanged(boolean background) {
686691
}
687692

688693
private static class UiExecutor implements Executor {
694+
689695
private static final Handler HANDLER = new Handler(Looper.getMainLooper());
690696

691697
@Override

0 commit comments

Comments
 (0)