blob: d47c65a4411a6ab484d9568c16facbb3655fb6c8 [file] [log] [blame] [view]
Nate Fischerdab822612020-06-30 20:07:181# WebView Providers
2
3Since Android Lollipop, WebView has been an updateable system component, with
4the updateable part of the implementation distributed as an APK or App Bundle.
5We refer to this updateable package as the "WebView provider" on the device.
6
7[TOC]
8
9## WebView provider options
10
11Some OS images permit users to change their WebView provider to a non-default
12package while other images only support a single preinstalled default. This
13table captures the WebView provider options for the most common device
14configurations:
15
16<!-- Keep this table in sync with build-instructions.md and the table below -->
17| API level | Has GMS vs. AOSP? | Allowed apps |
18| -------------------- | ----------------- | ------------ |
19| L-M | AOSP | Standalone AOSP WebView **(default, preinstalled)** |
20| L-M | Has GMS | Standalone Google WebView **(default, preinstalled)** |
21| N-P | AOSP | Standalone AOSP WebView **(default, preinstalled)** |
22| N-P (TV/car devices) | Has GMS | Standalone Google WebView **(default, preinstalled)** |
23| N-P (other devices) | Has GMS | Monochrome Stable **(default, preinstalled)**<br>Monochrome Beta<br>Monochrome Dev<br>Monochrome Canary<br>Monochrome (no channel) **(only userdebug/eng)**<br>Google WebView Stub **(preinstalled)** or Standalone Google WebView (see [Important notes for N-P](build-instructions.md#Important-notes-for-N-P)) |
24| >= Q | AOSP | Standalone AOSP WebView **(default, preinstalled)** |
25| >= Q | Has GMS | Trichrome WebView Google Stable **(default, preinstalled)**<br>Trichrome WebView Google Beta<br>Trichrome WebView Google Dev<br>Trichrome WebView Google Canary<br>Trichrome WebView Google (no channel) **(only userdebug/eng)**<br>Standalone AOSP WebView or Trichrome WebView AOSP **(only userdebug/eng)** |
26
27*** aside
28[Vendors modifying AOSP][aosp] can configure which providers are compatible with
29their OS image, although they often stick with the default configuration (marked
30above as "AOSP").
31
32Vendors shipping OS images which include GMS and the Play Store must use
33Google's provided WebView configuration (marked above as "Has GMS"). This is to
34ensure Google can deliver WebView updates to users, and we enforce this with GTS
35tests. Most production Android devices use this configuration.
36***
37
38### The currently selected WebView provider
39
40Most devices use the **default** option listed in the table above. If your
41device supports multiple options, you can figure out which is currently selected
42by:
43
44* Looking in [developer settings](prerelease.md#switch-channel)
45* With the [commandline](quick-start.md#Troubleshooting) (look for "Current
46 WebView package," only works on O+)
47
48### Switching WebView provider
49
50On Nougat and above, you can switch WebView providers [in developer
51settings](prerelease.md#switch-channel) or in your terminal:
52
53```sh
54# If you're building an app locally (change "system_webview_apk" as desired):
55$ autoninja -C out/Default system_webview_apk
56$ out/Default/bin/system_webview_apk install
57$ out/Default/bin/system_webview_apk set-webview-provider
58
59# Or, if you've already installed the app (change "com.android.webview" as
60# desired):
61$ adb shell cmd webviewupdate set-webview-implementation com.android.webview
62```
63
64## WebView provider requirements
65
66A package must fulfill several requirements to be eligible to be a WebView
67provider. These requirements are enforced by the **WebView Update Service**,
68which runs as part of the Android framework on the device.
69
70### Installed and enabled
71
72On Android O+, an eligible WebView provider must be installed and enabled for
73**all user profiles** (some Android features are implemented behind the scenes
74with [multiple user profiles](prerelease.md#multiple-profiles)). On Android L-N,
75the package only needs to be installed and enabled for the default user profile.
76
77If you uninstall (or disable) the selected WebView provider, the WebView Update
78Service will fallback to a different package based on an ordered preference (the
79order is [predetermined in the OS image][aosp]). If there are no more eligible
80packages (if this was the only package or the user disabled/removed all other
81packages), WebView will simply not work and WebView-based apps will crash until
82the user re-enables one of the packages.
83
84On Android N-P, `com.google.android.webview` and `com.android.chrome` are
85mutually exclusive, due to "fallback logic." Disabling (or enabling) Chrome will
86enable (or disable) the WebView stub. See [Important notes for
87N-P](build-instructions.md#Important-notes-for-N-P) for more information.
88
89### Package name
90
91For security reasons, Android will only permit a predetermined list of package
92names to act as WebView provider. The WebView team provides several different
93preset lists, depending how the Android image will be configured.
94
95<!-- Keep this table in sync with build-instructions.md and the table above -->
96| API level | Has GMS vs. AOSP? | Allowed package names |
97| -------------------- | ----------------- | --------------------- |
98| L-M | AOSP | `com.android.webview` **(default, preinstalled)** |
99| L-M | Has GMS | `com.google.android.webview` **(default, preinstalled)** |
100| N-P | AOSP | `com.android.webview` **(default, preinstalled)** |
101| N-P (TV/car devices) | Has GMS | `com.google.android.webview` **(default, preinstalled)** |
102| N-P (other devices) | Has GMS | `com.android.chrome` **(default, preinstalled)**<br>`com.chrome.beta`<br>`com.chrome.dev`<br>`com.chrome.canary`<br>`com.google.android.apps.chrome` **(only userdebug/eng)**<br>`com.google.android.webview` **(preinstalled)** (see [Important notes for N-P](build-instructions.md#Important-notes-for-N-P)) |
103| >= Q | AOSP | `com.android.webview` **(default, preinstalled)** |
104| >= Q | Has GMS | `com.google.android.webview` **(default, preinstalled)**<br>`com.google.android.webview.beta`<br>`com.google.android.webview.dev`<br>`com.google.android.webview.canary`<br>`com.google.android.webview.debug` **(only userdebug/eng)**<br>`com.android.webview` **(only userdebug/eng)** |
105
106*** aside
107The package name list can be [configured in AOSP][aosp].
108***
109
110### Signature (for user builds)
111
112For security reasons, Android also checks the signature of WebView providers,
113only permitting apps signed with the expected release keys.
114
115This requirement is waived on userdebug/eng devices so we can install local
116WebView builds (which don't have release keys) on test devices.
117
118*** aside
119The signatures can be [configured in AOSP][aosp].
120***
121
122### targetSdkVersion
123
124A valid WebView provider must implement all the APIs exposed in that version of
125the Android platform, otherwise calling a new API will crash at runtime. WebView
126Update Service can't reliably determine which APIs a provider implements, so we
127decided to use `targetSdkVersion` as a proxy for this:
128
129* For a finalized Android version, a valid WebView provider must declare
130 a `targetSdkVersion` greater than or equal to the platform's
131 [`Build.VERSION.SDK_INT`](https://developer.android.com/reference/android/os/Build.VERSION#SDK_INT)
132 value.
133* For a pre-release (AKA in-development) Android version, a valid WebView
134 provider must declare a `targetSdkVersion` equal to
135 [`Build.VERSION_CODES.CUR_DEVELOPMENT`](https://developer.android.com/reference/android/os/Build.VERSION_CODES#CUR_DEVELOPMENT)
136 and be compiled with the corresponding pre-release SDK.
137
138In the Chromium repo, we configure this in GN args by setting
139`android_sdk_release = "x"`, where "x" is the lowercase codename letter of the
140desired OS version. Upstream chromium code usually only supports the latest
141public Android version, so you should use that value for all public Android OS
142versions. Googlers building with the internal repository may be able to override
143this to target the current pre-release Android version.
144
145*** note
146**Note:** it is not sufficient to simply change `targetSdkVersion` in the APK:
147new API calls will still crash at runtime! You should only configure this with
148`android_sdk_release = "x"`, as this also pulls in the code to implement new
149Android APIs. See [WebView for AOSP system
150integrators](aosp-system-integration.md#pre-release) for details.
151***
152
153### versionCode
154
155We enforce a minimum `versionCode` both for security (to prevent downgrade
156attacks) and correctness (this ensures the package can implement all the new
157WebView APIs in the new version of the OS). This is computed at runtime by the
158WebView Update Service by taking the minimum of all valid WebView providers
159installed on the system image.
160
161You generally should not hit this issue for local builds, but may see this if
162you're trying to install a really old WebView official build.
163
164### Declare a native library
165
166Because WebView is implemented partially in C++, the Android framework must load
167its native library. On L, the native library must be called
168`libwebviewchromium.so`. Starting with M and above, the native library must be
169declared by the `com.android.webview.WebViewLibrary` metadata tag in
170`AndroidManifest.xml`. See [Loading native code with RELRO
171sharing](how-does-loading-work.md#Loading-native-code-with-RELRO-sharing) for
172more details if you're curious how this process works.
173
174You generally should not hit this issue unless you're trying to install a target
175which is not WebView-capable (ex. `chrome_public_apk` instead of
176`monochrome_public_apk`).
177
178[aosp]: aosp-system-integration.md#Configuring-the-Android-framework