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

Commit 4addccb4 authored by Omar Abdelmonem's avatar Omar Abdelmonem
Browse files

Handle multiple touchpads in TouchpadDebugViewController

Add logic to the TouchpadDebugViewController to be able to handle,
multiple touchpad connection/disconnection, to avoid a state of
having a touchpad connected but no View after original touchpad
disconnection.
Made sure that the View's colour only changes when a
HardwareProperty of the same ID is received.

Bug: 363979581

Test: Updated unit tests to test sending HardwareProperties with
different deviceIds to the view and verify that only the one with
the same deviceId affected the View.
Manual testing by connecting multiple touchpads and verifying the
result of disconnecting the first or second touchpad and making
sure we get the desired behaviour.
Flag: com.android.hardware.input.touchpad_visualizer

Change-Id: I9dc8c53ed48e53002d9f13bed250d1a65ddbf20a
parent 1c218092
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -2269,14 +2269,8 @@ public class InputManagerService extends IInputManager.Stub
    // Native callback.
    @SuppressWarnings("unused")
    private void notifyTouchpadHardwareState(TouchpadHardwareState hardwareStates, int deviceId) {
        Slog.d(TAG, "notifyTouchpadHardwareState: Time: "
                + hardwareStates.getTimestamp() + ", No. Buttons: "
                + hardwareStates.getButtonsDown() + ", No. Fingers: "
                + hardwareStates.getFingerCount() + ", No. Touch: "
                + hardwareStates.getTouchCount() + ", Id: "
                + deviceId);
        if (mTouchpadDebugViewController != null) {
            mTouchpadDebugViewController.updateTouchpadHardwareState(hardwareStates);
            mTouchpadDebugViewController.updateTouchpadHardwareState(hardwareStates, deviceId);
        }
    }

+9 −1
Original line number Diff line number Diff line
@@ -213,7 +213,15 @@ public class TouchpadDebugView extends LinearLayout {
        return mWindowLayoutParams;
    }

    public void updateHardwareState(TouchpadHardwareState touchpadHardwareState) {
    /**
     * Notify the view of a change in TouchpadHardwareState and changing the
     * color of the view based on the status of the button click.
     */
    public void updateHardwareState(TouchpadHardwareState touchpadHardwareState, int deviceId) {
        if (deviceId != mTouchpadId) {
            return;
        }

        if (mLastTouchpadState.getButtonsDown() == 0) {
            if (touchpadHardwareState.getButtonsDown() > 0) {
                onTouchpadButtonPress();
+13 −2
Original line number Diff line number Diff line
@@ -68,6 +68,13 @@ public class TouchpadDebugViewController implements InputManager.InputDeviceList
    @Override
    public void onInputDeviceRemoved(int deviceId) {
        hideDebugView(deviceId);
        if (mTouchpadDebugView == null) {
            final InputManager inputManager = Objects.requireNonNull(
                    mContext.getSystemService(InputManager.class));
            for (int id : inputManager.getInputDeviceIds()) {
                onInputDeviceAdded(id);
            }
        }
    }

    @Override
@@ -134,9 +141,13 @@ public class TouchpadDebugViewController implements InputManager.InputDeviceList
        Slog.d(TAG, "Touchpad debug view removed.");
    }

    public void updateTouchpadHardwareState(TouchpadHardwareState touchpadHardwareState) {
    /**
     * Notify the TouchpadDebugView with the new TouchpadHardwareState.
     */
    public void updateTouchpadHardwareState(TouchpadHardwareState touchpadHardwareState,
                                            int deviceId) {
        if (mTouchpadDebugView != null) {
            mTouchpadDebugView.updateHardwareState(touchpadHardwareState);
            mTouchpadDebugView.updateHardwareState(touchpadHardwareState, deviceId);
        }
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -300,19 +300,26 @@ public class TouchpadDebugViewTest {

        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 1 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]));
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);

        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 0 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]));
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.RED);

        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 1 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]));
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);

        // Color should not change because hardware state of a different touchpad
        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 0 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID + 1);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);
    }