New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 628627 link

Starred by 5 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Sep 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug

Blocking:
issue 628650



Sign in to add a comment

WebView 51 and onwards causes StrictMode violation on startup

Project Member Reported by gsennton@chromium.org, Jul 15 2016

Issue description

Stack:

07-15 15:34:41.062 13272 13272 D StrictMode: StrictMode policy violation; ~duration=92 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=327682 violation=2
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1293)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:249)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at java.io.File.exists(File.java:780)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:521)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.app.ContextImpl.getPreferencesDir(ContextImpl.java:477)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.app.ContextImpl.getSharedPreferencesPath(ContextImpl.java:655)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:354)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:164)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:164)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:487)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.base.ContextUtils.fetchAppSharedPreferences(ContextUtils.java:78)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.base.ContextUtils.access$000(ContextUtils.java:17)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.base.ContextUtils$Holder.<clinit>(ContextUtils.java:26)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.base.ContextUtils$Holder.access$100(ContextUtils.java:24)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.base.ContextUtils.getAppSharedPreferences(ContextUtils.java:89)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.policy.AbstractAppRestrictionsProvider.getCachedPolicies(AbstractAppRestrictionsProvider.java:142)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.policy.AbstractAppRestrictionsProvider.refresh(AbstractAppRestrictionsProvider.java:94)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.policy.CombinedPolicyProvider.linkNativeInternal(CombinedPolicyProvider.java:45)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.policy.CombinedPolicyProvider.linkNative(CombinedPolicyProvider.java:54)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.content.app.ContentMain.nativeStart(Native Method)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.content.app.ContentMain.start(ContentMain.java:25)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.content.browser.BrowserStartupController.contentStart(BrowserStartupController.java:233)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.content.browser.BrowserStartupController.startBrowserProcessesSync(BrowserStartupController.java:215)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.android_webview.AwBrowserProcess$1.run(AwBrowserProcess.java:88)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.base.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:67)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at org.chromium.android_webview.AwBrowserProcess.start(AwBrowserProcess.java:78)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.startChromiumLocked(WebViewChromiumFactoryProvider.java:310)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.ensureChromiumStartedLocked(WebViewChromiumFactoryProvider.java:251)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.startYourEngines(WebViewChromiumFactoryProvider.java:342)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:224)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.WebView.<init>(WebView.java:636)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.WebView.<init>(WebView.java:572)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.WebView.<init>(WebView.java:555)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.WebView.<init>(WebView.java:542)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.WebView.<init>(WebView.java:532)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.cts.WebViewStartupCtsActivity.createAndAttachWebView(WebViewStartupCtsActivity.java:33)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.webkit.cts.WebViewStartupTest.testStrictModeNotViolatedOnStartup(WebViewStartupTest.java:103)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at java.lang.reflect.Method.invoke(Native Method)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:220)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.test.InstrumentationTestCase.-wrap0(InstrumentationTestCase.java)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.test.InstrumentationTestCase$2.run(InstrumentationTestCase.java:195)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1950)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.os.Handler.handleCallback(Handler.java:751)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.os.Handler.dispatchMessage(Handler.java:95)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.os.Looper.loop(Looper.java:154)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at android.app.ActivityThread.main(ActivityThread.java:6077)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at java.lang.reflect.Method.invoke(Native Method)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
07-15 15:34:41.062 13272 13272 D StrictMode: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)


cc'ing dgn@ and aberent@ who have been touching AbstractAppRestrictionsProvider

