Skip to content

Enable WebViewFasterGetDefaultUserAgent by default#1140

Draft
inthewaves wants to merge 1 commit into
GrapheneOS:mainfrom
inthewaves:webviewuseragent-fast
Draft

Enable WebViewFasterGetDefaultUserAgent by default#1140
inthewaves wants to merge 1 commit into
GrapheneOS:mainfrom
inthewaves:webviewuseragent-fast

Conversation

@inthewaves
Copy link
Copy Markdown
Member

Closes #1139
Applies on #1138

Apps, in particular ones that use Google Mobile Ads SDK, can dead lock. A worker thread in the Mobile Ads SDK holds a singleton lock and calls WebSettings.getDefaultUserAgent() which block until a task posted to the main thread to initialize WebView finishes. Meanwhile, the main thread of the app enters Mobile Ads SDK. If the Dynamite ads module is not available, the library has a local fallback path which attempts to acquires the singleton lock that the worker thread is holding. The result is that the main thread gets blocked on a lock held by the worker thread which is waiting for main thread to process its task.

Dynamite ads module can be unavailable if Play services + Play Store are not installed (or have some other issue). This would block users from using any app with SDK used in this way.

By enabling this feature, the worker thread no longer waits on the initialization task posted to main thread to finish and gets a user agent immediately. This works around this deadlock.

Note that Vanadium config doesn't handle WebViewCachedFlags which is meant to be fast and designed around SharedPreferences. The feature is only read in the relevant location from WebViewCachedFlags, so the native feature change is just for completeness.

Test: Install app like com.faitaujapon.otg which had this issue. With no Play services install, app no longer ANRs on start
Test: tools/autotest.py -C out/Default android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewThreadTest.java

Apps, in particular ones that use Google Mobile Ads SDK, can dead lock. A worker thread in the
Mobile Ads SDK holds a singleton lock and calls WebSettings.getDefaultUserAgent() which block until
a task posted to the main thread to initialize WebView finishes. Meanwhile, the main thread of the
app enters Mobile Ads SDK. If the Dynamite ads module is not available, the library has a local
fallback path which attempts to acquires the singleton lock that the worker thread is holding. The
result is that the main thread gets blocked on a lock held by the worker thread which is waiting for
main thread to process its task.

Dynamite ads module can be unavailable if Play services + Play Store are not installed (or have some
other issue). This would block users from using any app with SDK used in this way.

By enabling this feature, the worker thread no longer waits on the initialization task posted to
main thread to finish and gets a user agent immediately. This works around this deadlock.

Note that Vanadium config doesn't handle WebViewCachedFlags which is meant to be fast and designed
around SharedPreferences. The feature is only read in the relevant location from WebViewCachedFlags,
so the native feature change is just for completeness.

Test: Install app like com.faitaujapon.otg which had this issue. With no Play services install, app
no longer ANRs on start
Test: tools/autotest.py -C out/Default \
  android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewThreadTest.java
@inthewaves inthewaves marked this pull request as draft May 22, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable WEBVIEW_FASTER_GET_DEFAULT_USER_AGENT feature to workaround deadlocks in Google Mobile Ads SDK

1 participant