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

Commit 45f79bc6 authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Fix crash for multiple virtual mice associated to multiple displays

Currently, we seem to update the virtual mouse pointer display id in
InputManager only during mouse creation/destruction. This doesn't work
if we have multiple mice, each associated with a different display.
Hence, we update the virtual mouse pointer display id in InputManager
based on which virtual mouse is currently being used.

Test: atest VirtualMouseTest
Bug: 302121028
Change-Id: I36dbb7b0eacfbef1a30ef7e088f28e4e3e1cdaa1
parent 705e7fa0
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -396,8 +396,8 @@ class InputController {
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                throw new IllegalStateException(
                        "Display id associated with this mouse is not currently targetable");
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeButtonEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getButtonCode(), event.getAction(), event.getEventTimeNanos());
@@ -429,8 +429,8 @@ class InputController {
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                throw new IllegalStateException(
                        "Display id associated with this mouse is not currently targetable");
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeRelativeEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getRelativeX(), event.getRelativeY(), event.getEventTimeNanos());
@@ -447,8 +447,8 @@ class InputController {
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                throw new IllegalStateException(
                        "Display id associated with this mouse is not currently targetable");
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeScrollEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getXAxisMovement(), event.getYAxisMovement(), event.getEventTimeNanos());
@@ -465,8 +465,8 @@ class InputController {
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                throw new IllegalStateException(
                        "Display id associated with this mouse is not currently targetable");
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            }
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition();
        }
+0 −48
Original line number Diff line number Diff line
@@ -1230,22 +1230,6 @@ public class VirtualDeviceManagerServiceTest {
        verify(mNativeWrapperMock).writeButtonEvent(fd, buttonCode, action, eventTimeNanos);
    }

    @Test
    public void sendButtonEvent_hasFd_wrongDisplay_throwsIllegalStateException() {
        final int fd = 1;
        final int buttonCode = VirtualMouseButtonEvent.BUTTON_BACK;
        final int action = VirtualMouseButtonEvent.ACTION_BUTTON_PRESS;
        mInputController.addDeviceForTesting(BINDER, fd,
                InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1,
                INPUT_DEVICE_ID);
        assertThrows(
                IllegalStateException.class,
                () ->
                        mDeviceImpl.sendButtonEvent(BINDER, new VirtualMouseButtonEvent.Builder()
                                .setButtonCode(buttonCode)
                                .setAction(action).build()));
    }

    @Test
    public void sendRelativeEvent_noFd() {
        assertThrows(
@@ -1274,22 +1258,6 @@ public class VirtualDeviceManagerServiceTest {
        verify(mNativeWrapperMock).writeRelativeEvent(fd, x, y, eventTimeNanos);
    }

    @Test
    public void sendRelativeEvent_hasFd_wrongDisplay_throwsIllegalStateException() {
        final int fd = 1;
        final float x = -0.2f;
        final float y = 0.7f;
        mInputController.addDeviceForTesting(BINDER, fd,
                InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1,
                INPUT_DEVICE_ID);
        assertThrows(
                IllegalStateException.class,
                () ->
                        mDeviceImpl.sendRelativeEvent(BINDER,
                                new VirtualMouseRelativeEvent.Builder()
                                        .setRelativeX(x).setRelativeY(y).build()));
    }

    @Test
    public void sendScrollEvent_noFd() {
        assertThrows(
@@ -1319,22 +1287,6 @@ public class VirtualDeviceManagerServiceTest {
        verify(mNativeWrapperMock).writeScrollEvent(fd, x, y, eventTimeNanos);
    }

    @Test
    public void sendScrollEvent_hasFd_wrongDisplay_throwsIllegalStateException() {
        final int fd = 1;
        final float x = 0.5f;
        final float y = 1f;
        mInputController.addDeviceForTesting(BINDER, fd,
                InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1,
                INPUT_DEVICE_ID);
        assertThrows(
                IllegalStateException.class,
                () ->
                        mDeviceImpl.sendScrollEvent(BINDER, new VirtualMouseScrollEvent.Builder()
                                .setXAxisMovement(x)
                                .setYAxisMovement(y).build()));
    }

    @Test
    public void sendTouchEvent_noFd() {
        assertThrows(