summaryrefslogtreecommitdiffstats
path: root/policy/src
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2015-01-26 15:53:51 -0800
committerRoboErik <epastern@google.com>2015-01-29 16:14:31 -0800
commit001c59c6374a171a0bd3bd969744be6a4318efce (patch)
treed2d49c71b9424f591e907153badd9f964b2e03ca /policy/src
parent4197cb60bc74629fe4c04ab10cb3b1c9a7427d24 (diff)
downloadframeworks_base-001c59c6374a171a0bd3bd969744be6a4318efce.zip
frameworks_base-001c59c6374a171a0bd3bd969744be6a4318efce.tar.gz
frameworks_base-001c59c6374a171a0bd3bd969744be6a4318efce.tar.bz2
Route volume keys directly to the audio system on TVs
This routes volume and mute keys directly to the audio system when on a television instead of letting apps or sessions intercept them. Change-Id: I2af47e30c7842aca96d045a6cc9ca025b94e546a
Diffstat (limited to 'policy/src')
-rw-r--r--policy/src/com/android/internal/policy/impl/PhoneWindowManager.java78
1 files changed, 73 insertions, 5 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index d4032cc..ac095e6 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -43,6 +43,7 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.media.AudioAttributes;
import android.media.AudioManager;
+import android.media.AudioService;
import android.media.IAudioService;
import android.media.Ringtone;
import android.media.RingtoneManager;
@@ -376,6 +377,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
boolean mHasSoftInput = false;
boolean mTranslucentDecorEnabled = true;
+ boolean mUseTvRouting;
+ boolean mUseMasterVolume;
int mPointerLocationMode = 0; // guarded by mLock
@@ -1262,6 +1265,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
com.android.internal.R.integer.config_triplePressOnPowerBehavior);
+ mUseTvRouting = AudioService.getPlatformType(mContext) == AudioService.PLATFORM_TELEVISION;
+ mUseMasterVolume = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_useMasterVolume);
+
readConfigurationDependentBehaviors();
mAccessibilityManager = (AccessibilityManager) context.getSystemService(
@@ -4534,6 +4541,10 @@ 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
@@ -4595,11 +4606,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
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);
+ 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;
}
}
@@ -4844,6 +4859,59 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return false;
}
+ private void dispatchDirectAudioEvent(KeyEvent event) {
+ if (event.getAction() != KeyEvent.ACTION_DOWN) {
+ return;
+ }
+ int keyCode = event.getKeyCode();
+ int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
+ String pkgName = mContext.getOpPackageName();
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ try {
+ if (mUseMasterVolume) {
+ getAudioService().adjustMasterVolume(AudioManager.ADJUST_RAISE, flags,
+ pkgName);
+ } else {
+ getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
+ AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
+ }
+ break;
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ try {
+ if (mUseMasterVolume) {
+ getAudioService().adjustMasterVolume(AudioManager.ADJUST_LOWER, flags,
+ pkgName);
+ } else {
+ getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
+ AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
+ }
+ break;
+ case KeyEvent.KEYCODE_VOLUME_MUTE:
+ try {
+ if (event.getRepeatCount() == 0) {
+ if (mUseMasterVolume) {
+ getAudioService().adjustMasterVolume(AudioManager.ADJUST_TOGGLE_MUTE,
+ flags, pkgName);
+ } else {
+ getAudioService().adjustSuggestedStreamVolume(
+ AudioManager.ADJUST_TOGGLE_MUTE,
+ AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
+ }
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
+ }
+ break;
+ }
+ }
+
void dispatchMediaKeyWithWakeLock(KeyEvent event) {
if (DEBUG_INPUT) {
Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);