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. Bug: 162725876 Fixes: 162725876 Test: 1. atest -v TransportManagerTest 2. 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: I7bd397f0f1eadbbca6f371c3c9710df5386aca13
Loading
Please register or sign in to comment