Commit fe20a56c authored by torne's avatar torne Committed by Commit bot

Allow disk writes while checking webview version pref.

Since N, the preference directory will be created if it doesn't exist
when getSharedPreferences is called. Enable disk writes to prevent a
strict mode violation; this will only happen the first time an app is
started up.

BUG=716219

Review-Url: https://codereview.chromium.org/2846963005
Cr-Commit-Position: refs/heads/master@{#468052}
parent 91dea332
...@@ -16,6 +16,7 @@ import android.net.Uri; ...@@ -16,6 +16,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Looper; import android.os.Looper;
import android.os.Process; import android.os.Process;
import android.os.StrictMode;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
...@@ -247,8 +248,15 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { ...@@ -247,8 +248,15 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
System.loadLibrary("webviewchromium_plat_support"); System.loadLibrary("webviewchromium_plat_support");
// Use shared preference to check for package downgrade. // Use shared preference to check for package downgrade.
mWebViewPrefs = ContextUtils.getApplicationContext().getSharedPreferences( // Since N, getSharedPreferences creates the preference dir if it doesn't exist,
CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); // causing a disk write.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
mWebViewPrefs = ContextUtils.getApplicationContext().getSharedPreferences(
CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0);
int currentVersion = packageInfo.versionCode; int currentVersion = packageInfo.versionCode;
if (!versionCodeGE(currentVersion, lastVersion)) { if (!versionCodeGE(currentVersion, lastVersion)) {
......
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