Warm up shared preferences in App#onCreate for bugfood builds.

This is being moved from DialtactsActivity#onCreate in order to provide better coverage (since App#onCreate is called earlier).

Additionally, to de-risk any impact on release builds, warming up now only happens when strict mode is enabled, i.e. on bugfood builds.

Test: none
PiperOrigin-RevId: 165046087
Change-Id: I2bd5337a59fa5a430480e77986015c61798185e8
diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java
index a5d6502..7e62065 100644
--- a/java/com/android/dialer/app/DialtactsActivity.java
+++ b/java/com/android/dialer/app/DialtactsActivity.java
@@ -31,7 +31,6 @@
 import android.os.Bundle;
 import android.os.SystemClock;
 import android.os.Trace;
-import android.preference.PreferenceManager;
 import android.provider.CallLog.Calls;
 import android.speech.RecognizerIntent;
 import android.support.annotation.MainThread;
@@ -121,7 +120,6 @@
 import com.android.dialer.simulator.SimulatorComponent;
 import com.android.dialer.smartdial.SmartDialNameMatcher;
 import com.android.dialer.smartdial.SmartDialPrefix;
-import com.android.dialer.strictmode.DialerStrictMode;
 import com.android.dialer.telecom.TelecomUtil;
 import com.android.dialer.util.DialerUtils;
 import com.android.dialer.util.PermissionsUtil;
@@ -389,8 +387,6 @@
     Trace.beginSection(TAG + " onCreate");
     super.onCreate(savedInstanceState);
 
-    warmupSharedPrefs();
-
     mFirstLaunch = true;
     isLastTabEnabled = ConfigProviderBindings.get(this).getBoolean("last_tab_enabled", false);
 
@@ -507,32 +503,6 @@
     Trace.endSection();
   }
 
-  /**
-   * We frequently access shared preferences on the main thread, which causes strict mode
-   * violations. Warm up the shared preferences here so that later uses of shared preferences access
-   * the in-memory versions and we don't have to bypass strict mode at every point in the
-   * application where shared preferences are accessed.
-   */
-  private void warmupSharedPrefs() {
-    DialerStrictMode.bypass(
-        () -> {
-          // From credential-encrypted (CE) storage, i.e.:
-          //    /data/data/com.google.android.dialer/shared_prefs
-
-          // com.google.android.dialer_preferences.xml
-          PreferenceManager.getDefaultSharedPreferences(this);
-
-          // com.google.android.dialer.xml
-          getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
-
-          // From device-encrypted (DE) storage, i.e.:
-          //   /data/user_de/0/com.android.dialer/shared_prefs/
-
-          // com.google.android.dialer_preferences.xml
-          DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(this);
-        });
-  }
-
   @NonNull
   private ActionBar getActionBarSafely() {
     return Assert.isNotNull(getSupportActionBar());
diff --git a/java/com/android/dialer/binary/common/DialerApplication.java b/java/com/android/dialer/binary/common/DialerApplication.java
index 0d38541..580e0a3 100644
--- a/java/com/android/dialer/binary/common/DialerApplication.java
+++ b/java/com/android/dialer/binary/common/DialerApplication.java
@@ -37,7 +37,7 @@
   @Override
   public void onCreate() {
     Trace.beginSection("DialerApplication.onCreate");
-    DialerStrictMode.onApplicationCreate();
+    DialerStrictMode.onApplicationCreate(this);
 
     super.onCreate();
     new BlockedNumbersAutoMigrator(
diff --git a/java/com/android/dialer/strictmode/DialerStrictMode.java b/java/com/android/dialer/strictmode/DialerStrictMode.java
index ad1a6c6..5ce2ad6 100644
--- a/java/com/android/dialer/strictmode/DialerStrictMode.java
+++ b/java/com/android/dialer/strictmode/DialerStrictMode.java
@@ -16,21 +16,51 @@
 
 package com.android.dialer.strictmode;
 
+import android.app.Application;
+import android.content.Context;
 import android.os.Looper;
 import android.os.StrictMode;
 import android.os.StrictMode.ThreadPolicy;
 import android.os.StrictMode.VmPolicy;
+import android.preference.PreferenceManager;
 import com.android.dialer.buildtype.BuildType;
+import com.android.dialer.util.DialerUtils;
 
 /** Enables strict mode for the application, and provides means of temporarily disabling it. */
 public final class DialerStrictMode {
 
   /** Initializes strict mode on application start. */
-  public static void onApplicationCreate() {
+  public static void onApplicationCreate(Application application) {
+    warmupSharedPrefs(application);
     enableDeathPenalty();
   }
 
   /**
+   * We frequently access shared preferences on the main thread, which causes strict mode
+   * violations. When strict mode is allowed, warm up the shared preferences so that later uses of
+   * shared preferences access the in-memory versions and we don't have to bypass strict mode at
+   * every point in the application where shared preferences are accessed.
+   */
+  private static void warmupSharedPrefs(Application application) {
+    if (isStrictModeAllowed()) {
+      // From credential-encrypted (CE) storage, i.e.:
+      //    /data/data/com.google.android.dialer/shared_prefs
+
+      // com.google.android.dialer_preferences.xml
+      PreferenceManager.getDefaultSharedPreferences(application);
+
+      // com.google.android.dialer.xml
+      application.getSharedPreferences(application.getPackageName(), Context.MODE_PRIVATE);
+
+      // From device-encrypted (DE) storage, i.e.:
+      //   /data/user_de/0/com.android.dialer/shared_prefs/
+
+      // com.google.android.dialer_preferences.xml
+      DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(application);
+    }
+  }
+
+  /**
    * Disables the strict mode death penalty. If strict mode is enabled for the build, warnings are
    * printed instead of the application crashing.
    *