From 86ecf34ca4a07a876511be8f99abcb1d77ab73d5 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Fri, 28 Apr 2017 15:35:58 -0700 Subject: [PATCH] Handle volume keys to apps in Vr mode When a device is in Vr mode - - Volume key event must be passed to the audio subsystem to reflect changes when the configuration is enabled. - When the configuration is disabled, neither the apps not the audio subsystem should be able to receive the volume key events Bug: 37625887 Bug: 36280728 Test: - Verified that the app doesn't receive volume events - Verified that the system volume bar is also not triggered Change-Id: I245f7797873f764d0b017879723a6dbff1bb4d36 Signed-off-by: Karthik Ravi Shankar --- core/res/res/values/config.xml | 4 ++++ core/res/res/values/symbols.xml | 1 + .../server/policy/PhoneWindowManager.java | 20 +++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index a921fd740b7ea..8006f786d4a8e 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2872,4 +2872,8 @@ + + + false + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 1966f6a894127..cff6eb198473e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3010,4 +3010,5 @@ + diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 4fb18d9e17c0f..07818fd112383 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -584,6 +584,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mTranslucentDecorEnabled = true; boolean mUseTvRouting; + private boolean mHandleVolumeKeysInWM; + int mPointerLocationMode = 0; // guarded by mLock // The last window we were told about in focusChanged. @@ -1928,6 +1930,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; + mHandleVolumeKeysInWM = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_handleVolumeKeysInWindowManager); + readConfigurationDependentBehaviors(); mAccessibilityManager = (AccessibilityManager) context.getSystemService( @@ -3522,11 +3527,18 @@ public class PhoneWindowManager implements WindowManagerPolicy { } 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. + if (mUseTvRouting || mHandleVolumeKeysInWM) { + // On TVs or when the configuration is enabled, volume keys never + // go to the foreground app. dispatchDirectAudioEvent(event); return -1; } + + // If the device is in Vr mode, drop the volume keys and don't + // forward it to the application/dispatch the audio event. + if (mPersistentVrModeEnabled) { + return -1; + } } else if (keyCode == KeyEvent.KEYCODE_TAB && event.isMetaPressed()) { // Pass through keyboard navigation keys. return 0; @@ -5911,8 +5923,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } } - if (mUseTvRouting) { - // On TVs, defer special key handlings to + if (mUseTvRouting || mHandleVolumeKeysInWM) { + // Defer special key handlings to // {@link interceptKeyBeforeDispatching()}. result |= ACTION_PASS_TO_USER; } else if ((result & ACTION_PASS_TO_USER) == 0) {