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

Commit 5cfe5d02 authored by Biswarup Pal's avatar Biswarup Pal Committed by Android (Google) Code Review
Browse files

Merge "Dispatch virtual key events to default display during mirroring" into main

parents 29bd7754 2915ab4e
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -692,7 +692,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);
        }
@@ -710,7 +711,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);
@@ -776,7 +778,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);
@@ -1002,6 +1005,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) {