Correct snapshot races
Bug: 185481065
This fixes the race conditions that could theoretically cause
PackageManager snapshots to fail, especially after package
installation. No failures have actually been observed.
1. Three arrays in Settings are now watched. Other attributes that
are included in the snapshot are annotated @Watched(manual = true).
untrackedStorage() is used for these arrays during XML read/rwrite
operations.
Also, KeySetManagerService now takes a WatchedArrayMap from
Settings, instead of untrackedStorage(). KeySetManagerService
should not alter the array, but if it does, Settings will learn
about it.
2. Key attributes in SnapshotCache are volatile. This should not be
necessary, since snapshots are only modified under PM mLock, but
the change is made just in case.
3. PackageManagerService.sSnapshotInvalid is now an atomic. This
should eliminate narrow race conditions around the variable.
4. A corking facility is part of PackageManagerService. Corking is
not currently used but it could be valuable to suppress snapshot
creation during very busy periods. This is the same reason for
corking that PropertyInvalidatedCache uses. SnapshotStatistics can
track corking.
5. SnapshotStatistics has a "brief" mode that can be invoked from the
command line. Brief output provides a good overview of snapshot
behavior. Full output (which is the default) is good for more
detailed analysis.
Test: atest
* CtsRoleTestCases
* CtsContentTestCases:IntentFilterTest
* CtsDynamicMimeHostTestCases
* FrameworksServicesTests:UserSystemPackageInstallerTest
* FrameworksServicesTests:PackageManagerSettingsTests
* FrameworksServicesTests:PackageManagerServiceTest
* FrameworksServicesTests:AppsFilterTest
* FrameworksServicesTests:PackageInstallerSessionTest
* FrameworksServicesTests:ScanTests
* UserLifecycleTests#startUser
* UserLifecycleTests#stopUser
* UserLifecycleTests#switchUser
* FrameworksServicesTests:WatcherTest
* android.appsecurity.cts.EphemeralTest
* android.appsecurity.cts.InstantAppUserTest
Change-Id: I111cc4256cbd795fc2aba287f57cfcfd5f9cd7ab
8 files changed