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

Commit 5e3f68d1 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

(3/n) Remove usage of isKeyGestureSupported() from KeyGestureController

isKeyGestureSupported is synchronous API that makes system server
dependent on handler and can cause ANR if handlers misbehave.
It was added as a stop gap for multi-key gestures that require
some SysUI info like keyguard state, display state, etc, to decide
if the key needs to be consumed or not at the start of the gesture.

Test: atest KeygestureControllerTests
Bug: 358569822
Bug: 383602794
Flag: EXEMPT refactor
Change-Id: I14abee92ede63e57c4c0d92c3d0eb501bd14a3bd
parent b57366c5
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -28,15 +28,4 @@ interface IKeyGestureHandler {
     * to that gesture.
     */
    boolean handleKeyGesture(in AidlKeyGestureEvent event, in IBinder focusedToken);

    /**
     * Called to know if a particular gesture type is supported by the handler.
     *
     * TODO(b/358569822): Remove this call to reduce the binder calls to single call for
     *  handleKeyGesture. For this we need to remove dependency of multi-key gestures to identify if
     *  a key gesture is supported on first relevant key down.
     *  Also, for now we prioritize handlers in the system server process above external handlers to
     *  reduce IPC binder calls.
     */
    boolean isKeyGestureSupported(int gestureType);
}
+0 −7
Original line number Diff line number Diff line
@@ -1758,13 +1758,6 @@ public final class InputManager {
         */
        boolean handleKeyGestureEvent(@NonNull KeyGestureEvent event,
                @Nullable IBinder focusedToken);

        /**
         * Called to identify if a particular gesture is of interest to a handler.
         *
         * NOTE: If no active handler supports certain gestures, the gestures will not be captured.
         */
        boolean isKeyGestureSupported(@KeyGestureEvent.KeyGestureType int gestureType);
    }

    /** @hide */
+0 −17
Original line number Diff line number Diff line
@@ -1193,23 +1193,6 @@ public final class InputManagerGlobal {
            }
            return false;
        }

        @Override
        public boolean isKeyGestureSupported(@KeyGestureEvent.KeyGestureType int gestureType) {
            synchronized (mKeyGestureEventHandlerLock) {
                if (mKeyGestureEventHandlers == null) {
                    return false;
                }
                final int numHandlers = mKeyGestureEventHandlers.size();
                for (int i = 0; i < numHandlers; i++) {
                    KeyGestureEventHandler handler = mKeyGestureEventHandlers.get(i);
                    if (handler.isKeyGestureSupported(gestureType)) {
                        return true;
                    }
                }
            }
            return false;
        }
    }

    /**
+0 −14
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ class DesktopModeKeyGestureHandler(

    override fun handleKeyGestureEvent(event: KeyGestureEvent, focusedToken: IBinder?): Boolean {
        if (
            !isKeyGestureSupported(event.keyGestureType) ||
                !desktopTasksController.isPresent ||
                !desktopModeWindowDecorViewModel.isPresent
        ) {
@@ -136,19 +135,6 @@ class DesktopModeKeyGestureHandler(
        }
    }

    override fun isKeyGestureSupported(gestureType: Int): Boolean =
        when (gestureType) {
            KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY ->
                enableMoveToNextDisplayShortcut()
            KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW,
            KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW,
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW,
            KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW ->
                DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue &&
                    manageKeyGestures()
            else -> false
        }

    //  TODO: b/364154795 - wait for the completion of moveToNextDisplay transition, otherwise it
    //  will pick a wrong task when a user quickly perform other actions with keyboard shortcuts
    //  after moveToNextDisplay, and move this to FocusTransitionObserver class.
+0 −8
Original line number Diff line number Diff line
@@ -162,10 +162,6 @@ constructor(
            ): Boolean {
                return this@NoteTaskInitializer.handleKeyGestureEvent(event)
            }

            override fun isKeyGestureSupported(gestureType: Int): Boolean {
                return this@NoteTaskInitializer.isKeyGestureSupported(gestureType)
            }
        }

    /**
@@ -225,10 +221,6 @@ constructor(
        return true
    }

    private fun isKeyGestureSupported(gestureType: Int): Boolean {
        return gestureType == KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES
    }

    companion object {
        val MULTI_PRESS_TIMEOUT = ViewConfiguration.getMultiPressTimeout().toLong()
        val LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout().toLong()
Loading