Android WebView: distinguishing defaults from application policy
When updating an Android app, it is important to understand where its WebView file access value comes from: a new default or an explicit setting in application code. Identical false values do not necessarily mean identical policies. For a screen intended only for network pages, it is useful to define an explicit application requirement and verify it across comparable builds. The following is a proposed check for a fictional app we own, ‘Demo Catalog’, rather than a report of measured results or an official test procedure.
Separate the initial value from the application requirement
A WebView receives default settings when it is created; until those settings are changed, getters return those defaults. getAllowFileAccess() indicates whether a particular instance supports file access, while setAllowFileAccess(boolean) enables or disables it. Your checks therefore need to cover your own instance and the point at which configuration is applied.
The API reference ties the default to the app’s targetSdk: true for targets Q and below, and false for targets R and above. This condition concerns the target SDK, rather than the installed Android version on its own. The trust boundary here is the file access capability of a WebView displaying network content; the requirement for that capability should be an application decision that can be checked independently of inherited defaults.
Prepare a log before changing the configuration
For the fictional Demo Catalog app, first prepare controlled test builds with the old and new targetSdk, preserving the existing application configuration. Create a record for each run that lets you reconstruct the observation conditions. A device name or an ‘after update’ label is not enough.
getCurrentWebViewPackage() can return null. If it does, record that the information is unavailable rather than substituting an assumed package or version. The documentation allows this result, for example, when a device is incorrectly configured, lacks WebView support, or lacks an updatable WebView implementation. A null result alone is insufficient to identify a specific cause.
- Build identifier, targetSdk, and Android version.
- The actual WebView provider package name and version returned by getCurrentWebViewPackage() from Jetpack Webkit.
- The WebView creation path, instance identifier, measurement stage, and getAllowFileAccess() result.
- Whether allowFileAccess is set explicitly, its assigned value, and a record of its application to this instance.
Measure the value before and after configuration
For each instance, read getAllowFileAccess() immediately after creation, before application configuration, then read it again once configuration is complete. The first value can only be called a default when you have controlled for the absence of earlier assignments. Check wrapper and factory code as well: otherwise, the ‘first’ measurement may already reflect their decisions.
Records should distinguish the initial value, the explicit assignment, and the final value. If both readings return false, that establishes only that the values match. Evidence of application policy also requires a record showing that the corresponding setting was applied. If a measurement follows unknown configuration, retain it as an observation without drawing a conclusion about the value’s origin.
Compare builds one factor at a time
First compare a pair of builds that differ only in targetSdk: Android, the WebView provider package and version, the creation path, and the application configuration must match. Express the expected initial value in terms of Q and R from the API reference. Do not attribute a difference to the OS version if you changed targetSdk at the same time.
Investigating Android or the provider requires separate pairs in which only the relevant factor changes. If you cannot hold the other conditions constant, or provider information is unavailable, record that limitation of the comparison. Such records help reproduction but cannot attribute a difference to a single cause. Before taking measurements, do not enter expected values in the log as actual results.
Make the policy explicit and repeat the matrix
For the Demo Catalog network screen, we will define this requirement: explicitly apply setAllowFileAccess(false) to every new WebView before the screen is used. After changing the configuration, repeat the previous measurement matrix. Compare before and after separately for each targetSdk, keeping the other conditions unchanged.
The acceptance criterion is a record showing that the policy was applied to the correct instance, together with getAllowFileAccess() == false after configuration is complete. If the initial value was already false, the result confirms that it matches the requirement, while the assignment record confirms that the requirement was explicitly applied. If the final value is true or the assignment was skipped, fix the relevant configuration path and repeat the check.
Check every creation path and screen recreation
Exercise every WebView creation path provided by the app and recreate the screen, including supported recreation following configuration changes. An Activity and its WebView may be destroyed when the device configuration changes or background resources are reclaimed. Repeat both readings and the policy application check for every new instance.
Measure the settings of the new, live instance. Calling a method on a retained WebSettings object after its WebView has been destroyed throws IllegalStateException. Also, before and after the change, open an HTTPS page you own containing synthetic products through each path and check that it displays as expected. A successful HTTP response is insufficient: if the scenario includes selecting a product, compare the displayed selection with the expected one.
Retain the evidence and the limits of the conclusion
The priorities are to establish the value’s origin, ensure an explicit assignment in every creation path, and then maintain a reproducible build comparison. The final log should connect the run conditions, instance, initial value, policy application, and final value. The check is limited to the configuration of instances you own and the display of a test page; it does not include reading local data.
A false value does not mean that every file URL is blocked: the documentation separately preserves access to assets and resources through the special addresses file:///android_asset and file:///android_res. The scenarios checked provide no general or statistical guarantee of WebView security. For an additional assessment of your website or the web portion of your product, you can use CheckMyApp’s free audit.