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

Commit 43b109b5 authored by Sandro Meier's avatar Sandro Meier
Browse files

Add correct synchronization to VDMServiceTest.java

Many test cases in VirtualDeviceManagerServiceTest directly put elements
in mInputController.mInputDeviceDescriptors without acquiring the lock
of mInputController. In the context of the current test cases this is not
a problem (no parallel access occurs). However, the presubmit lint flags
this on new tests added. Therefore this commit adds synchronization to
all existing accesses.

Test: atest FrameworksServicesTests:VirtualDeviceManagerServiceTest
Bug: 244516415
Change-Id: Ib6b974e1aa672a6d7cd8152be8889a5107038a99
parent b03a7b7d
Loading
Loading
Loading
Loading
+19 −27
Original line number Diff line number Diff line
@@ -587,9 +587,9 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final int keyCode = KeyEvent.KEYCODE_A;
        final int action = VirtualKeyEvent.ACTION_UP;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 1,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */1, /* displayId= */ 1, PHYS,
                DEVICE_ID);

        mDeviceImpl.sendKeyEvent(BINDER, new VirtualKeyEvent.Builder().setKeyCode(keyCode)
                .setAction(action).build());
        verify(mNativeWrapperMock).writeKeyEvent(fd, keyCode, action);
@@ -612,9 +612,8 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final int buttonCode = VirtualMouseButtonEvent.BUTTON_BACK;
        final int action = VirtualMouseButtonEvent.ACTION_BUTTON_PRESS;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 2,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        mDeviceImpl.sendButtonEvent(BINDER, new VirtualMouseButtonEvent.Builder()
                .setButtonCode(buttonCode)
@@ -627,9 +626,8 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final int buttonCode = VirtualMouseButtonEvent.BUTTON_BACK;
        final int action = VirtualMouseButtonEvent.ACTION_BUTTON_PRESS;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 2,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        assertThrows(
                IllegalStateException.class,
                () ->
@@ -653,9 +651,8 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final float x = -0.2f;
        final float y = 0.7f;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 2,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        mDeviceImpl.sendRelativeEvent(BINDER, new VirtualMouseRelativeEvent.Builder()
                .setRelativeX(x).setRelativeY(y).build());
@@ -667,9 +664,8 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final float x = -0.2f;
        final float y = 0.7f;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 2,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        assertThrows(
                IllegalStateException.class,
                () ->
@@ -694,9 +690,8 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final float x = 0.5f;
        final float y = 1f;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 2,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        mDeviceImpl.sendScrollEvent(BINDER, new VirtualMouseScrollEvent.Builder()
                .setXAxisMovement(x)
@@ -709,9 +704,8 @@ public class VirtualDeviceManagerServiceTest {
        final int fd = 1;
        final float x = 0.5f;
        final float y = 1f;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 2,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */2, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        assertThrows(
                IllegalStateException.class,
                () ->
@@ -742,9 +736,8 @@ public class VirtualDeviceManagerServiceTest {
        final float x = 100.5f;
        final float y = 200.5f;
        final int action = VirtualTouchEvent.ACTION_UP;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 3,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */3, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        mDeviceImpl.sendTouchEvent(BINDER, new VirtualTouchEvent.Builder().setX(x)
                .setY(y).setAction(action).setPointerId(pointerId).setToolType(toolType).build());
        verify(mNativeWrapperMock).writeTouchEvent(fd, pointerId, toolType, action, x, y, Float.NaN,
@@ -761,9 +754,8 @@ public class VirtualDeviceManagerServiceTest {
        final int action = VirtualTouchEvent.ACTION_UP;
        final float pressure = 1.0f;
        final float majorAxisSize = 10.0f;
        mInputController.mInputDeviceDescriptors.put(BINDER,
                new InputController.InputDeviceDescriptor(fd, () -> {}, /* type= */ 3,
                        /* displayId= */ 1, PHYS, DEVICE_ID));
        mInputController.addDeviceForTesting(BINDER, fd, /* type= */3, /* displayId= */ 1, PHYS,
                DEVICE_ID);
        mDeviceImpl.sendTouchEvent(BINDER, new VirtualTouchEvent.Builder().setX(x)
                .setY(y).setAction(action).setPointerId(pointerId).setToolType(toolType)
                .setPressure(pressure).setMajorAxisSize(majorAxisSize).build());