Loading core/api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -3201,6 +3201,7 @@ package android.companion.virtual { public final class VirtualDeviceManager { method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.companion.virtual.VirtualDeviceManager.VirtualDevice createVirtualDevice(int, @NonNull android.companion.virtual.VirtualDeviceParams); method @FlaggedApi("android.companion.virtual.flags.persistent_device_id_api") @Nullable public CharSequence getDisplayNameForPersistentDeviceId(@NonNull String); field public static final int LAUNCH_FAILURE_NO_ACTIVITY = 2; // 0x2 field public static final int LAUNCH_FAILURE_PENDING_INTENT_CANCELED = 1; // 0x1 field public static final int LAUNCH_SUCCESS = 0; // 0x0 core/java/android/companion/virtual/IVirtualDeviceManager.aidl +5 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,11 @@ interface IVirtualDeviceManager { */ int getDeviceIdForDisplayId(int displayId); /** * Returns the display name corresponding to the given persistent device ID, if any. */ CharSequence getDisplayNameForPersistentDeviceId(in String persistentDeviceId); /** * Checks whether the passed {@code deviceId} is a valid virtual device ID or not. * {@link VirtualDeviceManager#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default Loading core/java/android/companion/virtual/VirtualDeviceManager.java +28 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,34 @@ public final class VirtualDeviceManager { } } /** * Get the display name for a given persistent device ID. * * <p>This will work even if currently there is no valid virtual device with the given * persistent ID, as long as such a device has been created or can be created.</p> * * @return the display name associated with the given persistent device ID, or {@code null} if * the persistent ID is invalid or does not correspond to a virtual device. * * @hide */ // TODO(b/315481938): Link @see VirtualDevice#getPersistentDeviceId() @FlaggedApi(Flags.FLAG_PERSISTENT_DEVICE_ID_API) @SystemApi @Nullable public CharSequence getDisplayNameForPersistentDeviceId(@NonNull String persistentDeviceId) { if (mService == null) { Log.w(TAG, "Failed to retrieve virtual devices; no virtual device manager service."); return null; } try { return mService.getDisplayNameForPersistentDeviceId( Objects.requireNonNull(persistentDeviceId)); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Checks whether the passed {@code deviceId} is a valid virtual device ID or not. * {@link Context#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default Loading services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ class CompanionDeviceShellCommand extends ShellCommand { String deviceProfile = getNextArg(); final MacAddress macAddress = MacAddress.fromString(address); mService.createNewAssociation(userId, packageName, macAddress, null, deviceProfile, false); /* displayName= */ deviceProfile, deviceProfile, false); } break; Loading services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java +24 −24 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.Process; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.os.UserHandle; import android.util.ArrayMap; import android.util.ArraySet; import android.util.ExceptionUtils; import android.util.Slog; Loading Loading @@ -112,7 +113,7 @@ public class VirtualDeviceManagerService extends SystemService { Context.DEVICE_ID_DEFAULT + 1); @GuardedBy("mVirtualDeviceManagerLock") private List<AssociationInfo> mActiveAssociations = new ArrayList<>(); private ArrayMap<String, AssociationInfo> mActiveAssociations = new ArrayMap<>(); private final CompanionDeviceManager.OnAssociationsChangedListener mCdmAssociationListener = new CompanionDeviceManager.OnAssociationsChangedListener() { Loading Loading @@ -343,34 +344,29 @@ public class VirtualDeviceManagerService extends SystemService { @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) void onCdmAssociationsChanged(List<AssociationInfo> associations) { List<AssociationInfo> vdmAssociations = new ArrayList<>(); Set<Integer> activeAssociationIds = new HashSet<>(); ArrayMap<String, AssociationInfo> vdmAssociations = new ArrayMap<>(); for (int i = 0; i < associations.size(); ++i) { AssociationInfo association = associations.get(i); if (VIRTUAL_DEVICE_COMPANION_DEVICE_PROFILES.contains(association.getDeviceProfile())) { vdmAssociations.add(association); activeAssociationIds.add(association.getId()); if (VIRTUAL_DEVICE_COMPANION_DEVICE_PROFILES.contains(association.getDeviceProfile()) && !association.isRevoked()) { String persistentId = VirtualDeviceImpl.createPersistentDeviceId(association.getId()); vdmAssociations.put(persistentId, association); } } Set<VirtualDeviceImpl> virtualDevicesToRemove = new HashSet<>(); Set<String> removedPersistentDeviceIds = new HashSet<>(); Set<String> removedPersistentDeviceIds; synchronized (mVirtualDeviceManagerLock) { for (int i = 0; i < mActiveAssociations.size(); ++i) { AssociationInfo associationInfo = mActiveAssociations.get(i); if (!activeAssociationIds.contains(associationInfo.getId())) { removedPersistentDeviceIds.add( VirtualDeviceImpl.createPersistentDeviceId(associationInfo.getId())); } } removedPersistentDeviceIds = mActiveAssociations.keySet(); removedPersistentDeviceIds.removeAll(vdmAssociations.keySet()); mActiveAssociations = vdmAssociations; for (int i = 0; i < mVirtualDevices.size(); i++) { VirtualDeviceImpl virtualDevice = mVirtualDevices.valueAt(i); if (!activeAssociationIds.contains(virtualDevice.getAssociationId())) { if (removedPersistentDeviceIds.contains(virtualDevice.getPersistentDeviceId())) { virtualDevicesToRemove.add(virtualDevice); } } mActiveAssociations = vdmAssociations; } for (VirtualDeviceImpl virtualDevice : virtualDevicesToRemove) { Loading Loading @@ -577,6 +573,16 @@ public class VirtualDeviceManagerService extends SystemService { return Context.DEVICE_ID_DEFAULT; } @Override // Binder call public @Nullable CharSequence getDisplayNameForPersistentDeviceId( @NonNull String persistentDeviceId) { final AssociationInfo associationInfo; synchronized (mVirtualDeviceManagerLock) { associationInfo = mActiveAssociations.get(persistentDeviceId); } return associationInfo == null ? null : associationInfo.getDisplayName(); } // Binder call @Override public boolean isValidVirtualDeviceId(int deviceId) { Loading Loading @@ -885,15 +891,9 @@ public class VirtualDeviceManagerService extends SystemService { @Override public @NonNull Set<String> getAllPersistentDeviceIds() { Set<String> persistentIds = new ArraySet<>(); synchronized (mVirtualDeviceManagerLock) { for (int i = 0; i < mActiveAssociations.size(); ++i) { AssociationInfo associationInfo = mActiveAssociations.get(i); persistentIds.add( VirtualDeviceImpl.createPersistentDeviceId(associationInfo.getId())); } return Set.copyOf(mActiveAssociations.keySet()); } return persistentIds; } @Override Loading Loading
core/api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -3201,6 +3201,7 @@ package android.companion.virtual { public final class VirtualDeviceManager { method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.companion.virtual.VirtualDeviceManager.VirtualDevice createVirtualDevice(int, @NonNull android.companion.virtual.VirtualDeviceParams); method @FlaggedApi("android.companion.virtual.flags.persistent_device_id_api") @Nullable public CharSequence getDisplayNameForPersistentDeviceId(@NonNull String); field public static final int LAUNCH_FAILURE_NO_ACTIVITY = 2; // 0x2 field public static final int LAUNCH_FAILURE_PENDING_INTENT_CANCELED = 1; // 0x1 field public static final int LAUNCH_SUCCESS = 0; // 0x0
core/java/android/companion/virtual/IVirtualDeviceManager.aidl +5 −0 Original line number Diff line number Diff line Loading @@ -77,6 +77,11 @@ interface IVirtualDeviceManager { */ int getDeviceIdForDisplayId(int displayId); /** * Returns the display name corresponding to the given persistent device ID, if any. */ CharSequence getDisplayNameForPersistentDeviceId(in String persistentDeviceId); /** * Checks whether the passed {@code deviceId} is a valid virtual device ID or not. * {@link VirtualDeviceManager#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default Loading
core/java/android/companion/virtual/VirtualDeviceManager.java +28 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,34 @@ public final class VirtualDeviceManager { } } /** * Get the display name for a given persistent device ID. * * <p>This will work even if currently there is no valid virtual device with the given * persistent ID, as long as such a device has been created or can be created.</p> * * @return the display name associated with the given persistent device ID, or {@code null} if * the persistent ID is invalid or does not correspond to a virtual device. * * @hide */ // TODO(b/315481938): Link @see VirtualDevice#getPersistentDeviceId() @FlaggedApi(Flags.FLAG_PERSISTENT_DEVICE_ID_API) @SystemApi @Nullable public CharSequence getDisplayNameForPersistentDeviceId(@NonNull String persistentDeviceId) { if (mService == null) { Log.w(TAG, "Failed to retrieve virtual devices; no virtual device manager service."); return null; } try { return mService.getDisplayNameForPersistentDeviceId( Objects.requireNonNull(persistentDeviceId)); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Checks whether the passed {@code deviceId} is a valid virtual device ID or not. * {@link Context#DEVICE_ID_DEFAULT} is not valid as it is the ID of the default Loading
services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ class CompanionDeviceShellCommand extends ShellCommand { String deviceProfile = getNextArg(); final MacAddress macAddress = MacAddress.fromString(address); mService.createNewAssociation(userId, packageName, macAddress, null, deviceProfile, false); /* displayName= */ deviceProfile, deviceProfile, false); } break; Loading
services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java +24 −24 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.Process; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.os.UserHandle; import android.util.ArrayMap; import android.util.ArraySet; import android.util.ExceptionUtils; import android.util.Slog; Loading Loading @@ -112,7 +113,7 @@ public class VirtualDeviceManagerService extends SystemService { Context.DEVICE_ID_DEFAULT + 1); @GuardedBy("mVirtualDeviceManagerLock") private List<AssociationInfo> mActiveAssociations = new ArrayList<>(); private ArrayMap<String, AssociationInfo> mActiveAssociations = new ArrayMap<>(); private final CompanionDeviceManager.OnAssociationsChangedListener mCdmAssociationListener = new CompanionDeviceManager.OnAssociationsChangedListener() { Loading Loading @@ -343,34 +344,29 @@ public class VirtualDeviceManagerService extends SystemService { @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) void onCdmAssociationsChanged(List<AssociationInfo> associations) { List<AssociationInfo> vdmAssociations = new ArrayList<>(); Set<Integer> activeAssociationIds = new HashSet<>(); ArrayMap<String, AssociationInfo> vdmAssociations = new ArrayMap<>(); for (int i = 0; i < associations.size(); ++i) { AssociationInfo association = associations.get(i); if (VIRTUAL_DEVICE_COMPANION_DEVICE_PROFILES.contains(association.getDeviceProfile())) { vdmAssociations.add(association); activeAssociationIds.add(association.getId()); if (VIRTUAL_DEVICE_COMPANION_DEVICE_PROFILES.contains(association.getDeviceProfile()) && !association.isRevoked()) { String persistentId = VirtualDeviceImpl.createPersistentDeviceId(association.getId()); vdmAssociations.put(persistentId, association); } } Set<VirtualDeviceImpl> virtualDevicesToRemove = new HashSet<>(); Set<String> removedPersistentDeviceIds = new HashSet<>(); Set<String> removedPersistentDeviceIds; synchronized (mVirtualDeviceManagerLock) { for (int i = 0; i < mActiveAssociations.size(); ++i) { AssociationInfo associationInfo = mActiveAssociations.get(i); if (!activeAssociationIds.contains(associationInfo.getId())) { removedPersistentDeviceIds.add( VirtualDeviceImpl.createPersistentDeviceId(associationInfo.getId())); } } removedPersistentDeviceIds = mActiveAssociations.keySet(); removedPersistentDeviceIds.removeAll(vdmAssociations.keySet()); mActiveAssociations = vdmAssociations; for (int i = 0; i < mVirtualDevices.size(); i++) { VirtualDeviceImpl virtualDevice = mVirtualDevices.valueAt(i); if (!activeAssociationIds.contains(virtualDevice.getAssociationId())) { if (removedPersistentDeviceIds.contains(virtualDevice.getPersistentDeviceId())) { virtualDevicesToRemove.add(virtualDevice); } } mActiveAssociations = vdmAssociations; } for (VirtualDeviceImpl virtualDevice : virtualDevicesToRemove) { Loading Loading @@ -577,6 +573,16 @@ public class VirtualDeviceManagerService extends SystemService { return Context.DEVICE_ID_DEFAULT; } @Override // Binder call public @Nullable CharSequence getDisplayNameForPersistentDeviceId( @NonNull String persistentDeviceId) { final AssociationInfo associationInfo; synchronized (mVirtualDeviceManagerLock) { associationInfo = mActiveAssociations.get(persistentDeviceId); } return associationInfo == null ? null : associationInfo.getDisplayName(); } // Binder call @Override public boolean isValidVirtualDeviceId(int deviceId) { Loading Loading @@ -885,15 +891,9 @@ public class VirtualDeviceManagerService extends SystemService { @Override public @NonNull Set<String> getAllPersistentDeviceIds() { Set<String> persistentIds = new ArraySet<>(); synchronized (mVirtualDeviceManagerLock) { for (int i = 0; i < mActiveAssociations.size(); ++i) { AssociationInfo associationInfo = mActiveAssociations.get(i); persistentIds.add( VirtualDeviceImpl.createPersistentDeviceId(associationInfo.getId())); } return Set.copyOf(mActiveAssociations.keySet()); } return persistentIds; } @Override Loading