Nate Fischer | dab82261 | 2020-06-30 20:07:18 | [diff] [blame] | 1 | # WebView Providers |
| 2 | |
| 3 | Since Android Lollipop, WebView has been an updateable system component, with |
| 4 | the updateable part of the implementation distributed as an APK or App Bundle. |
| 5 | We refer to this updateable package as the "WebView provider" on the device. |
| 6 | |
| 7 | [TOC] |
| 8 | |
| 9 | ## WebView provider options |
| 10 | |
| 11 | Some OS images permit users to change their WebView provider to a non-default |
| 12 | package while other images only support a single preinstalled default. This |
| 13 | table captures the WebView provider options for the most common device |
| 14 | configurations: |
| 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 |
| 29 | their OS image, although they often stick with the default configuration (marked |
| 30 | above as "AOSP"). |
| 31 | |
| 32 | Vendors shipping OS images which include GMS and the Play Store must use |
| 33 | Google's provided WebView configuration (marked above as "Has GMS"). This is to |
| 34 | ensure Google can deliver WebView updates to users, and we enforce this with GTS |
| 35 | tests. Most production Android devices use this configuration. |
| 36 | *** |
| 37 | |
| 38 | ### The currently selected WebView provider |
| 39 | |
| 40 | Most devices use the **default** option listed in the table above. If your |
| 41 | device supports multiple options, you can figure out which is currently selected |
| 42 | by: |
| 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 | |
| 50 | On Nougat and above, you can switch WebView providers [in developer |
| 51 | settings](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 | |
| 66 | A package must fulfill several requirements to be eligible to be a WebView |
| 67 | provider. These requirements are enforced by the **WebView Update Service**, |
| 68 | which runs as part of the Android framework on the device. |
| 69 | |
| 70 | ### Installed and enabled |
| 71 | |
| 72 | On Android O+, an eligible WebView provider must be installed and enabled for |
| 73 | **all user profiles** (some Android features are implemented behind the scenes |
| 74 | with [multiple user profiles](prerelease.md#multiple-profiles)). On Android L-N, |
| 75 | the package only needs to be installed and enabled for the default user profile. |
| 76 | |
| 77 | If you uninstall (or disable) the selected WebView provider, the WebView Update |
| 78 | Service will fallback to a different package based on an ordered preference (the |
| 79 | order is [predetermined in the OS image][aosp]). If there are no more eligible |
| 80 | packages (if this was the only package or the user disabled/removed all other |
| 81 | packages), WebView will simply not work and WebView-based apps will crash until |
| 82 | the user re-enables one of the packages. |
| 83 | |
| 84 | On Android N-P, `com.google.android.webview` and `com.android.chrome` are |
| 85 | mutually exclusive, due to "fallback logic." Disabling (or enabling) Chrome will |
| 86 | enable (or disable) the WebView stub. See [Important notes for |
| 87 | N-P](build-instructions.md#Important-notes-for-N-P) for more information. |
| 88 | |
| 89 | ### Package name |
| 90 | |
| 91 | For security reasons, Android will only permit a predetermined list of package |
| 92 | names to act as WebView provider. The WebView team provides several different |
| 93 | preset 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 |
| 107 | The package name list can be [configured in AOSP][aosp]. |
| 108 | *** |
| 109 | |
| 110 | ### Signature (for user builds) |
| 111 | |
| 112 | For security reasons, Android also checks the signature of WebView providers, |
| 113 | only permitting apps signed with the expected release keys. |
| 114 | |
| 115 | This requirement is waived on userdebug/eng devices so we can install local |
| 116 | WebView builds (which don't have release keys) on test devices. |
| 117 | |
| 118 | *** aside |
| 119 | The signatures can be [configured in AOSP][aosp]. |
| 120 | *** |
| 121 | |
| 122 | ### targetSdkVersion |
| 123 | |
| 124 | A valid WebView provider must implement all the APIs exposed in that version of |
| 125 | the Android platform, otherwise calling a new API will crash at runtime. WebView |
| 126 | Update Service can't reliably determine which APIs a provider implements, so we |
| 127 | decided 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 | |
| 138 | In 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 |
| 140 | desired OS version. Upstream chromium code usually only supports the latest |
| 141 | public Android version, so you should use that value for all public Android OS |
| 142 | versions. Googlers building with the internal repository may be able to override |
| 143 | this to target the current pre-release Android version. |
| 144 | |
| 145 | *** note |
| 146 | **Note:** it is not sufficient to simply change `targetSdkVersion` in the APK: |
| 147 | new 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 |
| 149 | Android APIs. See [WebView for AOSP system |
| 150 | integrators](aosp-system-integration.md#pre-release) for details. |
| 151 | *** |
| 152 | |
| 153 | ### versionCode |
| 154 | |
| 155 | We enforce a minimum `versionCode` both for security (to prevent downgrade |
| 156 | attacks) and correctness (this ensures the package can implement all the new |
| 157 | WebView APIs in the new version of the OS). This is computed at runtime by the |
| 158 | WebView Update Service by taking the minimum of all valid WebView providers |
| 159 | installed on the system image. |
| 160 | |
| 161 | You generally should not hit this issue for local builds, but may see this if |
| 162 | you're trying to install a really old WebView official build. |
| 163 | |
| 164 | ### Declare a native library |
| 165 | |
| 166 | Because WebView is implemented partially in C++, the Android framework must load |
| 167 | its native library. On L, the native library must be called |
| 168 | `libwebviewchromium.so`. Starting with M and above, the native library must be |
| 169 | declared by the `com.android.webview.WebViewLibrary` metadata tag in |
| 170 | `AndroidManifest.xml`. See [Loading native code with RELRO |
| 171 | sharing](how-does-loading-work.md#Loading-native-code-with-RELRO-sharing) for |
| 172 | more details if you're curious how this process works. |
| 173 | |
| 174 | You generally should not hit this issue unless you're trying to install a target |
| 175 | which 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 |