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

Commit 8f9c28bc authored by Matt Garnes's avatar Matt Garnes Committed by Steve Kondik
Browse files

If a wake key is disabled by the user, do not wake from doze.

Currently, any wake key will wake the device from a doze, even if that
key has not been enabled as a wake key in Settings.

If the device is 'dreaming' in the Doze state, check if the user has
explicitly disabled the wake key (or never enabled the setting in the
first place) before waking the device.

Change-Id: I7397087c143161e8e1ddb84d0e23f6027fea0aac
parent b5ed5703
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -5905,8 +5905,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);
        } else {
            // When the screen is off and the key is not injected, determine whether
            // to wake the device but don't pass the key to the application.
@@ -6290,6 +6291,29 @@ 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 mVolumeWakeScreen || mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
            case KeyEvent.KEYCODE_BACK:
                return mBackWakeScreen;
            case KeyEvent.KEYCODE_MENU:
                return mMenuWakeScreen;
            case KeyEvent.KEYCODE_ASSIST:
                return mAssistWakeScreen;
            case KeyEvent.KEYCODE_APP_SWITCH:
                return mAppSwitchWakeScreen;
        }
        return true;
    }

    /**
     * When the screen is off we ignore some keys that might otherwise typically
     * be considered wake keys.  We filter them out here.