apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

fix!: Make CoreAndroid plugin instantiate on load #1605

Closed breautek closed 1 year ago

breautek commented 1 year ago

I don't anticipate breaking changes from this change, however it is a difference in behaviour since CoreAndroid won't be lazily loaded, therefore I've marked this commit has a breaking change.

Platforms affected

Android / CoreAndroid plugin

Motivation and Context

CoreAndroid was lazily loaded via getPlugin call. This can create a race condition in some situations, particularly with a new feature in the works: https://github.com/apache/cordova-android/pull/1574 where onRenderProcessGone may be invoked before anything gets a chance to call getPlugin for CoreAndroid.

In general, because this is Core plugin, I feel like it should always be loaded in, not lazily loaded in.

Description

Inside PluginManager, I added a new public API: addService(String serviceName, String className, bool onload). The addService(String serviceName, String className) implementation has been moved to the new public API.

CordovaWebviewImpl will now add the CoreAndroid service with onload set to true.

Testing

Ran npm test on linux. Also manual test while testing the onRenderProcessGone PR.

Checklist

codecov-commenter commented 1 year ago

Codecov Report

Merging #1605 (57369f3) into master (2252c09) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1605   +/-   ##
=======================================
  Coverage   71.82%   71.82%           
=======================================
  Files          23       23           
  Lines        1796     1796           
=======================================
  Hits         1290     1290           
  Misses        506      506           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more