[webview_flutter] Filter onChanged events for invalid displays (#1964)

Works around an Android WebView bug that was causing a crash by filtering some DisplayListener invocations.

Older Android WebView versions had assumed that when DisplayListener#onDisplayChanged is invoked, the display ID it is provided is of a valid display. However it turns out that when a display is removed Android may call onDisplayChanged with the ID of the removed display, in this case the Android WebView code tries to fetch and use the display with this ID and crashes with an NPE.

The issue was fixed in the Android WebView code in https://chromium-review.googlesource.com/517913 which is available starting WebView version 58.0.3029.125 however older webviews in the wild still have this issue.

Since Flutter removes virtual displays whenever a platform view is resized the webview crash is more likely to happen than other apps. And users were reporting this issue see: flutter/flutter#30420

This change works around the webview bug by unregistering the WebView's DisplayListener, and instead registering our own DisplayListener which delegates the callbacks to the WebView's listener unless it's a onDisplayChanged for an invalid display.
6 files changed
tree: 2462b624ea55edb83bfe93cde3cf63ef6e175aaf
  1. .ci/
  2. .github/
  3. .opensource/
  4. examples/
  5. packages/
  6. script/
  7. .cirrus.yml
  8. .gitattributes
  9. .gitignore
  10. analysis_options.yaml
  11. AUTHORS
  12. CODEOWNERS
  13. CONTRIBUTING.md
  14. FlutterFire.md
  15. LICENSE
  16. README.md
README.md

Flutter plugins

Build Status

This repo is a companion repo to the main flutter repo. It contains the source code for Flutter first-party plugins (i.e., plugins developed by the core Flutter team). Check the packages directory for all plugins.

Flutter plugins enable access to platform-specific APIs. For more information about plugins, and how to use them, see https://flutter.dev/platform-plugins/.

These plugins are also available on pub.

Issues

Please file any issues, bugs, or feature requests in the main flutter repo.

Contributing

If you wish to contribute a new plugin to the Flutter ecosystem, please see the documentation for developing packages and platform channels. You can store your plugin source code in any GitHub repository (the present repo is only intended for plugins developed by the core Flutter team). Once your plugin is ready you can publish to the pub repository.

If you wish to contribute a change to any of the existing plugins in this repo, please review our contribution guide, and send a pull request.

Plugins

These are the available plugins in this repository.

PluginPub
android_alarm_managerpub package
android_intentpub package
batterypub package
camerapub package
connectivitypub package
device_infopub package
google_maps_flutterpub package
google_sign_inpub package
image_pickerpub package
in_app_purchasepub package
local_authpub package
package_infopub package
path_providerpub package
quick_actionspub package
sensorspub package
sharepub package
shared_preferencespub package
url_launcherpub package
video_playerpub package
webview_flutterpub package
FlutterFire Plugins
cloud_firestorepub package
cloud_functionspub package
firebase_admobpub package
firebase_analyticspub package
firebase_authpub package
firebase_corepub package
firebase_crashlyticspub package
firebase_databasepub package
firebase_dynamic_linkspub package
firebase_in_app_messagingpub package
firebase_messagingpub package
firebase_ml_visionpub package
firebase_performancepub package
firebase_remote_configpub package
firebase_storagepub package

Learn more about FlutterFire.