diff options
| author | 2024-04-17 20:44:49 +0000 | |
|---|---|---|
| committer | 2024-04-17 20:44:49 +0000 | |
| commit | 59a4848bd488a1e10429e8793ccd9b83b77d9838 (patch) | |
| tree | 9da19e2c9f675b0b3e7c4ac157320bb2232fc7e6 | |
| parent | e25101a2a23af1a2a3cc536fe40b7994ff970007 (diff) | |
| parent | 6324c31b798ee951410f47aeb43f5a2f54d86363 (diff) | |
Merge "[CDM][Refactoring 8/N] Make maxId global" into main
4 files changed, 12 insertions, 12 deletions
diff --git a/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java b/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java index 82e9a26310e8..7a2106bb7753 100644 --- a/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java +++ b/services/companion/java/com/android/server/companion/BackupRestoreProcessor.java @@ -175,7 +175,7 @@ class BackupRestoreProcessor { // Create a new association reassigned to this user and a valid association ID final String packageName = restored.getPackageName(); - final int newId = mAssociationStore.getNextId(userId); + final int newId = mAssociationStore.getNextId(); AssociationInfo newAssociation = new AssociationInfo.Builder(newId, userId, packageName, restored).build(); diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java b/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java index 9cfb5351f6cf..c892b84ab4d5 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java @@ -85,7 +85,7 @@ class CompanionDeviceShellCommand extends ShellCommand { final int userId = getNextIntArgRequired(); final List<AssociationInfo> associationsForUser = mAssociationStore.getActiveAssociationsByUser(userId); - final int maxId = mAssociationStore.getMaxId(userId); + final int maxId = mAssociationStore.getMaxId(); out.println("Max ID: " + maxId); out.println("Association ID | Package Name | Mac Address"); for (AssociationInfo association : associationsForUser) { diff --git a/services/companion/java/com/android/server/companion/association/AssociationRequestsProcessor.java b/services/companion/java/com/android/server/companion/association/AssociationRequestsProcessor.java index a18776e67200..1f09d4da6260 100644 --- a/services/companion/java/com/android/server/companion/association/AssociationRequestsProcessor.java +++ b/services/companion/java/com/android/server/companion/association/AssociationRequestsProcessor.java @@ -284,7 +284,7 @@ public class AssociationRequestsProcessor { @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice, boolean selfManaged, @Nullable IAssociationRequestCallback callback, @Nullable ResultReceiver resultReceiver) { - final int id = mAssociationStore.getNextId(userId); + final int id = mAssociationStore.getNextId(); final long timestamp = System.currentTimeMillis(); final AssociationInfo association = new AssociationInfo(id, userId, packageName, diff --git a/services/companion/java/com/android/server/companion/association/AssociationStore.java b/services/companion/java/com/android/server/companion/association/AssociationStore.java index ae2b70852a35..29e8095f8680 100644 --- a/services/companion/java/com/android/server/companion/association/AssociationStore.java +++ b/services/companion/java/com/android/server/companion/association/AssociationStore.java @@ -132,7 +132,7 @@ public class AssociationStore { @GuardedBy("mLock") private final Map<Integer, AssociationInfo> mIdToAssociationMap = new HashMap<>(); @GuardedBy("mLock") - private final Map<Integer, Integer> mUserToMaxId = new HashMap<>(); + private int mMaxId = 0; @GuardedBy("mLocalListeners") private final Set<OnChangeListener> mLocalListeners = new LinkedHashSet<>(); @@ -162,7 +162,7 @@ public class AssociationStore { mPersisted = false; mIdToAssociationMap.clear(); - mUserToMaxId.clear(); + mMaxId = 0; // The data is stored in DE directories, so we can read the data for all users now // (which would not be possible if the data was stored to CE directories). @@ -172,7 +172,7 @@ public class AssociationStore { for (AssociationInfo association : entry.getValue().getAssociations()) { mIdToAssociationMap.put(association.getId(), association); } - mUserToMaxId.put(entry.getKey(), entry.getValue().getMaxId()); + mMaxId = Math.max(mMaxId, entry.getValue().getMaxId()); } mPersisted = true; @@ -183,18 +183,18 @@ public class AssociationStore { /** * Get the current max association id. */ - public int getMaxId(int userId) { + public int getMaxId() { synchronized (mLock) { - return mUserToMaxId.getOrDefault(userId, 0); + return mMaxId; } } /** * Get the next available association id. */ - public int getNextId(int userId) { + public int getNextId() { synchronized (mLock) { - return getMaxId(userId) + 1; + return getMaxId() + 1; } } @@ -214,7 +214,7 @@ public class AssociationStore { } mIdToAssociationMap.put(id, association); - mUserToMaxId.put(userId, Math.max(mUserToMaxId.getOrDefault(userId, 0), id)); + mMaxId = Math.max(mMaxId, id); writeCacheToDisk(userId); @@ -305,7 +305,7 @@ public class AssociationStore { mExecutor.execute(() -> { Associations associations = new Associations(); synchronized (mLock) { - associations.setMaxId(mUserToMaxId.getOrDefault(userId, 0)); + associations.setMaxId(mMaxId); associations.setAssociations( CollectionUtils.filter(mIdToAssociationMap.values().stream().toList(), a -> a.getUserId() == userId)); |