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

Commit f107bda0 authored by Sascha Prueter's avatar Sascha Prueter Committed by Android Git Automerger
Browse files

am a517fc3a: am ee8fab8b: am 872965bb: Merge "Use a consistent policy for...

am a517fc3a: am ee8fab8b: am 872965bb: Merge "Use a consistent policy for filtering wake keys." into jb-mr1-dev

* commit 'a517fc3a':
  Use a consistent policy for filtering wake keys.
parents a965fc5e a517fc3a
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;

@@ -935,8 +935,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
@@ -1014,54 +1014,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);
    }

    /**
@@ -1073,17 +1033,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) {
@@ -1350,7 +1307,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
     */