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

Commit 1c2e4948 authored by Jeff Brown's avatar Jeff Brown
Browse files

Use a consistent policy for filtering wake keys.

Previously wake keys were filtered differently depending on whether
a keyguard was showing.  If the user disables the keyguard then
no filtering was applied, which means that the volume key may
wake your device while in your pocket.

This change ensures that we use the same policy consistently
regardless of whether keyguard is showing.  The behavior is
otherwise the same.

Removed the "Locked" suffix on a method that was actually
being called without a lock held and which in fact does not
require it.

Bug: 7481025
Change-Id: I704c71ca009bc5437f349f858b9de7c77ea73e4b
parent 0f4d5df5
Loading
Loading
Loading
Loading
+38 −6
Original line number Diff line number Diff line
@@ -3168,8 +3168,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

        if (lidOpen) {
            if (keyguardIsShowingTq()) {
                mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(
                        KeyEvent.KEYCODE_POWER, mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
                mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
            } else {
                mPowerManager.wakeUp(SystemClock.uptimeMillis());
            }
@@ -3388,11 +3387,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            // 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.
            result = 0;
            if (down && isWakeKey) {
            if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
                if (keyguardActive) {
                    // If the keyguard is showing, let it decide what to do with the wake key.
                    mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode,
                            mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
                    // If the keyguard is showing, let it wake the device when ready.
                    mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
                } else {
                    // Otherwise, wake the device ourselves.
                    result |= ACTION_WAKE_UP;
@@ -3614,6 +3612,40 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return result;
    }

    /**
     * When the screen is off we ignore some keys that might otherwise typically
     * be considered wake keys.  We filter them out here.
     *
     * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
     * is always considered a wake key.
     */
    private boolean isWakeKeyWhenScreenOff(int keyCode) {
        switch (keyCode) {
            // ignore volume keys unless docked
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;

            // ignore media and camera keys
            case KeyEvent.KEYCODE_MUTE:
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY:
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            case KeyEvent.KEYCODE_MEDIA_STOP:
            case KeyEvent.KEYCODE_MEDIA_NEXT:
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            case KeyEvent.KEYCODE_MEDIA_REWIND:
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            case KeyEvent.KEYCODE_CAMERA:
                return false;
        }
        return true;
    }


    /** {@inheritDoc} */
    @Override
    public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
+11 −54
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public class KeyguardViewMediator {
     * Does not turn on screen, held while a call to {@link KeyguardViewManager#wakeWhenReadyTq(int)}
     * is called to make sure the device doesn't sleep before it has a chance to poke
     * the wake lock.
     * @see #wakeWhenReadyLocked(int)
     * @see #wakeWhenReady(int)
     */
    private PowerManager.WakeLock mWakeAndHandOff;

@@ -933,8 +933,8 @@ public class KeyguardViewMediator {
     * @see #handleWakeWhenReady
     * @see #onWakeKeyWhenKeyguardShowingTq(int)
     */
    private void wakeWhenReadyLocked(int keyCode) {
        if (DBG_WAKE) Log.d(TAG, "wakeWhenReadyLocked(" + keyCode + ")");
    private void wakeWhenReady(int keyCode) {
        if (DBG_WAKE) Log.d(TAG, "wakeWhenReady(" + keyCode + ")");

        /**
         * acquire the handoff lock that will keep the cpu running.  this will
@@ -1012,54 +1012,14 @@ public class KeyguardViewMediator {
     * action should be posted to a handler.
     *
     * @param keyCode The keycode of the key that woke the device
     * @param isDocked True if the device is in the dock
     * @return Whether we poked the wake lock (and turned the screen on)
     */
    public boolean onWakeKeyWhenKeyguardShowingTq(int keyCode, boolean isDocked) {
    public void onWakeKeyWhenKeyguardShowingTq(int keyCode) {
        if (DEBUG) Log.d(TAG, "onWakeKeyWhenKeyguardShowing(" + keyCode + ")");

        if (isWakeKeyWhenKeyguardShowing(keyCode, isDocked)) {
        // give the keyguard view manager a chance to adjust the state of the
        // keyguard based on the key that woke the device before poking
        // the wake lock
            wakeWhenReadyLocked(keyCode);
            return true;
        } else {
            return false;
        }
    }

    /**
     * When the keyguard is showing we ignore some keys that might otherwise typically
     * be considered wake keys.  We filter them out here.
     *
     * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
     * is always considered a wake key.
     */
    private boolean isWakeKeyWhenKeyguardShowing(int keyCode, boolean isDocked) {
        switch (keyCode) {
            // ignore volume keys unless docked
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return isDocked;

            // ignore media and camera keys
            case KeyEvent.KEYCODE_MUTE:
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY:
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            case KeyEvent.KEYCODE_MEDIA_STOP:
            case KeyEvent.KEYCODE_MEDIA_NEXT:
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            case KeyEvent.KEYCODE_MEDIA_REWIND:
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            case KeyEvent.KEYCODE_CAMERA:
                return false;
        }
        return true;
        wakeWhenReady(keyCode);
    }

    /**
@@ -1071,17 +1031,14 @@ public class KeyguardViewMediator {
     * The 'Tq' suffix is per the documentation in {@link WindowManagerPolicy}.
     * Be sure not to take any action that takes a long time; any significant
     * action should be posted to a handler.
     *
     * @return Whether we poked the wake lock (and turned the screen on)
     */
    public boolean onWakeMotionWhenKeyguardShowingTq() {
    public void onWakeMotionWhenKeyguardShowingTq() {
        if (DEBUG) Log.d(TAG, "onWakeMotionWhenKeyguardShowing()");

        // give the keyguard view manager a chance to adjust the state of the
        // keyguard based on the key that woke the device before poking
        // the wake lock
        wakeWhenReadyLocked(KeyEvent.KEYCODE_UNKNOWN);
        return true;
        wakeWhenReady(KeyEvent.KEYCODE_UNKNOWN);
    }

    public void keyguardDone(boolean authenticated, boolean wakeup) {
@@ -1348,7 +1305,7 @@ public class KeyguardViewMediator {
    }

    /**
     * Handle message sent by {@link #wakeWhenReadyLocked(int)}
     * Handle message sent by {@link #wakeWhenReady(int)}
     * @param keyCode The key that woke the device.
     * @see #WAKE_WHEN_READY
     */