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

Commit 871d741e authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Move tracking input devices for trackpad to background thread

Fixes: 330996627
Test: manual
Flag: EXEMPT bugfix
Change-Id: Id2bffa8c52177d9fd2737c725ac781c75659da03
parent 27e05672
Loading
Loading
Loading
Loading
+25 −20
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.navigationbar.gestural;
import static android.content.pm.ActivityInfo.CONFIG_FONT_SCALE;
import static android.content.pm.ActivityInfo.CONFIG_FONT_SCALE;
import static android.view.InputDevice.SOURCE_MOUSE;
import static android.view.InputDevice.SOURCE_MOUSE;
import static android.view.InputDevice.SOURCE_TOUCHPAD;
import static android.view.InputDevice.SOURCE_TOUCHPAD;
import static android.view.MotionEvent.TOOL_TYPE_FINGER;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION;


import static com.android.systemui.Flags.edgebackGestureHandlerGetRunningTasksBackground;
import static com.android.systemui.Flags.edgebackGestureHandlerGetRunningTasksBackground;
@@ -216,6 +217,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
    private final int mDisplayId;
    private final int mDisplayId;


    private final UiThreadContext mUiThreadContext;
    private final UiThreadContext mUiThreadContext;
    private final Handler mBgHandler;
    private final Executor mBackgroundExecutor;
    private final Executor mBackgroundExecutor;


    private final Rect mPipExcludedBounds = new Rect();
    private final Rect mPipExcludedBounds = new Rect();
@@ -378,11 +380,14 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        @Override
        @Override
        public void onInputDeviceAdded(int deviceId) {
        public void onInputDeviceAdded(int deviceId) {
            if (isTrackpadDevice(deviceId)) {
            if (isTrackpadDevice(deviceId)) {
                // This updates the gesture handler state and should be running on the main thread.
                mUiThreadContext.getHandler().post(() -> {
                    boolean wasEmpty = mTrackpadsConnected.isEmpty();
                    boolean wasEmpty = mTrackpadsConnected.isEmpty();
                    mTrackpadsConnected.add(deviceId);
                    mTrackpadsConnected.add(deviceId);
                    if (wasEmpty) {
                    if (wasEmpty) {
                        update();
                        update();
                    }
                    }
                });
            }
            }
        }
        }


@@ -391,10 +396,13 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack


        @Override
        @Override
        public void onInputDeviceRemoved(int deviceId) {
        public void onInputDeviceRemoved(int deviceId) {
            // This updates the gesture handler state and should be running on the main thread.
            mUiThreadContext.getHandler().post(() -> {
                mTrackpadsConnected.remove(deviceId);
                mTrackpadsConnected.remove(deviceId);
                if (mTrackpadsConnected.isEmpty()) {
                if (mTrackpadsConnected.isEmpty()) {
                    update();
                    update();
                }
                }
            });
        }
        }


        private void update() {
        private void update() {
@@ -408,12 +416,12 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        }
        }


        private boolean isTrackpadDevice(int deviceId) {
        private boolean isTrackpadDevice(int deviceId) {
            // This is a blocking binder call that should run on a bg thread.
            InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
            InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
            if (inputDevice == null) {
            if (inputDevice == null) {
                return false;
                return false;
            }
            }
            return inputDevice.getSources() == (InputDevice.SOURCE_MOUSE
            return inputDevice.getSources() == (SOURCE_MOUSE | SOURCE_TOUCHPAD);
                    | InputDevice.SOURCE_TOUCHPAD);
        }
        }
    };
    };


@@ -457,6 +465,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        mDisplayId = context.getDisplayId();
        mDisplayId = context.getDisplayId();
        mUiThreadContext = uiThreadContext;
        mUiThreadContext = uiThreadContext;
        mBackgroundExecutor = backgroundExecutor;
        mBackgroundExecutor = backgroundExecutor;
        mBgHandler = bgHandler;
        mUserTracker = userTracker;
        mUserTracker = userTracker;
        mOverviewProxyService = overviewProxyService;
        mOverviewProxyService = overviewProxyService;
        mSysUiState = sysUiState;
        mSysUiState = sysUiState;
@@ -611,9 +620,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        mIsAttached = true;
        mIsAttached = true;
        mOverviewProxyService.addCallback(mQuickSwitchListener);
        mOverviewProxyService.addCallback(mQuickSwitchListener);
        mSysUiState.addCallback(mSysUiStateCallback);
        mSysUiState.addCallback(mSysUiStateCallback);
        mInputManager.registerInputDeviceListener(
        mInputManager.registerInputDeviceListener(mInputDeviceListener, mBgHandler);
                mInputDeviceListener,
                mUiThreadContext.getHandler());
        int[] inputDevices = mInputManager.getInputDeviceIds();
        int[] inputDevices = mInputManager.getInputDeviceIds();
        for (int inputDeviceId : inputDevices) {
        for (int inputDeviceId : inputDevices) {
            mInputDeviceListener.onInputDeviceAdded(inputDeviceId);
            mInputDeviceListener.onInputDeviceAdded(inputDeviceId);
@@ -1202,10 +1209,8 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
    }
    }


    private boolean isButtonPressFromTrackpad(MotionEvent ev) {
    private boolean isButtonPressFromTrackpad(MotionEvent ev) {
        // We don't allow back for button press from the trackpad, and yet we do with a mouse.
        return ev.getSource() == (SOURCE_MOUSE | SOURCE_TOUCHPAD)
        int sources = InputManager.getInstance().getInputDevice(ev.getDeviceId()).getSources();
                && ev.getToolType(ev.getActionIndex()) == TOOL_TYPE_FINGER;
        int sourceTrackpad = (SOURCE_MOUSE | SOURCE_TOUCHPAD);
        return (sources & sourceTrackpad) == sourceTrackpad && ev.getButtonState() != 0;
    }
    }


    private void dispatchToBackAnimation(MotionEvent event) {
    private void dispatchToBackAnimation(MotionEvent event) {