Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 8354946c authored by Paul Hadfield's avatar Paul Hadfield
Browse files

Fix onPackageChanged handling of disabled packages

TransportManager#onPackageChanged was not correctly handling the
circumstance where broadcast ACTION_PACKAGE_CHANGED was received
with EXTRA_CHANGED_COMPONENT_NAME_LIST containing only the
package name, instead of >=1 component names.  When that happens
it indicates that a package-wide change has occurred, such as
the package being enabled or disabled.

If the package in question contains backup transports, they
should be unregistered if the package is disabled, and re-
registered if the package is enabled.  But the current
TransportManager#onPackageChanged doesn't know enough to do so.

We can determine the enabled state of the package by calling
PackageManager#getApplicationEnabledSetting. This commit modifies
onPackageChanged to do that, and then (un/re)-register the
packaged transports as appropriate.

To test I extend the Roboelectric ShadowApplicationPackageManager
so that the {get,set}ApplicationEnabledState() methods are
exposed for use in the test setup.

Note, this is a retake of ag/15301455, with handling added for a
race condition which caused flakiness in CtsUtilTestCases: the
onPackageChanged method must handle a possible exception thrown
by the PackageManager if the package has just been removed.

Bug: 162725876
Fixes: 162725876
Test: 1. atest -v TransportManagerTest
      2. atest CtsBackupHostTestCases|CtsBackupTestCases|CtsUtilTestCases
      3. manual test on device:
           1 device:/ # bmgr list transports
           2 device:/ # pm disable com.google.android.gms
           3 device:/ # bmgr list transports
           4 device:/ # pm enable com.google.android.gms
           5 device:/ # bmgr list transports
         observe logcat showing BackupTransportManager MORE_DEBUG:
	   step 2: Package c.g.a.gms was disabled.
	   step 4: Package c.g.a.gms was enabled.
	           Transport c.g.a.gms/.b.c.D2dTransportService registered
Change-Id: I1ba20a50dfb9a6918605bbd3216a08f0047e2c10
(cherry picked from commit d68bb378)
parent a8196fc5
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment