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

Fix strict mode exclusions for WebView prefs.

Anywhere we call getSharedPreferences might be a disk write as the
directory for prefs is created if it doesn't already exist; move the
existing StrictModeContext in AwGeolocationPermissions up to the caller
to also cover where the SharedPreferences object is retrieved, and add
another missing one when the browser context is created.

Bug: 994321
Change-Id: I2e18e156d378910751ee2a530d72180eab012696
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1773781Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Commit-Queue: Richard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690913}
parent 74df4431
...@@ -9,6 +9,7 @@ import android.content.SharedPreferences; ...@@ -9,6 +9,7 @@ import android.content.SharedPreferences;
import org.chromium.android_webview.common.PlatformServiceBridge; import org.chromium.android_webview.common.PlatformServiceBridge;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
...@@ -102,11 +103,17 @@ public class AwBrowserContext { ...@@ -102,11 +103,17 @@ public class AwBrowserContext {
} }
private void migrateGeolocationPreferences() { private void migrateGeolocationPreferences() {
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
// Prefs dir will be created if it doesn't exist, so must allow writes
// for this and so that the actual prefs can be written to the new
// location if needed.
final String oldGlobalPrefsName = "WebViewChromiumPrefs"; final String oldGlobalPrefsName = "WebViewChromiumPrefs";
SharedPreferences oldGlobalPrefs = SharedPreferences oldGlobalPrefs =
ContextUtils.getApplicationContext().getSharedPreferences( ContextUtils.getApplicationContext().getSharedPreferences(
oldGlobalPrefsName, Context.MODE_PRIVATE); oldGlobalPrefsName, Context.MODE_PRIVATE);
AwGeolocationPermissions.migrateGeolocationPreferences(oldGlobalPrefs, mSharedPreferences); AwGeolocationPermissions.migrateGeolocationPreferences(
oldGlobalPrefs, mSharedPreferences);
}
} }
/** /**
...@@ -141,9 +148,12 @@ public class AwBrowserContext { ...@@ -141,9 +148,12 @@ public class AwBrowserContext {
@CalledByNative @CalledByNative
public static AwBrowserContext create(long nativeAwBrowserContext, boolean isDefault) { public static AwBrowserContext create(long nativeAwBrowserContext, boolean isDefault) {
SharedPreferences sharedPreferences = SharedPreferences sharedPreferences;
ContextUtils.getApplicationContext().getSharedPreferences( try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
// Prefs dir will be created if it doesn't exist, so must allow writes.
sharedPreferences = ContextUtils.getApplicationContext().getSharedPreferences(
CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE);
}
return new AwBrowserContext(sharedPreferences, nativeAwBrowserContext, isDefault); return new AwBrowserContext(sharedPreferences, nativeAwBrowserContext, isDefault);
} }
......
...@@ -6,7 +6,6 @@ package org.chromium.android_webview; ...@@ -6,7 +6,6 @@ package org.chromium.android_webview;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import org.chromium.base.StrictModeContext;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.net.GURLUtils; import org.chromium.net.GURLUtils;
...@@ -133,7 +132,6 @@ public final class AwGeolocationPermissions { ...@@ -133,7 +132,6 @@ public final class AwGeolocationPermissions {
/* package */ /* package */
static void migrateGeolocationPreferences( static void migrateGeolocationPreferences(
SharedPreferences oldPrefs, SharedPreferences newPrefs) { SharedPreferences oldPrefs, SharedPreferences newPrefs) {
try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
SharedPreferences.Editor oldPrefsEditor = oldPrefs.edit(); SharedPreferences.Editor oldPrefsEditor = oldPrefs.edit();
SharedPreferences.Editor newPrefsEditor = newPrefs.edit(); SharedPreferences.Editor newPrefsEditor = newPrefs.edit();
...@@ -145,5 +143,4 @@ public final class AwGeolocationPermissions { ...@@ -145,5 +143,4 @@ public final class AwGeolocationPermissions {
} }
} }
} }
}
} }
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