Loading services/companion/java/com/android/server/companion/BackupRestoreProcessor.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading services/companion/java/com/android/server/companion/association/AssociationRequestsProcessor.java +1 −1 Original line number Diff line number Diff line Loading @@ -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, Loading services/companion/java/com/android/server/companion/association/AssociationStore.java +9 −9 Original line number Diff line number Diff line Loading @@ -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<>(); Loading Loading @@ -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). Loading @@ -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; Loading @@ -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; } } Loading @@ -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); Loading Loading @@ -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)); Loading Loading
services/companion/java/com/android/server/companion/BackupRestoreProcessor.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading
services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading
services/companion/java/com/android/server/companion/association/AssociationRequestsProcessor.java +1 −1 Original line number Diff line number Diff line Loading @@ -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, Loading
services/companion/java/com/android/server/companion/association/AssociationStore.java +9 −9 Original line number Diff line number Diff line Loading @@ -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<>(); Loading Loading @@ -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). Loading @@ -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; Loading @@ -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; } } Loading @@ -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); Loading Loading @@ -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)); Loading