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

Commit cb49228b authored by LuK1337's avatar LuK1337 Committed by Bruno Martins
Browse files

PhoneWindowManager: Add support for back key long press customization

Change-Id: I28762c88d4777f8dbc8f213a2522875c3428fdab
parent 6941ebee
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -559,6 +559,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mPendingCapsLockToggle;

    // Tracks user-customisable behavior for certain key events
    private Action mBackLongPressAction;
    private Action mHomeLongPressAction;
    private Action mHomeDoubleTapAction;
    private Action mMenuPressAction;
@@ -830,6 +831,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.KEY_BACK_LONG_PRESS_ACTION), false, this,
                    UserHandle.USER_ALL);
           resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.KEY_HOME_LONG_PRESS_ACTION), false, this,
                    UserHandle.USER_ALL);
@@ -1303,13 +1307,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private void backLongPress() {
        mBackKeyHandled = true;

        switch (mLongPressOnBackBehavior) {
            case LONG_PRESS_BACK_NOTHING:
                break;
            case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
                launchVoiceAssist(false /* allowDuringSetup */);
                break;
        }
        long now = SystemClock.uptimeMillis();
        KeyEvent event = new KeyEvent(now, now, KeyEvent.ACTION_DOWN,
                KEYCODE_BACK, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
                KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD);

        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                "Back - Long Press");
        performKeyAction(mBackLongPressAction, event);
    }

    private void accessibilityShortcutActivated() {
@@ -1377,7 +1382,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    private boolean hasLongPressOnBackBehavior() {
        return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING;
        return mBackLongPressAction != Action.NOTHING;
    }

    private void interceptScreenshotChord() {
@@ -2310,11 +2315,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            powerKeyGestures |= KEY_LONGPRESS;
        }
        mSingleKeyGestureDetector.addRule(new PowerKeyRule(powerKeyGestures));

        if (hasLongPressOnBackBehavior()) {
        mSingleKeyGestureDetector.addRule(new BackKeyRule(KEY_LONGPRESS));
    }
    }

    private void updateKeyAssignments() {
        int activeHardwareKeys = mDeviceHardwareKeys;
@@ -2344,6 +2346,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {

        mEdgeLongSwipeAction = Action.NOTHING;

        mBackLongPressAction = Action.fromIntSafe(res.getInteger(
                org.lineageos.platform.internal.R.integer.config_longPressOnBackBehavior));
        if (mBackLongPressAction.ordinal() > Action.SLEEP.ordinal()) {
            mBackLongPressAction = Action.NOTHING;
        }

        mBackLongPressAction = Action.fromSettings(resolver,
                LineageSettings.System.KEY_BACK_LONG_PRESS_ACTION,
                mBackLongPressAction);

        mHomeLongPressAction = Action.fromIntSafe(res.getInteger(
                org.lineageos.platform.internal.R.integer.config_longPressOnHomeBehavior));
        if (mHomeLongPressAction.ordinal() > Action.SLEEP.ordinal()) {