summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-08-11 15:14:55 -0700
committerEric Erfanian <erfanian@google.com>2017-08-14 08:30:39 -0700
commit86d76510112dbd1349b3ab6797febebd179a725b (patch)
treec7bcf49ea3169ed92e38e9cda7fdc370889a82ee /java/com/android/dialer/app
parenta30dd0f49b2bf63d292c90821c374be34755aeca (diff)
Fixed some strict mode violations.
Many strict mode violations are due to use of shared preferences on main thread, so we now warm up shared preferences in bypass mode in DialtactsActivity.onCreate. (Note that this shouldn't slow it down because we were already accessing them but without bypassing strict mode.) I also added a new "storage" module which caches device protected shared prefs. Before we were not caching them and every access was resulting in a disk access, because #createDeviceProtectedStorageContext returns a new context for each call. (Note that this change is required for warming those prefs to work.) Note that warming up prefs doesn't fix cases where prefs are read from jobs, services, or Application#onCreate (because those things can happen before DialtactsActivity#onCreate) so there is still a need to bypass in those specific places. Finally, there were various other violations which we now bypass though we probably shouldn't; I'm considering these as being grandfathered in and it would be nice to fix them at some point but today I'd like to just get the app into a usable state so devs can keep strict mode enabled. Bug: 64118795 Test: manually navigated bugfood build and observed no/fewer crashes PiperOrigin-RevId: 165031607 Change-Id: I336212a650a7bd93915ebe56a08e976d37818d68
Diffstat (limited to 'java/com/android/dialer/app')
-rw-r--r--java/com/android/dialer/app/DialtactsActivity.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java
index 99a16d931..a5d650215 100644
--- a/java/com/android/dialer/app/DialtactsActivity.java
+++ b/java/com/android/dialer/app/DialtactsActivity.java
@@ -31,6 +31,7 @@ import android.net.Uri;
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;
@@ -120,6 +121,7 @@ import com.android.dialer.simulator.Simulator;
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;
@@ -387,6 +389,8 @@ public class DialtactsActivity extends TransactionSafeActivity
Trace.beginSection(TAG + " onCreate");
super.onCreate(savedInstanceState);
+ warmupSharedPrefs();
+
mFirstLaunch = true;
isLastTabEnabled = ConfigProviderBindings.get(this).getBoolean("last_tab_enabled", false);
@@ -503,6 +507,32 @@ public class DialtactsActivity extends TransactionSafeActivity
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());
@@ -855,7 +885,7 @@ public class DialtactsActivity extends TransactionSafeActivity
Assert.isNotNull(mListsFragment.getView()).animate().alpha(0).withLayer();
- //adjust the title, so the user will know where we're at when the activity start/resumes.
+ // adjust the title, so the user will know where we're at when the activity start/resumes.
setTitle(R.string.launcherDialpadActivityLabel);
}
@@ -917,7 +947,7 @@ public class DialtactsActivity extends TransactionSafeActivity
exitSearchUi();
}
}
- //reset the title to normal.
+ // reset the title to normal.
setTitle(R.string.launcherActivityLabel);
}