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

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

Merge "Add VDM internal API getDeviceIdForDisplayId" into main

parents 0e27a4cf e8c71644
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -460,11 +460,11 @@ public class VirtualDeviceManagerService extends SystemService {

            synchronized (mVirtualDeviceManagerLock) {
                if (!Flags.persistentDeviceIdApi() && mVirtualDevices.size() == 0) {
                    final long callindId = Binder.clearCallingIdentity();
                    final long callingId = Binder.clearCallingIdentity();
                    try {
                        registerCdmAssociationListener();
                    } finally {
                        Binder.restoreCallingIdentity(callindId);
                        Binder.restoreCallingIdentity(callingId);
                    }
                }
                mVirtualDevices.put(deviceId, virtualDevice);
@@ -850,6 +850,11 @@ public class VirtualDeviceManagerService extends SystemService {
                            .collect(Collectors.toCollection(ArraySet::new));
        }

        @Override
        public int getDeviceIdForDisplayId(int displayId) {
            return mImpl.getDeviceIdForDisplayId(displayId);
        }

        @Override
        public @Nullable String getPersistentIdForDevice(int deviceId) {
            if (deviceId == Context.DEVICE_ID_DEFAULT) {
+8 −0
Original line number Diff line number Diff line
@@ -148,6 +148,14 @@ public abstract class VirtualDeviceManagerInternal {
     */
    public abstract @NonNull ArraySet<Integer> getDisplayIdsForDevice(int deviceId);

    /**
     * Returns the ID of the device which owns the display with the given ID.
     *
     * <p>In case the virtual display ID is invalid or doesn't belong to a virtual device, then
     * {@link android.content.Context#DEVICE_ID_DEFAULT} is returned.</p>
     */
    public abstract int getDeviceIdForDisplayId(int displayId);

    /**
     * Gets the persistent ID for the VirtualDevice with the given device ID.
     *
+8 −0
Original line number Diff line number Diff line
@@ -413,18 +413,24 @@ public class VirtualDeviceManagerServiceTest {
    public void getDeviceIdForDisplayId_invalidDisplayId_returnsDefault() {
        assertThat(mVdm.getDeviceIdForDisplayId(Display.INVALID_DISPLAY))
                .isEqualTo(DEVICE_ID_DEFAULT);
        assertThat(mLocalService.getDeviceIdForDisplayId(Display.INVALID_DISPLAY))
                .isEqualTo(DEVICE_ID_DEFAULT);
    }

    @Test
    public void getDeviceIdForDisplayId_defaultDisplayId_returnsDefault() {
        assertThat(mVdm.getDeviceIdForDisplayId(Display.DEFAULT_DISPLAY))
                .isEqualTo(DEVICE_ID_DEFAULT);
        assertThat(mLocalService.getDeviceIdForDisplayId(Display.DEFAULT_DISPLAY))
                .isEqualTo(DEVICE_ID_DEFAULT);
    }

    @Test
    public void getDeviceIdForDisplayId_nonExistentDisplayId_returnsDefault() {
        assertThat(mVdm.getDeviceIdForDisplayId(NON_EXISTENT_DISPLAY_ID))
                .isEqualTo(DEVICE_ID_DEFAULT);
        assertThat(mLocalService.getDeviceIdForDisplayId(NON_EXISTENT_DISPLAY_ID))
                .isEqualTo(DEVICE_ID_DEFAULT);
    }

    @Test
@@ -433,6 +439,8 @@ public class VirtualDeviceManagerServiceTest {

        assertThat(mVdm.getDeviceIdForDisplayId(DISPLAY_ID_1))
                .isEqualTo(mDeviceImpl.getDeviceId());
        assertThat(mLocalService.getDeviceIdForDisplayId(DISPLAY_ID_1))
                .isEqualTo(mDeviceImpl.getDeviceId());
    }

    @Test