OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package com.android.webview.chromium; | 5 package com.android.webview.chromium; |
6 | 6 |
7 import android.Manifest; | 7 import android.Manifest; |
8 import android.app.ActivityManager; | 8 import android.app.ActivityManager; |
9 import android.content.ComponentCallbacks2; | 9 import android.content.ComponentCallbacks2; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.SharedPreferences; | 12 import android.content.SharedPreferences; |
13 import android.content.pm.ApplicationInfo; | |
13 import android.content.pm.PackageInfo; | 14 import android.content.pm.PackageInfo; |
14 import android.content.pm.PackageManager; | 15 import android.content.pm.PackageManager; |
15 import android.content.pm.PackageManager.NameNotFoundException; | 16 import android.content.pm.PackageManager.NameNotFoundException; |
16 import android.net.Uri; | 17 import android.net.Uri; |
17 import android.os.Build; | 18 import android.os.Build; |
18 import android.os.Looper; | 19 import android.os.Looper; |
19 import android.os.Process; | 20 import android.os.Process; |
20 import android.os.StrictMode; | 21 import android.os.StrictMode; |
21 import android.provider.Settings; | 22 import android.provider.Settings; |
22 import android.util.Log; | 23 import android.util.Log; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 import org.chromium.base.TraceEvent; | 60 import org.chromium.base.TraceEvent; |
60 import org.chromium.base.annotations.SuppressFBWarnings; | 61 import org.chromium.base.annotations.SuppressFBWarnings; |
61 import org.chromium.base.library_loader.LibraryLoader; | 62 import org.chromium.base.library_loader.LibraryLoader; |
62 import org.chromium.base.library_loader.LibraryProcessType; | 63 import org.chromium.base.library_loader.LibraryProcessType; |
63 import org.chromium.base.library_loader.ProcessInitException; | 64 import org.chromium.base.library_loader.ProcessInitException; |
64 import org.chromium.content.browser.ContentViewStatics; | 65 import org.chromium.content.browser.ContentViewStatics; |
65 import org.chromium.net.NetworkChangeNotifier; | 66 import org.chromium.net.NetworkChangeNotifier; |
66 import org.chromium.ui.base.ResourceBundle; | 67 import org.chromium.ui.base.ResourceBundle; |
67 | 68 |
68 import java.io.File; | 69 import java.io.File; |
70 import java.lang.reflect.InvocationTargetException; | |
69 import java.util.Queue; | 71 import java.util.Queue; |
70 import java.util.concurrent.Callable; | 72 import java.util.concurrent.Callable; |
71 import java.util.concurrent.ConcurrentLinkedQueue; | 73 import java.util.concurrent.ConcurrentLinkedQueue; |
72 import java.util.concurrent.FutureTask; | 74 import java.util.concurrent.FutureTask; |
73 import java.util.concurrent.TimeUnit; | 75 import java.util.concurrent.TimeUnit; |
74 | 76 |
75 /** | 77 /** |
76 * Entry point to the WebView. The system framework talks to this class to get i nstances of the | 78 * Entry point to the WebView. The system framework talks to this class to get i nstances of the |
77 * implementation classes. | 79 * implementation classes. |
78 */ | 80 */ |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter. | 194 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter. |
193 */ | 195 */ |
194 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { | 196 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { |
195 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); | 197 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); |
196 } | 198 } |
197 | 199 |
198 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 200 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
199 private void initialize(WebViewDelegate webViewDelegate) { | 201 private void initialize(WebViewDelegate webViewDelegate) { |
200 mWebViewDelegate = webViewDelegate; | 202 mWebViewDelegate = webViewDelegate; |
201 | 203 |
202 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication()); | 204 Context ctx = switchToCredentialProtectedStorage( |
205 mWebViewDelegate.getApplication().getApplicationContext()); | |
203 | 206 |
204 // WebView needs to make sure to always use the wrapped application cont ext. | 207 // WebView needs to make sure to always use the wrapped application cont ext. |
205 ContextUtils.initApplicationContext( | 208 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx)); |
206 ResourcesContextWrapperFactory.get( | |
207 mWebViewDelegate.getApplication().getApplicationContext( ))); | |
208 | 209 |
209 if (isBuildDebuggable()) { | 210 if (isBuildDebuggable()) { |
210 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds. | 211 // Suppress the StrictMode violation as this codepath is only hit on debuggable builds. |
211 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); | 212 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); |
212 CommandLine.initFromFile(COMMAND_LINE_FILE); | 213 CommandLine.initFromFile(COMMAND_LINE_FILE); |
213 StrictMode.setThreadPolicy(oldPolicy); | 214 StrictMode.setThreadPolicy(oldPolicy); |
214 } else { | 215 } else { |
215 CommandLine.init(null); | 216 CommandLine.init(null); |
216 } | 217 } |
217 | 218 |
(...skipping 28 matching lines...) Expand all Loading... | |
246 } | 247 } |
247 if (lastVersion != currentVersion) { | 248 if (lastVersion != currentVersion) { |
248 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); | 249 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); |
249 } | 250 } |
250 | 251 |
251 mShouldDisableThreadChecking = | 252 mShouldDisableThreadChecking = |
252 shouldDisableThreadChecking(ContextUtils.getApplicationContext() ); | 253 shouldDisableThreadChecking(ContextUtils.getApplicationContext() ); |
253 // Now safe to use WebView data directory. | 254 // Now safe to use WebView data directory. |
254 } | 255 } |
255 | 256 |
256 static void checkStorageIsNotDeviceProtected(Context context) { | 257 // Webview must use a CredentialEncrypted Context. If context is a CE contex t, then simply |
258 // return it without modification. Otherwise, create a new CE context and re turn that instead. | |
259 static Context switchToCredentialProtectedStorage(Context context) { | |
260 // For versions N+, android webview must use a CredentialEncrypted Conte xt | |
257 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) | 261 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) |
258 && context.isDeviceProtectedStorage()) { | 262 && context.isDeviceProtectedStorage()) { |
259 throw new IllegalArgumentException( | 263 ApplicationInfo appInfo = context.getApplicationInfo(); |
260 "WebView cannot be used with device protected storage"); | 264 try { |
265 // Check the manifest flag android:defaultToDeviceProtectedStora ge | |
Torne
2016/09/21 12:04:18
I'm not sure there's any point in actually checkin
Nate Fischer
2016/09/22 04:21:12
Ok, I misunderstood the bug report. I've removed t
| |
266 boolean defaultsToDeviceProtection = | |
267 (Boolean) appInfo.getClass() | |
268 .getMethod("isDefaultToDeviceProtectedStorage") | |
269 .invoke(appInfo); | |
270 // For system applications using the flag, attempt to use a CE c ontext if it's | |
271 // available | |
272 if (defaultsToDeviceProtection) { | |
273 context = context.createCredentialProtectedStorageContext(); | |
274 } | |
275 | |
276 // If this application does not default to DE storage, or we wer e unable to create a | |
277 // CE context | |
278 if (context.isDeviceProtectedStorage()) { | |
279 throw new IllegalArgumentException( | |
280 "WebView cannot be used with device protected storag e"); | |
281 } | |
282 } catch (NoSuchMethodException | InvocationTargetException | Illegal AccessException | |
283 | IllegalArgumentException e) { | |
284 throw new IllegalArgumentException( | |
285 "WebView cannot be used with device protected storage"); | |
286 } | |
261 } | 287 } |
288 return context; | |
262 } | 289 } |
263 | 290 |
264 private static boolean isBuildDebuggable() { | 291 private static boolean isBuildDebuggable() { |
265 return !Build.TYPE.equals("user"); | 292 return !Build.TYPE.equals("user"); |
266 } | 293 } |
267 | 294 |
268 /** | 295 /** |
269 * Both versionCodes should be from a WebView provider package implemented b y Chromium. | 296 * Both versionCodes should be from a WebView provider package implemented b y Chromium. |
270 * VersionCodes from other kinds of packages won't make any sense in this me thod. | 297 * VersionCodes from other kinds of packages won't make any sense in this me thod. |
271 * | 298 * |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | 673 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); |
647 } | 674 } |
648 } | 675 } |
649 return mWebViewDatabase; | 676 return mWebViewDatabase; |
650 } | 677 } |
651 | 678 |
652 WebViewDelegate getWebViewDelegate() { | 679 WebViewDelegate getWebViewDelegate() { |
653 return mWebViewDelegate; | 680 return mWebViewDelegate; |
654 } | 681 } |
655 } | 682 } |
OLD | NEW |