Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1205)

Unified Diff: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java

Issue 2339343002: Android webview tries to switch to CE context (Closed)
Patch Set: Removed redundancy Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
index 2ef597bfab1af55fa202d279a6c2850544ddf6dd..d7547a38b18184044c1548a6df7d3659dfd62d66 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
@@ -18,6 +18,7 @@ import android.os.Build;
import android.os.Looper;
import android.os.Process;
import android.os.StrictMode;
+import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
import android.webkit.CookieManager;
@@ -199,12 +200,11 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
private void initialize(WebViewDelegate webViewDelegate) {
mWebViewDelegate = webViewDelegate;
- checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication());
+ Context ctx = switchToCredentialProtectedStorage(
+ mWebViewDelegate.getApplication().getApplicationContext());
// WebView needs to make sure to always use the wrapped application context.
- ContextUtils.initApplicationContext(
- ResourcesContextWrapperFactory.get(
- mWebViewDelegate.getApplication().getApplicationContext()));
+ ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(ctx));
if (isBuildDebuggable()) {
// Suppress the StrictMode violation as this codepath is only hit on debuggable builds.
@@ -253,12 +253,20 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
// Now safe to use WebView data directory.
}
- static void checkStorageIsNotDeviceProtected(Context context) {
+ // Webview must use a CredentialEncrypted Context. If context is a CE context, then simply
+ // return it without modification. Otherwise, create a new CE context and return that instead.
+ static Context switchToCredentialProtectedStorage(Context context) {
+ // For versions N+, android webview must use a CredentialEncrypted Context
if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build.VERSION_CODES.M)
&& context.isDeviceProtectedStorage()) {
- throw new IllegalArgumentException(
- "WebView cannot be used with device protected storage");
+ context = context.createCredentialProtectedStorageContext();
+
+ if (!context.getSystemService(UserManager.class).isUserUnlocked()) {
Torne 2016/09/22 09:59:54 I think you should be getting a lint warning about
Nate Fischer 2016/09/22 19:47:49 I don't think I received a lint warning. I was abl
Torne 2016/09/23 11:13:15 I think they happen during the build, not in presu
+ throw new IllegalArgumentException(
+ "WebView cannot be used with device protected storage");
+ }
}
+ return context;
}
private static boolean isBuildDebuggable() {

Powered by Google App Engine
This is Rietveld 408576698