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

Commit 37fa9143 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Handle custom key gestures added by the user

DD: go/customizable_shortcuts
PRD: go/custom-kb-shortcuts

Bug: 365064144
Test: atest InputTests:CustomInputGestureManagerTests
Flag: com.android.hardware.input.enable_customizable_input_gestures
Change-Id: I3d3f18558174fb9cc5ec03b3808a357ff0aa2b5b
parent bda78423
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -17,10 +17,13 @@
package com.android.server.input;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.hardware.input.InputGestureData;
import android.hardware.input.InputManager;
import android.util.IndentingPrintWriter;
import android.util.SparseArray;
import android.view.KeyEvent;

import com.android.internal.annotations.GuardedBy;

@@ -40,6 +43,10 @@ import java.util.Objects;
final class InputGestureManager {
    private static final String TAG = "InputGestureManager";

    private static final int KEY_GESTURE_META_MASK =
            KeyEvent.META_CTRL_ON | KeyEvent.META_ALT_ON | KeyEvent.META_SHIFT_ON
                    | KeyEvent.META_META_ON;

    @GuardedBy("mCustomInputGestures")
    private final SparseArray<Map<InputGestureData.Trigger, InputGestureData>>
            mCustomInputGestures = new SparseArray<>();
@@ -96,6 +103,23 @@ final class InputGestureManager {
        }
    }

    @Nullable
    public InputGestureData getCustomGestureForKeyEvent(@UserIdInt int userId, KeyEvent event) {
        final int keyCode = event.getKeyCode();
        if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
            return null;
        }
        synchronized (mCustomInputGestures) {
            Map<InputGestureData.Trigger, InputGestureData> customGestures =
                    mCustomInputGestures.get(userId);
            if (customGestures == null) {
                return null;
            }
            int modifierState = event.getMetaState() & KEY_GESTURE_META_MASK;
            return customGestures.get(InputGestureData.createKeyTrigger(keyCode, modifierState));
        }
    }

    public void dump(IndentingPrintWriter ipw) {
        ipw.println("InputGestureManager:");
        ipw.increaseIndent();
+1 −0
Original line number Diff line number Diff line
@@ -3022,6 +3022,7 @@ public class InputManagerService extends IInputManager.Stub

    private void handleCurrentUserChanged(@UserIdInt int userId) {
        mCurrentUserId = userId;
        mKeyGestureController.setCurrentUserId(userId);
    }

    /**