From 9a5b262330191ada5a9724f58272a82e97ad4ccd Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Tue, 18 Apr 2017 18:20:56 -0700 Subject: [PATCH] audio service: simplify becoming noisy intent logic Simplify and fix the logic deciding if AudioManager.ACTION_AUDIO_BECOMING_NOISY intent should be broadcast when a device is disconnected. Bug: 37308922 Test: verify music stops when disconnecting a wired or BT A2DP headset and it is the only device connected. Verify music doesn't stop when disconnecting a wired or BT A2DP headset and they are both connected. Change-Id: Iba5885697d37a2f3d23dfc013623e2fbec173998 --- .../android/server/audio/AudioService.java | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 268724283351a..bea2862c0fb74 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -5156,7 +5156,9 @@ public class AudioService extends IAudioService.Stub } // Devices which removal triggers intent ACTION_AUDIO_BECOMING_NOISY. The intent is only - // sent if none of these devices is connected. + // sent if: + // - none of these devices are connected anymore after one is disconnected AND + // - the device being disconnected is actually used for music. // Access synchronized on mConnectedDevices int mBecomingNoisyIntentDevices = AudioSystem.DEVICE_OUT_WIRED_HEADSET | AudioSystem.DEVICE_OUT_WIRED_HEADPHONE | @@ -5177,7 +5179,8 @@ public class AudioService extends IAudioService.Stub devices |= dev; } } - if (devices == device) { + int musicDevice = getDeviceForStream(AudioSystem.STREAM_MUSIC); + if ((device == musicDevice) && (device == devices)) { sendMsg(mAudioHandler, MSG_BROADCAST_AUDIO_BECOMING_NOISY, SENDMSG_REPLACE, @@ -5796,25 +5799,9 @@ public class AudioService extends IAudioService.Stub // Must be called synchronized on mConnectedDevices private void setForceUseInt_SyncDevices(int usage, int config) { - switch (usage) { - case AudioSystem.FOR_MEDIA: - if (config == AudioSystem.FORCE_NO_BT_A2DP) { - mBecomingNoisyIntentDevices &= ~AudioSystem.DEVICE_OUT_ALL_A2DP; - } else { // config == AudioSystem.FORCE_NONE - mBecomingNoisyIntentDevices |= AudioSystem.DEVICE_OUT_ALL_A2DP; - } - sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES, - SENDMSG_NOOP, 0, 0, null, 0); - break; - case AudioSystem.FOR_DOCK: - if (config == AudioSystem.FORCE_ANALOG_DOCK) { - mBecomingNoisyIntentDevices |= AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET; - } else { // config == AudioSystem.FORCE_NONE - mBecomingNoisyIntentDevices &= ~AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET; - } - break; - default: - // usage doesn't affect the broadcast of ACTION_AUDIO_BECOMING_NOISY + if (usage == AudioSystem.FOR_MEDIA) { + sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES, + SENDMSG_NOOP, 0, 0, null, 0); } AudioSystem.setForceUse(usage, config); }