Commit fcc26842 authored by Torne (Richard Coles)'s avatar Torne (Richard Coles) Committed by Commit Bot

android: Allow disk writes to init shared prefs.

If code used very early in startup reads shared preferences and the app
is freshly installed the prefs directory might not exist yet, triggering
a disk write in getDefaultSharedPreferences. Suppress this for
StrictMode as it can happen in WebView.

Bug: 1131941
Change-Id: Iaf738bad917673a1e5a0d3804f1c55f3181b10a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431730
Auto-Submit: Richard Coles <torne@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810892}
parent 1a72d2e8
......@@ -75,7 +75,11 @@ public class ContextUtils {
*/
@SuppressWarnings("DefaultSharedPreferencesCheck")
private static SharedPreferences fetchAppSharedPreferences() {
return PreferenceManager.getDefaultSharedPreferences(sApplicationContext);
// This may need to create the prefs directory if we've never used shared prefs before, so
// allow disk writes. This is rare but can happen if code used early in startup reads prefs.
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
return PreferenceManager.getDefaultSharedPreferences(sApplicationContext);
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment