Ensure PM watches all Watchables
Bug: 179388643 The bug occurs because two Watchables were not being observed by PackageManagerService. The two Watchables are mSettings and mInstantAppRegistry. The bug should have been detected by Watchable.verifyWatchedAttributes() but that, too had a bug: the PackageManagerService attributes were not visible to the Watchable package so the verification code got an IllegalAccessException, which caused the attributes to be silently ignored. The following changes are made: 1. PackageManagerService now registers with the missing Watchables. 2. Registration is moved to a function that is called in two places. 3. The verification code is enhanced to ensure fields are accessible. A RuntimeException is thrown if the field is still not accessible. Note that only fields annotated with @Watched can generate this exception. 4. PackageManagerVerification is skipped (log-only on errors) if it appears to be part of a mockito test. 4. Settings now registers with a missing Watchable. The Watchable is not actually used in Settings (see the TODO at the attribute declaration) but this CL assumes that it might be used in the future. 6. One import order violation was corrected. In addition to automated tests, the changes were tested with an instrumented PackageManagerService that enabled snapshots and skipped registration with one or more observers. All attributes were tested one by one. Test: atest * FrameworksServicesTests:UserSystemPackageInstallerTest * FrameworksServicesTests:PackageManagerSettingsTests * FrameworksServicesTests:PackageManagerServiceTest * FrameworksServicesTests:AppsFilterTest * FrameworksServicesTests:PackageInstallerSessionTest * FrameworksServicesTests:ScanTests * UserLifecycleTests#startUser * UserLifecycleTests#stopUser * UserLifecycleTests#switchUser * android.appsecurity.cts.EphemeralTest#testEphemeralStartExposed06 * android.appsecurity.cts.InstantAppUserTest#testStartExposed06 * com.android.server.pm.PackageManagerServiceBootTest Change-Id: Ib2b14c4745bd5e5ab2882ed6fe953d7da2df4087
Loading
Please register or sign in to comment