From 5205a35f7805aec1285e1a17a8e6dcb0e49f7e33 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 27 Apr 2017 18:31:22 -0700 Subject: [PATCH] AudioService: fix missing AUDIO_BECOMING_NOISY intent If Bluetooth service calls onBluetoothA2dpDeviceConfigChange() before setBluetoothA2dpDeviceConnectionState(), there is a chance that the first method fails leaving the A2DP device state disconnected in audio policy manager while it appears as connected in AudioService causing a failure to send the AUDIO_BECOMING_NOISY intent. Bug: 37687852 Test: Verify AUDIO_BECOMING_NOISY intent is sent even if race condition occurs. Change-Id: I014d145e7da5e7d267991ffb2ff50626e71247eb --- .../java/com/android/server/audio/AudioService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index fff10e9c3ce1d..e2b838f74699d 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -5149,7 +5149,7 @@ public class AudioService extends IAudioService.Stub private void onBluetoothA2dpDeviceConfigChange(BluetoothDevice btDevice) { - if (DEBUG_VOL) { + if (DEBUG_DEVICES) { Log.d(TAG, "onBluetoothA2dpDeviceConfigChange btDevice=" + btDevice); } if (btDevice == null) { @@ -5166,8 +5166,13 @@ public class AudioService extends IAudioService.Stub final DeviceListSpec deviceSpec = mConnectedDevices.get(key); if (deviceSpec != null) { // Device is connected - AudioSystem.handleDeviceConfigChange(device, address, - btDevice.getName()); + if (AudioSystem.handleDeviceConfigChange(device, address, + btDevice.getName()) != AudioSystem.AUDIO_STATUS_OK) { + // force A2DP device disconnection in case of error so that AudioService state is + // consistent with audio policy manager state + setBluetoothA2dpDeviceConnectionState( + btDevice, BluetoothA2dp.STATE_DISCONNECTED, BluetoothProfile.A2DP_SINK); + } } } }