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

Commit 5733be54 authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] use list caches instead of real lists when snapshotting

The actual lists/maps can be changed when snapshotting, causing system
server crashes.

BUG: 255912832
Test: builds
Change-Id: Ia10b4bd47fb3c1d3de577bc4b1a4a70d0d5adc9f
parent adb0627c
Loading
Loading
Loading
Loading
+72 −22
Original line number Original line Diff line number Diff line
@@ -455,19 +455,24 @@ public final class Settings implements Watchable, Snappable {
    // The user's preferred activities associated with particular intent
    // The user's preferred activities associated with particular intent
    // filters.
    // filters.
    @Watched
    @Watched
    private final WatchedSparseArray<PreferredIntentResolver>
    private final WatchedSparseArray<PreferredIntentResolver> mPreferredActivities;
            mPreferredActivities = new WatchedSparseArray<>();
    private final SnapshotCache<WatchedSparseArray<PreferredIntentResolver>>
            mPreferredActivitiesSnapshot;


    // The persistent preferred activities of the user's profile/device owner
    // The persistent preferred activities of the user's profile/device owner
    // associated with particular intent filters.
    // associated with particular intent filters.
    @Watched
    @Watched
    private final WatchedSparseArray<PersistentPreferredIntentResolver>
    private final WatchedSparseArray<PersistentPreferredIntentResolver>
            mPersistentPreferredActivities = new WatchedSparseArray<>();
            mPersistentPreferredActivities;
    private final SnapshotCache<WatchedSparseArray<PersistentPreferredIntentResolver>>
            mPersistentPreferredActivitiesSnapshot;



    // For every user, it is used to find to which other users the intent can be forwarded.
    // For every user, it is used to find to which other users the intent can be forwarded.
    @Watched
    @Watched
    private final WatchedSparseArray<CrossProfileIntentResolver>
    private final WatchedSparseArray<CrossProfileIntentResolver> mCrossProfileIntentResolvers;
            mCrossProfileIntentResolvers = new WatchedSparseArray<>();
    private final SnapshotCache<WatchedSparseArray<CrossProfileIntentResolver>>
            mCrossProfileIntentResolversSnapshot;


    @Watched
    @Watched
    final WatchedArrayMap<String, SharedUserSetting> mSharedUsers = new WatchedArrayMap<>();
    final WatchedArrayMap<String, SharedUserSetting> mSharedUsers = new WatchedArrayMap<>();
@@ -476,11 +481,12 @@ public final class Settings implements Watchable, Snappable {


    // For reading/writing settings file.
    // For reading/writing settings file.
    @Watched
    @Watched
    private final WatchedArrayList<Signature> mPastSignatures =
    private final WatchedArrayList<Signature> mPastSignatures;
            new WatchedArrayList<Signature>();
    private final SnapshotCache<WatchedArrayList<Signature>> mPastSignaturesSnapshot;

    @Watched
    @Watched
    private final WatchedArrayMap<Long, Integer> mKeySetRefs =
    private final WatchedArrayMap<Long, Integer> mKeySetRefs;
            new WatchedArrayMap<Long, Integer>();
    private final SnapshotCache<WatchedArrayMap<Long, Integer>> mKeySetRefsSnapshot;


    // Packages that have been renamed since they were first installed.
    // Packages that have been renamed since they were first installed.
    // Keys are the new names of the packages, values are the original
    // Keys are the new names of the packages, values are the original
@@ -511,7 +517,8 @@ public final class Settings implements Watchable, Snappable {
     * scanning to make it less confusing.
     * scanning to make it less confusing.
     */
     */
    @Watched
    @Watched
    private final WatchedArrayList<PackageSetting> mPendingPackages = new WatchedArrayList<>();
    private final WatchedArrayList<PackageSetting> mPendingPackages;
    private final SnapshotCache<WatchedArrayList<PackageSetting>> mPendingPackagesSnapshot;


    private final File mSystemDir;
    private final File mSystemDir;


@@ -583,6 +590,26 @@ public final class Settings implements Watchable, Snappable {
        mInstallerPackagesSnapshot =
        mInstallerPackagesSnapshot =
                new SnapshotCache.Auto<>(mInstallerPackages, mInstallerPackages,
                new SnapshotCache.Auto<>(mInstallerPackages, mInstallerPackages,
                                         "Settings.mInstallerPackages");
                                         "Settings.mInstallerPackages");
        mPreferredActivities = new WatchedSparseArray<>();
        mPreferredActivitiesSnapshot = new SnapshotCache.Auto<>(mPreferredActivities,
                mPreferredActivities, "Settings.mPreferredActivities");
        mPersistentPreferredActivities = new WatchedSparseArray<>();
        mPersistentPreferredActivitiesSnapshot = new SnapshotCache.Auto<>(
                mPersistentPreferredActivities, mPersistentPreferredActivities,
                "Settings.mPersistentPreferredActivities");
        mCrossProfileIntentResolvers = new WatchedSparseArray<>();
        mCrossProfileIntentResolversSnapshot = new SnapshotCache.Auto<>(
                mCrossProfileIntentResolvers, mCrossProfileIntentResolvers,
                "Settings.mCrossProfileIntentResolvers");
        mPastSignatures = new WatchedArrayList<>();
        mPastSignaturesSnapshot = new SnapshotCache.Auto<>(mPastSignatures, mPastSignatures,
                "Settings.mPastSignatures");
        mKeySetRefs = new WatchedArrayMap<>();
        mKeySetRefsSnapshot = new SnapshotCache.Auto<>(mKeySetRefs, mKeySetRefs,
                "Settings.mKeySetRefs");
        mPendingPackages = new WatchedArrayList<>();
        mPendingPackagesSnapshot = new SnapshotCache.Auto<>(mPendingPackages, mPendingPackages,
                "Settings.mPendingPackages");
        mKeySetManagerService = new KeySetManagerService(mPackages);
        mKeySetManagerService = new KeySetManagerService(mPackages);


        // Test-only handler working on background thread.
        // Test-only handler working on background thread.
@@ -623,6 +650,26 @@ public final class Settings implements Watchable, Snappable {
        mInstallerPackagesSnapshot =
        mInstallerPackagesSnapshot =
                new SnapshotCache.Auto<>(mInstallerPackages, mInstallerPackages,
                new SnapshotCache.Auto<>(mInstallerPackages, mInstallerPackages,
                                         "Settings.mInstallerPackages");
                                         "Settings.mInstallerPackages");
        mPreferredActivities = new WatchedSparseArray<>();
        mPreferredActivitiesSnapshot = new SnapshotCache.Auto<>(mPreferredActivities,
                mPreferredActivities, "Settings.mPreferredActivities");
        mPersistentPreferredActivities = new WatchedSparseArray<>();
        mPersistentPreferredActivitiesSnapshot = new SnapshotCache.Auto<>(
                mPersistentPreferredActivities, mPersistentPreferredActivities,
                "Settings.mPersistentPreferredActivities");
        mCrossProfileIntentResolvers = new WatchedSparseArray<>();
        mCrossProfileIntentResolversSnapshot = new SnapshotCache.Auto<>(
                mCrossProfileIntentResolvers, mCrossProfileIntentResolvers,
                "Settings.mCrossProfileIntentResolvers");
        mPastSignatures = new WatchedArrayList<>();
        mPastSignaturesSnapshot = new SnapshotCache.Auto<>(mPastSignatures, mPastSignatures,
                "Settings.mPastSignatures");
        mKeySetRefs = new WatchedArrayMap<>();
        mKeySetRefsSnapshot = new SnapshotCache.Auto<>(mKeySetRefs, mKeySetRefs,
                "Settings.mKeySetRefs");
        mPendingPackages = new WatchedArrayList<>();
        mPendingPackagesSnapshot = new SnapshotCache.Auto<>(mPendingPackages, mPendingPackages,
                "Settings.mPendingPackages");
        mKeySetManagerService = new KeySetManagerService(mPackages);
        mKeySetManagerService = new KeySetManagerService(mPackages);


        mHandler = handler;
        mHandler = handler;
@@ -699,24 +746,27 @@ public final class Settings implements Watchable, Snappable {
        mBlockUninstallPackages.snapshot(r.mBlockUninstallPackages);
        mBlockUninstallPackages.snapshot(r.mBlockUninstallPackages);
        mVersion.putAll(r.mVersion);
        mVersion.putAll(r.mVersion);
        mVerifierDeviceIdentity = r.mVerifierDeviceIdentity;
        mVerifierDeviceIdentity = r.mVerifierDeviceIdentity;
        WatchedSparseArray.snapshot(
        mPreferredActivities = r.mPreferredActivitiesSnapshot.snapshot();
                mPreferredActivities, r.mPreferredActivities);
        mPreferredActivitiesSnapshot = new SnapshotCache.Sealed<>();
        WatchedSparseArray.snapshot(
        mPersistentPreferredActivities = r.mPersistentPreferredActivitiesSnapshot.snapshot();
                mPersistentPreferredActivities, r.mPersistentPreferredActivities);
        mPersistentPreferredActivitiesSnapshot = new SnapshotCache.Sealed<>();
        WatchedSparseArray.snapshot(
        mCrossProfileIntentResolvers = r.mCrossProfileIntentResolversSnapshot.snapshot();
                mCrossProfileIntentResolvers, r.mCrossProfileIntentResolvers);
        mCrossProfileIntentResolversSnapshot = new SnapshotCache.Sealed<>();

        mSharedUsers.snapshot(r.mSharedUsers);
        mSharedUsers.snapshot(r.mSharedUsers);
        mAppIds = r.mAppIds.snapshot();
        mAppIds = r.mAppIds.snapshot();
        WatchedArrayList.snapshot(

                mPastSignatures, r.mPastSignatures);
        mPastSignatures = r.mPastSignaturesSnapshot.snapshot();
        WatchedArrayMap.snapshot(
        mPastSignaturesSnapshot = new SnapshotCache.Sealed<>();
                mKeySetRefs, r.mKeySetRefs);
        mKeySetRefs = r.mKeySetRefsSnapshot.snapshot();
        mKeySetRefsSnapshot = new SnapshotCache.Sealed<>();

        mRenamedPackages.snapshot(r.mRenamedPackages);
        mRenamedPackages.snapshot(r.mRenamedPackages);
        mNextAppLinkGeneration.snapshot(r.mNextAppLinkGeneration);
        mNextAppLinkGeneration.snapshot(r.mNextAppLinkGeneration);
        mDefaultBrowserApp.snapshot(r.mDefaultBrowserApp);
        mDefaultBrowserApp.snapshot(r.mDefaultBrowserApp);
        // mReadMessages
        // mReadMessages
        WatchedArrayList.snapshot(
        mPendingPackages = r.mPendingPackagesSnapshot.snapshot();
                mPendingPackages, r.mPendingPackages);
        mPendingPackagesSnapshot = new SnapshotCache.Sealed<>();
        mSystemDir = null;
        mSystemDir = null;
        // mKeySetManagerService;
        // mKeySetManagerService;
        mPermissions = r.mPermissions;
        mPermissions = r.mPermissions;