From a0d0c542b9ba92c08dbb00ed613bae133348937a Mon Sep 17 00:00:00 2001 From: Tomoharu Kasahara Date: Fri, 18 Jan 2019 20:04:38 +0900 Subject: [PATCH] Enable phone apps to mute the BLUETOOTH_SCO stream This change adds support for privileged apps with the MODIFY_PHONE_STATE permission to mute the bluetooth sco stream using the adjustStreamVolume method. The change adds specific handling for BLUETOOTH_SCO as a mutable stream. Bug: 111195322 Test: Mute works by AudioManager.adjustStreamVolume (STREAM_BLUETOOTH_SCO, ADJUST_MUTE, 0) Change-Id: I932f9e152e9b6df93a749b083a7bcc7e08c2ad70 --- media/java/android/media/AudioSystem.java | 3 ++- .../com/android/server/audio/AudioService.java | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 39f3b317d2100..e8a59603c02c7 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -1010,7 +1010,8 @@ public class AudioSystem (1 << STREAM_RING) | (1 << STREAM_NOTIFICATION) | (1 << STREAM_SYSTEM) | - (1 << STREAM_VOICE_CALL); + (1 << STREAM_VOICE_CALL) | + (1 << STREAM_BLUETOOTH_SCO); /** * Event posted by AudioTrack and AudioRecord JNI (JNIDeviceCallback) when routing changes. diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 6cc0e6153a33d..455a3e302480e 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -1163,11 +1163,13 @@ public class AudioService extends IAudioService.Stub private void checkMuteAffectedStreams() { // any stream with a min level > 0 is not muteable by definition - // STREAM_VOICE_CALL can be muted by applications that has the the MODIFY_PHONE_STATE permission. + // STREAM_VOICE_CALL and STREAM_BLUETOOTH_SCO can be muted by applications + // that has the the MODIFY_PHONE_STATE permission. for (int i = 0; i < mStreamStates.length; i++) { final VolumeStreamState vss = mStreamStates[i]; if (vss.mIndexMin > 0 && - vss.mStreamType != AudioSystem.STREAM_VOICE_CALL) { + (vss.mStreamType != AudioSystem.STREAM_VOICE_CALL && + vss.mStreamType != AudioSystem.STREAM_BLUETOOTH_SCO)) { mMuteAffectedStreams &= ~(1 << vss.mStreamType); } } @@ -1617,10 +1619,11 @@ public class AudioService extends IAudioService.Stub return; } - // If adjust is mute and the stream is STREAM_VOICE_CALL, make sure + // If adjust is mute and the stream is STREAM_VOICE_CALL or STREAM_BLUETOOTH_SCO, make sure // that the calling app have the MODIFY_PHONE_STATE permission. if (isMuteAdjust && - streamType == AudioSystem.STREAM_VOICE_CALL && + (streamType == AudioSystem.STREAM_VOICE_CALL || + streamType == AudioSystem.STREAM_BLUETOOTH_SCO) && mContext.checkCallingOrSelfPermission( android.Manifest.permission.MODIFY_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { @@ -1937,12 +1940,14 @@ public class AudioService extends IAudioService.Stub + " CHANGE_ACCESSIBILITY_VOLUME callingPackage=" + callingPackage); return; } - if ((streamType == AudioManager.STREAM_VOICE_CALL) && + if ((streamType == AudioManager.STREAM_VOICE_CALL || + streamType == AudioManager.STREAM_BLUETOOTH_SCO) && (index == 0) && (mContext.checkCallingOrSelfPermission( android.Manifest.permission.MODIFY_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)) { - Log.w(TAG, "Trying to call setStreamVolume() for STREAM_VOICE_CALL and index 0 without" + Log.w(TAG, "Trying to call setStreamVolume() for STREAM_VOICE_CALL or" + + " STREAM_BLUETOOTH_SCO and index 0 without" + " MODIFY_PHONE_STATE callingPackage=" + callingPackage); return; }