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

Commit e8c71644 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Add VDM internal API getDeviceIdForDisplayId

Useful for other system services that already use
VDMInternal so they won't have to create a VDM instance.

Bug: 287269288
Test: presubmit
Change-Id: I5f430834b48635613071cc78cda8bf3e30496b7c
parent 3b565b4e
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