This is from a ToT build, it has been failing since 51 :( (but with a slightly different call stack back then)
 
Blocking: 628650
Also affects Android N Developer Preview 5 (tested on Nexus 9), with Chrome Stable listed as the WebView implementation.

This has been an issue since Android 5.0 (see  issue #425820 , reported by me nearly two years ago).

Attached, please find a sample project that can reproduce the error.

Browser1.zip
25.9 KB Download
Labels: -Pri-3 Pri-1

Comment 4 by boliu@chromium.org, Jul 22 2016

Labels: -Pri-1 Pri-3
why p1? is this affecting you?

Comment 5 by sgu...@chromium.org, Jul 22 2016

Owner: dgn@chromium.org
Status: Assigned (was: Untriaged)
dgn@ can you please verify if it is one of your changes that introduced this? thanks

Comment 6 by dgn@chromium.org, Jul 25 2016

Owner: aber...@chromium.org
aberent@ started looking into this. We need to read the preferences on startup, and because they already preloaded by some other things in Chrome, we don't have the strict mode violation issue. But for WebView they are not so we trigger the I/O path which causes the violation.

aberent@: What was your conclusion about how we should fix this?
The only two solutions are:
1. Somehow warm up the preferences in WebView early in startup (I don't know enough about WebView startup to know if this is possible).
2. Disable strict mode checking in this component when reading the preferences.

Note that the policy caching in this component was originally introduced to avoid a strict mode issue with fetching the app restrictions. If we were to disable strict mode checking in this module then maybe we should reconsider the need for a policy cache, since, in practice both reading app restrictions and reading preferences end up as reading files.

Comment 8 by torne@chromium.org, Jul 25 2016

It's unlikely that there's anywhere in webview start we can warm up prefs early enough to avoid this all the time; the webview start process is too "compressed" and most of it happens in one big chunk. I think we'll just have to mask strict mode here, and look at the effect on startup performance :/

Comment 9 by torne@chromium.org, Sep 7 2016

This is still happening and surprising apps (see internal b/31319364 for the most recent example) - we need to at least put on the band-aid of temporarily disabling strict mode while we do this to avoid breaking webview apps, but we should still look at whether this can be avoided as well.

Comment 10 by kmans...@gmail.com, Sep 15 2016

Seeing this too in my app's debug builds (where I've enabled strict mode).

Current WebView version is 54.0.2840.25

Detailed stack trace:

09-15 12:10:12.219 E/StrictMode(24516): java.lang.Throwable: Explicit termination method 'close' not called
09-15 12:10:12.219 E/StrictMode(24516): 	at dalvik.system.CloseGuard.open(CloseGuard.java:180)
09-15 12:10:12.219 E/StrictMode(24516): 	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:127)
09-15 12:10:12.219 E/StrictMode(24516): 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.startChromiumLocked(WebViewChromiumFactoryProvider.java:16107)
09-15 12:10:12.219 E/StrictMode(24516): 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.ensureChromiumStartedLocked(WebViewChromiumFactoryProvider.java:334)
09-15 12:10:12.219 E/StrictMode(24516): 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.startYourEngines(WebViewChromiumFactoryProvider.java:417)
09-15 12:10:12.219 E/StrictMode(24516): 	at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:162)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.webkit.WebView.<init>(WebView.java:618)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.webkit.WebView.<init>(WebView.java:554)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.webkit.WebView.<init>(WebView.java:537)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.webkit.WebView.<init>(WebView.java:524)
09-15 12:10:12.219 E/StrictMode(24516): 	at org.kman.AquaMail.view.MessageWebView.<init>(MessageWebView.java:34)
09-15 12:10:12.219 E/StrictMode(24516): 	at org.kman.AquaMail.view.MessageDisplayWebView.<init>(MessageDisplayWebView.java:34)
09-15 12:10:12.219 E/StrictMode(24516): 	at java.lang.reflect.Constructor.newInstance(Native Method)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.createView(LayoutInflater.java:631)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:855)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
09-15 12:10:12.219 E/StrictMode(24516): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:429)


Please do not fudge by disabling strict mode -- developers will want strict mode to remain enabled, as configured by their apps, so it does what it's supposed to do.

Why not just properly close the file?
Re #10: to me this looks as if it coming from a different place. The original problem is caused by AbstractAppRestrictionsProvider reading the preferences synchronously early in startup, and doesn't relate to closing the file. The new stack trace doesn't involve AbstractAppRestrictionsProvider, so must have a different cause.

The CL I am about to land, to fix the original problem, only disables strict mode checking very briefly (for the duration of one file read), and then restores its original state, so should not affect developers' ability to check app is behaving correctly.
Project Member

Comment 12 by bugdroid1@chromium.org, Sep 15 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/e4795a72b9d0c53c0e32911f1562a432e0ad4ee7

commit e4795a72b9d0c53c0e32911f1562a432e0ad4ee7
Author: aberent <aberent@chromium.org>
Date: Thu Sep 15 10:02:25 2016

Remove the Android policy cache

The Android policy cache was originally created to avoid Strict Mode
violations, but doesn't do so in Webview. Actually, although reading
the app restrictions on the UI thread is a strict mode violation it
is unlikely to cause UI visible delays, As such the solution is to
simply to allow file reads in this component.

BUG= 628627 

Review-Url: https://codereview.chromium.org/2322963002
Cr-Commit-Position: refs/heads/master@{#418818}

[modify] https://crrev.com/e4795a72b9d0c53c0e32911f1562a432e0ad4ee7/components/policy/android/java/src/org/chromium/policy/AbstractAppRestrictionsProvider.java
[modify] https://crrev.com/e4795a72b9d0c53c0e32911f1562a432e0ad4ee7/components/policy/android/junit/src/org/chromium/policy/AbstractAppRestrictionsProviderTest.java

Status: Fixed (was: Assigned)
Closing this bug, since the original issue is now fixed. kmansoft@, please create a new bug with details of how to reproduce (which app etc.).

Comment 14 by kmans...@gmail.com, Sep 15 2016

@13:

1 - New bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=647291

2 - Re: "reading prefs on the UI thread is no big deal" -- it's not a small deal either.

First line in the first message:

StrictMode policy violation; ~duration=92 ms

92 ms is enough to cause substantial animation jitter. Android docs highly recommend trying to hit 60 fps, which is only 16 ms per frame.

Comment 15 by torne@chromium.org, Sep 15 2016

It happens at most once, during startup. So yes, this may cause frameskip of a loading animation or similar, but will not affect applications while they're actually running.

Sign in to add a comment