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

Unverified Commit 0869a5e3 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

fw/b: Implement device hardware wake keys support



Co-authored-by: default avatarClyde Tan <bokbokan@gmail.com>
Co-authored-by: default avatarDanny Baumann <dannybaumann@web.de>
Co-authored-by: default avatarGabriele M <moto.falcon.git@gmail.com>
Co-authored-by: default avatarJason Riordan <jriordan001@gmail.com>
Co-authored-by: default avatarMartin Brabham <optedoblivion@cyngn.com>
Co-authored-by: default avatarMatt Garnes <matt@cyngn.com>
Co-authored-by: default avatarMichael Bestas <mikeioannina@gmail.com>
Co-authored-by: default avatarwilll03 <wgangers@gmail.com>
Change-Id: Ic294515c7200c1260ac514db23ef3778d374d727
parent c756a965
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2937,6 +2937,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
    public static final boolean isWakeKey(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_STEM_1:
@@ -2944,6 +2945,9 @@ public class KeyEvent extends InputEvent implements Parcelable {
            case KeyEvent.KEYCODE_STEM_3:
            case KeyEvent.KEYCODE_WAKEUP:
            case KeyEvent.KEYCODE_STEM_PRIMARY:
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return true;
        }
        return false;
+160 −10
Original line number Diff line number Diff line
@@ -663,6 +663,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mIsFocusPressed;
    boolean mIsLongPress;

    // Button wake control flags
    boolean mWakeOnHomeKeyPress;
    boolean mWakeOnMenuKeyPress;
    boolean mWakeOnAppSwitchKeyPress;
    boolean mWakeOnCameraKeyPress;
    boolean mWakeOnVolumeKeyPress;

    // During wakeup by volume keys, we still need to capture subsequent events
    // until the key is released. This is required since the beep sound is produced
    // post keypressed.
    boolean mVolumeDownWakeTriggered;
    boolean mVolumeUpWakeTriggered;
    boolean mVolumeMuteWakeTriggered;

    private boolean mPendingKeyguardOccluded;
    private boolean mKeyguardOccludedChanged;

@@ -1014,6 +1028,27 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.KEY_APP_SWITCH_LONG_PRESS_ACTION), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.CAMERA_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.HOME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.BACK_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.MENU_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.ASSIST_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.APP_SWITCH_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
        }

@@ -2477,10 +2512,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        Resources res = mContext.getResources();
        mWakeOnDpadKeyPress =
                res.getBoolean(com.android.internal.R.bool.config_wakeOnDpadKeyPress);
        mWakeOnAssistKeyPress =
                res.getBoolean(com.android.internal.R.bool.config_wakeOnAssistKeyPress);
        mWakeOnBackKeyPress =
                res.getBoolean(com.android.internal.R.bool.config_wakeOnBackKeyPress);

        // Init display burn-in protection
        boolean burnInProtectionEnabled = mContext.getResources().getBoolean(
@@ -3224,6 +3255,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        boolean updateRotation = false;
        boolean updateKidsModeSettings = false;
        final boolean kidsModeEnabled;
        int mDeviceHardwareWakeKeys = mContext.getResources().getInteger(
                org.lineageos.platform.internal.R.integer.config_deviceHardwareWakeKeys);
        synchronized (mLock) {
            mEndcallBehavior = Settings.System.getIntForUser(resolver,
                    Settings.System.END_BUTTON_BEHAVIOR,
@@ -3254,7 +3287,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mCameraLaunch = LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.CAMERA_LAUNCH, 0,
                    UserHandle.USER_CURRENT) == 1;
            mCameraSleepOnRelease = LineageSettings.System.getIntForUser(resolver,
            mWakeOnCameraKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.CAMERA_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_CAMERA) != 0);
            mCameraSleepOnRelease = mWakeOnCameraKeyPress &&
                    LineageSettings.System.getIntForUser(resolver,
                            LineageSettings.System.CAMERA_SLEEP_ON_RELEASE, 0,
                            UserHandle.USER_CURRENT) == 1;
            mTorchLongPressPowerEnabled = LineageSettings.System.getIntForUser(
@@ -3263,6 +3300,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mTorchTimeout = LineageSettings.System.getIntForUser(
                    resolver, LineageSettings.System.TORCH_LONG_PRESS_POWER_TIMEOUT, 0,
                    UserHandle.USER_CURRENT);
            mWakeOnHomeKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.HOME_WAKE_SCREEN, 1, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_HOME) != 0);
            mWakeOnBackKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.BACK_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_BACK) != 0);
            mWakeOnMenuKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.MENU_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_MENU) != 0);
            mWakeOnAssistKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.ASSIST_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_ASSIST) != 0);
            mWakeOnAppSwitchKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.APP_SWITCH_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_APP_SWITCH) != 0);
            mWakeOnVolumeKeyPress = (LineageSettings.System.getIntForUser(resolver,
                    LineageSettings.System.VOLUME_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1)
                    && ((mDeviceHardwareWakeKeys & KEY_MASK_VOLUME) != 0);

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -4633,7 +4688,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                awakenDreams();
            }
            hideRecentApps(false, true);
        } else {
        } else if (mDefaultDisplayPolicy.isScreenOnFully()) {
            // Otherwise, just launch Home
            startDockOrHome(displayId, true /*fromHomeKey*/, awakenFromDreams);
        }
