diff --git a/services/core/java/com/android/server/pm/AppIdSettingMap.java b/services/core/java/com/android/server/pm/AppIdSettingMap.java index b41a0b8878e0a..20c67f87d3b9b 100644 --- a/services/core/java/com/android/server/pm/AppIdSettingMap.java +++ b/services/core/java/com/android/server/pm/AppIdSettingMap.java @@ -19,6 +19,7 @@ package com.android.server.pm; import android.os.Process; import android.util.Log; +import com.android.server.utils.SnapshotCache; import com.android.server.utils.WatchedArrayList; import com.android.server.utils.WatchedSparseArray; import com.android.server.utils.Watcher; @@ -34,10 +35,28 @@ final class AppIdSettingMap { * index to the corresponding SettingBase object is (appId - FIRST_APPLICATION_ID). If an app ID * doesn't exist (i.e., app is not installed), we fill the corresponding entry with null. */ - private WatchedArrayList mNonSystemSettings = new WatchedArrayList<>(); - private WatchedSparseArray mSystemSettings = new WatchedSparseArray<>(); + private final WatchedArrayList mNonSystemSettings; + private final SnapshotCache> mNonSystemSettingsSnapshot; + private final WatchedSparseArray mSystemSettings; + private final SnapshotCache> mSystemSettingsSnapshot; private int mFirstAvailableAppId = Process.FIRST_APPLICATION_UID; + AppIdSettingMap() { + mNonSystemSettings = new WatchedArrayList<>(); + mNonSystemSettingsSnapshot = new SnapshotCache.Auto<>( + mNonSystemSettings, mNonSystemSettings, "AppIdSettingMap.mNonSystemSettings"); + mSystemSettings = new WatchedSparseArray<>(); + mSystemSettingsSnapshot = new SnapshotCache.Auto<>( + mSystemSettings, mSystemSettings, "AppIdSettingMap.mSystemSettings"); + } + + AppIdSettingMap(AppIdSettingMap orig) { + mNonSystemSettings = orig.mNonSystemSettingsSnapshot.snapshot(); + mNonSystemSettingsSnapshot = new SnapshotCache.Sealed<>(); + mSystemSettings = orig.mSystemSettingsSnapshot.snapshot(); + mSystemSettingsSnapshot = new SnapshotCache.Sealed<>(); + } + /** Returns true if the requested AppID was valid and not already registered. */ public boolean registerExistingAppId(int appId, SettingBase setting, Object name) { if (appId >= Process.FIRST_APPLICATION_UID) { @@ -134,10 +153,7 @@ final class AppIdSettingMap { } public AppIdSettingMap snapshot() { - AppIdSettingMap l = new AppIdSettingMap(); - mNonSystemSettings.snapshot(l.mNonSystemSettings, mNonSystemSettings); - mSystemSettings.snapshot(l.mSystemSettings, mSystemSettings); - return l; + return new AppIdSettingMap(this); } public void registerObserver(Watcher observer) {