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

Commit f17c30cc authored by Wenyu Zhang's avatar Wenyu Zhang
Browse files

autoclick: Remove stylus which is always available in tablet

This fixes the issue that the click type panel is still shown even with
the mouse disconnected.

Change-Id: Id5b1007f626835a6c4ab9b7a79d24242740504c3
Bug: b/422538372
Test: AutoclickControllerTest
Flag: com.android.server.accessibility.enable_autoclick_indicator
parent 1149807e
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -280,9 +280,7 @@ public class AutoclickController extends BaseEventStreamTransformation implement
                            continue;
                        }
                        if (device.supportsSource(InputDevice.SOURCE_MOUSE)
                                || device.supportsSource(InputDevice.SOURCE_TOUCHPAD)
                                || device.supportsSource(InputDevice.SOURCE_STYLUS)
                                || device.supportsSource(InputDevice.SOURCE_BLUETOOTH_STYLUS)) {
                                || device.supportsSource(InputDevice.SOURCE_TOUCHPAD)) {
                            mIsPointingDeviceConnected = true;
                            break;
                        }
+52 −0
Original line number Diff line number Diff line
@@ -1660,6 +1660,58 @@ public class AutoclickControllerTest {
        verify(mockTypePanel, Mockito.never()).show();
    }

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void onInputDeviceChanged_touchpad_hidesAndShowsTypePanel() {
        // Setup: one touchpad connected initially.
        mController.mInputManagerWrapper = mMockInputManagerWrapper;
        when(mMockInputManagerWrapper.getInputDeviceIds()).thenReturn(new int[]{1});
        AutoclickController.InputDeviceWrapper mockTouchpad =
                mock(AutoclickController.InputDeviceWrapper.class);
        when(mockTouchpad.supportsSource(InputDevice.SOURCE_TOUCHPAD)).thenReturn(true);
        when(mockTouchpad.isEnabled()).thenReturn(true);
        when(mockTouchpad.isVirtual()).thenReturn(false);
        when(mMockInputManagerWrapper.getInputDevice(1)).thenReturn(mockTouchpad);

        // Initialize controller and panels.
        injectFakeMouseActionHoverMoveEvent();

        // Capture the listener.
        ArgumentCaptor<InputManager.InputDeviceListener> listenerCaptor =
                ArgumentCaptor.forClass(InputManager.InputDeviceListener.class);
        verify(mMockInputManagerWrapper)
                .registerInputDeviceListener(listenerCaptor.capture(), any());
        InputManager.InputDeviceListener listener = listenerCaptor.getValue();

        // Manually trigger once to establish initial connected state.
        listener.onInputDeviceChanged(1);
        mTestableLooper.processAllMessages();

        // Mock panels to verify interactions.
        AutoclickTypePanel mockTypePanel = mock(AutoclickTypePanel.class);
        AutoclickScrollPanel mockScrollPanel = mock(AutoclickScrollPanel.class);
        mController.mAutoclickTypePanel = mockTypePanel;
        mController.mAutoclickScrollPanel = mockScrollPanel;

        // Action: disconnect touchpad.
        when(mMockInputManagerWrapper.getInputDeviceIds()).thenReturn(new int[0]);
        listener.onInputDeviceChanged(1);
        mTestableLooper.processAllMessages();

        // Verify panels are hidden.
        verify(mockTypePanel).hide();
        verify(mockScrollPanel).hide();

        // Action: reconnect touchpad.
        when(mMockInputManagerWrapper.getInputDeviceIds()).thenReturn(new int[]{1});
        listener.onInputDeviceChanged(1);
        mTestableLooper.processAllMessages();

        // Verify type panel is shown, but scroll panel is not.
        verify(mockTypePanel).show();
        verify(mockScrollPanel, Mockito.never()).show(anyFloat(), anyFloat());
    }

    /**
     * =========================================================================
     * Helper Functions