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

Commit 899dedf5 authored by Abdelrahman Awadalla's avatar Abdelrahman Awadalla
Browse files

Fixing Concurrent Modification Exception in TouchpadDebugView

A race conditions is being hit because the updates in TouchpadVisualizationView are happening from different threads. In this case, hardware state update is received (which happens on the InputReader thread) at the same time as the onDraw (which happens on the UI thread).
So, Handlers is used to start posting the updateHardwareState and and updateGestureInfo in TouchpadDebugView and onDraw and onTouchpadHardwareStateNotified in TouchpadVisualizationView.

Test: $ atest TouchpadDebugViewTest
Test: $ atest TouchpadDebugViewControllerTests
Test: Presubmit checks
Bug: 368743974
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: I14df74b188b3ba8aadd49e1ce4098e7da1cc1dcb
parent ded22208
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.input.debug;

import android.annotation.AnyThread;
import android.annotation.Nullable;
import android.content.Context;
import android.hardware.input.InputManager;
@@ -157,19 +158,28 @@ public class TouchpadDebugViewController implements InputManager.InputDeviceList
     * @param touchpadHardwareState the hardware state of a touchpad
     * @param deviceId              the deviceId of the touchpad that is sending the hardware state
     */
    @AnyThread
    public void updateTouchpadHardwareState(TouchpadHardwareState touchpadHardwareState,
                                            int deviceId) {
        mHandler.post(() -> {
            if (mTouchpadDebugView != null) {
            mTouchpadDebugView.updateHardwareState(touchpadHardwareState, deviceId);
                mTouchpadDebugView.post(
                        () -> mTouchpadDebugView.updateHardwareState(touchpadHardwareState,
                                deviceId));
            }
        });
    }

    /**
     * Notify the TouchpadDebugView of a new touchpad gesture.
     */
    @AnyThread
    public void updateTouchpadGestureInfo(int gestureType, int deviceId) {
        mHandler.post(() -> {
            if (mTouchpadDebugView != null) {
            mTouchpadDebugView.updateGestureInfo(gestureType, deviceId);
                mTouchpadDebugView.post(
                        () -> mTouchpadDebugView.updateGestureInfo(gestureType, deviceId));
            }
        });
    }
}