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

Commit 2915ab4e authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Dispatch virtual key events to default display during mirroring

Test: manual
Bug: 292212199
Change-Id: I5f8c71660d4c979af468a7ee4bfd72da1d74aeb6
parent d7ab513e
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -688,7 +688,8 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        final long ident = Binder.clearCallingIdentity();
        try {
            mInputController.createDpad(config.getInputDeviceName(), config.getVendorId(),
                    config.getProductId(), deviceToken, config.getAssociatedDisplayId());
                    config.getProductId(), deviceToken,
                    getTargetDisplayIdForInput(config.getAssociatedDisplayId()));
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
@@ -706,7 +707,8 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        final long ident = Binder.clearCallingIdentity();
        try {
            mInputController.createKeyboard(config.getInputDeviceName(), config.getVendorId(),
                    config.getProductId(), deviceToken, config.getAssociatedDisplayId(),
                    config.getProductId(), deviceToken,
                    getTargetDisplayIdForInput(config.getAssociatedDisplayId()),
                    config.getLanguageTag(), config.getLayoutType());
        } finally {
            Binder.restoreCallingIdentity(ident);
@@ -772,7 +774,8 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        try {
            mInputController.createNavigationTouchpad(
                    config.getInputDeviceName(), config.getVendorId(),
                    config.getProductId(), deviceToken, config.getAssociatedDisplayId(),
                    config.getProductId(), deviceToken,
                    getTargetDisplayIdForInput(config.getAssociatedDisplayId()),
                    touchpadHeight, touchpadWidth);
        } finally {
            Binder.restoreCallingIdentity(ident);
@@ -983,6 +986,20 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        }
    }

    // For display mirroring, we want to dispatch all key events to the source (default) display,
    // as the virtual display doesn't have any focused windows. Hence, call this for
    // associating any input device to the source display if the input device emits any key events.
    private int getTargetDisplayIdForInput(int displayId) {
        if (!Flags.interactiveScreenMirror()) {
            return displayId;
        }

        DisplayManagerInternal displayManager = LocalServices.getService(
                DisplayManagerInternal.class);
        int mirroredDisplayId = displayManager.getDisplayIdToMirror(displayId);
        return mirroredDisplayId == Display.INVALID_DISPLAY ? displayId : mirroredDisplayId;
    }

    @GuardedBy("mVirtualDeviceLock")
    private GenericWindowPolicyController createWindowPolicyControllerLocked(
            @NonNull Set<String> displayCategories) {