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

Commit 3e714fc8 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Android (Google) Code Review
Browse files

Merge "Add VDMInternal API getAllPersistentDeviceIds" into main

parents 8ca8f2b0 3bda19e5
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -863,6 +863,23 @@ public class VirtualDeviceManagerService extends SystemService {
            return virtualDevice == null ? null : virtualDevice.getPersistentDeviceId();
        }

        @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);
                    if (VIRTUAL_DEVICE_COMPANION_DEVICE_PROFILES.contains(
                            associationInfo.getDeviceProfile())) {
                        persistentIds.add(
                                VirtualDeviceImpl.createPersistentDeviceId(
                                        associationInfo.getId()));
                    }
                }
            }
            return persistentIds;
        }

        @Override
        public void registerAppsOnVirtualDeviceListener(
                @NonNull AppsOnVirtualDeviceListener listener) {
+6 −0
Original line number Diff line number Diff line
@@ -157,4 +157,10 @@ public abstract class VirtualDeviceManagerInternal {
     * @see VirtualDevice#getPersistentDeviceId()
     */
    public abstract @Nullable String getPersistentIdForDevice(int deviceId);

    /**
     * Returns all current persistent device IDs, including the ones for which no virtual device
     * exists, as long as one may have existed or can be created.
     */
    public abstract @NonNull Set<String> getAllPersistentDeviceIds();
}
+24 −0
Original line number Diff line number Diff line
@@ -772,6 +772,30 @@ public class VirtualDeviceManagerServiceTest {
        verifyNoMoreInteractions(mPersistentDeviceIdRemovedListener);
    }

    @Test
    public void getAllPersistentDeviceIds_respectsCurrentAssociations() {
        mVdms.onCdmAssociationsChanged(List.of(mAssociationInfo));
        TestableLooper.get(this).processAllMessages();

        assertThat(mLocalService.getAllPersistentDeviceIds())
                .containsExactly(mDeviceImpl.getPersistentDeviceId());

        mVdms.onCdmAssociationsChanged(List.of(
                createAssociationInfo(2, AssociationRequest.DEVICE_PROFILE_APP_STREAMING),
                createAssociationInfo(3, AssociationRequest.DEVICE_PROFILE_AUTOMOTIVE_PROJECTION),
                createAssociationInfo(4, AssociationRequest.DEVICE_PROFILE_WATCH)));
        TestableLooper.get(this).processAllMessages();

        assertThat(mLocalService.getAllPersistentDeviceIds()).containsExactly(
                VirtualDeviceImpl.createPersistentDeviceId(2),
                VirtualDeviceImpl.createPersistentDeviceId(3));

        mVdms.onCdmAssociationsChanged(Collections.emptyList());
        TestableLooper.get(this).processAllMessages();

        assertThat(mLocalService.getAllPersistentDeviceIds()).isEmpty();
    }

    @Test
    public void onAppsOnVirtualDeviceChanged_singleVirtualDevice_listenersNotified() {
        ArraySet<Integer> uids = new ArraySet<>(Arrays.asList(UID_1, UID_2));