From 001c59c6374a171a0bd3bd969744be6a4318efce Mon Sep 17 00:00:00 2001 From: RoboErik Date: Mon, 26 Jan 2015 15:53:51 -0800 Subject: 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 --- media/java/android/media/AudioService.java | 36 ++++++++++++++-------- .../media/session/MediaSessionLegacyHelper.java | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'media') diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index d96fee6..98a43a8 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -153,11 +153,11 @@ public class AudioService extends IAudioService.Stub { private final AppOpsManager mAppOps; // the platform has no specific capabilities - private static final int PLATFORM_DEFAULT = 0; + public static final int PLATFORM_DEFAULT = 0; // the platform is voice call capable (a phone) - private static final int PLATFORM_VOICE = 1; + public static final int PLATFORM_VOICE = 1; // the platform is a television or a set-top box - private static final int PLATFORM_TELEVISION = 2; + public static final int PLATFORM_TELEVISION = 2; // the platform type affects volume and silent mode behavior private final int mPlatformType; @@ -546,15 +546,7 @@ public class AudioService extends IAudioService.Stub { mContentResolver = context.getContentResolver(); mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); - if (mContext.getResources().getBoolean( - com.android.internal.R.bool.config_voice_capable)) { - mPlatformType = PLATFORM_VOICE; - } else if (context.getPackageManager().hasSystemFeature( - PackageManager.FEATURE_LEANBACK)) { - mPlatformType = PLATFORM_TELEVISION; - } else { - mPlatformType = PLATFORM_DEFAULT; - } + mPlatformType = getPlatformType(context); PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mAudioEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleAudioEvent"); @@ -667,6 +659,26 @@ public class AudioService extends IAudioService.Stub { LocalServices.addService(AudioManagerInternal.class, new AudioServiceInternal()); } + /** + * Return the platform type that this is running on. One of: + * + */ + public static int getPlatformType(Context context) { + if (context.getResources().getBoolean( + com.android.internal.R.bool.config_voice_capable)) { + return PLATFORM_VOICE; + } else if (context.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_LEANBACK)) { + return PLATFORM_TELEVISION; + } else { + return PLATFORM_DEFAULT; + } + } + public void systemReady() { sendMsg(mAudioHandler, MSG_SYSTEM_READY, SENDMSG_QUEUE, 0, 0, null, 0); diff --git a/media/java/android/media/session/MediaSessionLegacyHelper.java b/media/java/android/media/session/MediaSessionLegacyHelper.java index 9954de5..4ea22f9 100644 --- a/media/java/android/media/session/MediaSessionLegacyHelper.java +++ b/media/java/android/media/session/MediaSessionLegacyHelper.java @@ -221,7 +221,7 @@ public class MediaSessionLegacyHelper { mSessionManager.dispatchAdjustVolume(AudioManager.USE_DEFAULT_STREAM_TYPE, direction, flags); } else if (isMute) { - if (down) { + if (down && keyEvent.getRepeatCount() == 0) { mSessionManager.dispatchAdjustVolume(AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.ADJUST_TOGGLE_MUTE, flags); } -- cgit v1.1