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

Commit 9bf606b9 authored by LuK1337's avatar LuK1337
Browse files

PhoneWindowManager: Add support for back key long press customization

Change-Id: I28762c88d4777f8dbc8f213a2522875c3428fdab
parent b6f3f983
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -561,6 +561,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private int mForceNavbar = -1;

    // Tracks user-customisable behavior for certain key events
    private Action mBackLongPressAction;
    private Action mHomeLongPressAction;
    private Action mHomeDoubleTapAction;
    private Action mMenuPressAction;
@@ -776,7 +777,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    showPictureInPictureMenuInternal();
                    break;
                case MSG_BACK_LONG_PRESS:
                    backLongPress();
                    backLongPress((KeyEvent) msg.obj);
                    break;
                case MSG_ACCESSIBILITY_SHORTCUT:
                    accessibilityShortcutActivated();
@@ -878,6 +879,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);
@@ -1014,13 +1018,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private void interceptBackKeyDown() {
    private void interceptBackKeyDown(KeyEvent event) {
        mLogger.count("key_back_down", 1);
        // Reset back key state for long press
        mBackKeyHandled = false;

        if (hasLongPressOnBackBehavior()) {
            Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS);
            Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS, event);
            msg.setAsynchronous(true);
            mHandler.sendMessageDelayed(msg,
                    ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
@@ -1458,16 +1462,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private void backLongPress() {
    private void backLongPress(KeyEvent event) {
        mBackKeyHandled = true;

        switch (mLongPressOnBackBehavior) {
            case LONG_PRESS_BACK_NOTHING:
                break;
            case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST:
                launchVoiceAssist(false /* allowDuringSetup */);
                break;
        }
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                "Back - Long Press");
        performKeyAction(mBackLongPressAction, event);
    }

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

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

    private void interceptScreenshotChord() {
@@ -2304,6 +2304,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()) {
@@ -4244,7 +4254,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                }

                if (down) {
                    interceptBackKeyDown();
                    interceptBackKeyDown(event);
                } else {
                    boolean handled = interceptBackKeyUp(event);