From 765487f929f3d91ab3cd130b6b1d2008b25c4728 Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Tue, 12 Jan 2016 14:45:42 +0900 Subject: [PATCH] Revive volume up/down long press in TV PhoneWindowManager.interceptKeyBeforeQueuing isn't good place to handle long press because rejecting a down event will not synthesize further key repeat. Move the logic to PhoneWindowManager.interceptKeyBeforeDispatching instead. This is the regression caused by following CL 001c59c Route volume keys directly to the audio system on TVs Bug: 26268032 Change-Id: Ic8f6dfaec473c0d45ffa42475763622dc700e635 --- .../server/policy/PhoneWindowManager.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 72611b7703e95..d488fa45a5b2a 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -2963,6 +2963,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { UserHandle.CURRENT_OR_SELF); } return -1; + } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP + || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN + || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { + if (mUseTvRouting) { + // On TVs volume keys never go to the foreground app. + dispatchDirectAudioEvent(event); + return -1; + } } else if (KeyEvent.isMetaKey(keyCode)) { if (down) { mPendingMetaAction = true; @@ -5040,10 +5048,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_MUTE: { - if (mUseTvRouting) { - // On TVs volume keys never go to the foreground app - result &= ~ACTION_PASS_TO_USER; - } if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (down) { if (interactive && !mScreenshotChordVolumeDownKeyTriggered @@ -5103,19 +5107,17 @@ public class PhoneWindowManager implements WindowManagerPolicy { break; } } - - if ((result & ACTION_PASS_TO_USER) == 0) { - if (mUseTvRouting) { - dispatchDirectAudioEvent(event); - } else { - // If we aren't passing to the user and no one else - // handled it send it to the session manager to - // figure out. - MediaSessionLegacyHelper.getHelper(mContext) - .sendVolumeKeyEvent(event, true); - } - break; - } + } + if (mUseTvRouting) { + // On TVs, defer special key handlings to + // {@link interceptKeyBeforeDispatching()}. + result |= ACTION_PASS_TO_USER; + } else if ((result & ACTION_PASS_TO_USER) == 0) { + // If we aren't passing to the user and no one else + // handled it send it to the session manager to + // figure out. + MediaSessionLegacyHelper.getHelper(mContext) + .sendVolumeKeyEvent(event, true); } break; }