@@ -4668,6 +4723,36 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return mKeyguardDelegate.isShowing();
    }

    private void setVolumeWakeTriggered(final int keyCode, boolean triggered) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                mVolumeDownWakeTriggered = triggered;
                break;
            case KeyEvent.KEYCODE_VOLUME_UP:
                mVolumeUpWakeTriggered = triggered;
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                mVolumeMuteWakeTriggered = triggered;
                break;
            default:
                Log.w(TAG, "setVolumeWakeTriggered: unexpected keyCode=" + keyCode);
        }
    }

    private boolean getVolumeWakeTriggered(final int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                return mVolumeDownWakeTriggered;
            case KeyEvent.KEYCODE_VOLUME_UP:
                return mVolumeUpWakeTriggered;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return mVolumeMuteWakeTriggered;
            default:
                Log.w(TAG, "getVolumeWakeTriggered: unexpected keyCode=" + keyCode);
                return false;
        }
    }

    /** {@inheritDoc} */
    @Override
    public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
@@ -4852,8 +4937,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            // If we're currently dozing with the screen on and the keyguard showing, pass the key
            // to the application but preserve its wake key status to make sure we still move
            // from dozing to fully interactive if we would normally go from off to fully
            // interactive.
            // interactive, unless the user has explicitly disabled this wake key.
            result = ACTION_PASS_TO_USER;
            isWakeKey = isWakeKey && isWakeKeyEnabled(keyCode);
            // Since we're dispatching the input, reset the pending key
            mPendingWakeKey = PENDING_KEY_NULL;
        } else {
@@ -4965,6 +5051,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                // Eat all down & up keys when using volume wake.
                // This disables volume control, music control, and "beep" on key up.
                if (isWakeKey && mWakeOnVolumeKeyPress) {
                    setVolumeWakeTriggered(keyCode, true);
                    break;
                } else if (getVolumeWakeTriggered(keyCode) && !down) {
                    result &= ~ACTION_PASS_TO_USER;
                    setVolumeWakeTriggered(keyCode, false);
                    break;
                }

                int gestureType = keyCode == KEYCODE_VOLUME_DOWN
                        ? KeyGestureEvent.KEY_GESTURE_TYPE_VOLUME_DOWN
                        : keyCode == KEYCODE_VOLUME_UP
@@ -5023,7 +5120,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    // Defer special key handlings to
                    // {@link interceptKeyBeforeDispatching()}.
                    result |= ACTION_PASS_TO_USER;
                } else if ((result & ACTION_PASS_TO_USER) == 0) {
                } else if ((result & ACTION_PASS_TO_USER) == 0 && !mWakeOnVolumeKeyPress) {
                    if (mLineageButtons.handleVolumeKey(event, interactive)) {
                        break;
                    }
@@ -5037,6 +5134,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                break;
            }

            case KeyEvent.KEYCODE_HOME:
                if (down && !interactive) {
                    isWakeKey = mWakeOnHomeKeyPress;
                    if (!isWakeKey) {
                        useHapticFeedback = false;
                    }
                }
                break;

            case KeyEvent.KEYCODE_FOCUS:
                if (down && !interactive && mCameraSleepOnRelease) {
                    mIsFocusPressed = true;
@@ -5076,6 +5182,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        } else {
                            intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                        }
                        isWakeKey = true;
                        startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
                    }
                }
@@ -5511,6 +5618,33 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    /**
     * Check if the given keyCode represents a key that is considered a wake key
     * and is currently enabled by the user in Settings or for another reason.
     */
    private boolean isWakeKeyEnabled(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                // Volume keys are still wake keys if the device is docked.
                return mWakeOnVolumeKeyPress ||
                        mDefaultDisplayPolicy.getDockMode() != Intent.EXTRA_DOCK_STATE_UNDOCKED;
            case KeyEvent.KEYCODE_BACK:
                return mWakeOnBackKeyPress;
            case KeyEvent.KEYCODE_MENU:
                return mWakeOnMenuKeyPress;
            case KeyEvent.KEYCODE_ASSIST:
                return mWakeOnAssistKeyPress;
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mWakeOnAppSwitchKeyPress;
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mWakeOnCameraKeyPress;
        }
        return true;
    }

    /**
     * When the screen is off we ignore some keys that might otherwise typically
     * be considered wake keys.  We filter them out here.
@@ -5520,6 +5654,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
     */
    private boolean isWakeKeyWhenScreenOff(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return mWakeOnVolumeKeyPress ||
                        mDefaultDisplayPolicy.getDockMode() != Intent.EXTRA_DOCK_STATE_UNDOCKED;

            case KeyEvent.KEYCODE_DPAD_UP:
            case KeyEvent.KEYCODE_DPAD_DOWN:
            case KeyEvent.KEYCODE_DPAD_LEFT:
@@ -5533,6 +5673,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_BACK:
                return mWakeOnBackKeyPress;

            case KeyEvent.KEYCODE_MENU:
                return mWakeOnMenuKeyPress;

            case KeyEvent.KEYCODE_APP_SWITCH:
                return mWakeOnAppSwitchKeyPress;

            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_FOCUS:
                return mWakeOnCameraKeyPress;

            case KeyEvent.KEYCODE_STYLUS_BUTTON_PRIMARY:
            case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY:
            case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: