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

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

Merge "Fix crash for multiple virtual mice associated to multiple displays" into main

parents c835de53 45f79bc6
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -342,8 +342,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());
@@ -373,8 +373,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());
@@ -390,8 +390,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());
@@ -408,8 +408,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
@@ -1254,22 +1254,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() {
        assertThat(mDeviceImpl.sendRelativeEvent(BINDER,
@@ -1301,22 +1285,6 @@ public class VirtualDeviceManagerServiceTest {
    }


    @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() {
        assertThat(mDeviceImpl.sendScrollEvent(BINDER,
@@ -1348,22 +1316,6 @@ public class VirtualDeviceManagerServiceTest {
    }


    @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() {
        assertThat(mDeviceImpl.sendTouchEvent(BINDER,