From e168a3f0eb804cd8fd9c6c7bf981754b2d11dd46 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 19 Dec 2019 11:32:44 -0800 Subject: [PATCH] AudioService: fix A2DP disconnection / reconnection Fix issue introduced by commit d32a94d where in case of an A2DP disconnection, the device was disconnected then reconnected. Bug: 146544156 Test: disconnect A2DP device, check it's not listed in dumpsys media.audio_policy Change-Id: Ic5f9387194d92a7a050e7a295a13a9ae18cd96ce --- .../server/audio/AudioDeviceInventory.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index 135f199d88be1..4a5a212322469 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -195,15 +195,17 @@ public class AudioDeviceInventory { } else { makeA2dpDeviceUnavailableNow(address, di.mDeviceCodecFormat); } + } else if (state == BluetoothProfile.STATE_CONNECTED) { + // device is not already connected + if (a2dpVolume != -1) { + mDeviceBroker.postSetVolumeIndexOnDevice(AudioSystem.STREAM_MUSIC, + // convert index to internal representation in VolumeStreamState + a2dpVolume * 10, + AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, "onSetA2dpSinkConnectionState"); + } + makeA2dpDeviceAvailable(address, BtHelper.getName(btDevice), + "onSetA2dpSinkConnectionState", a2dpCodec); } - if (a2dpVolume != -1) { - mDeviceBroker.postSetVolumeIndexOnDevice(AudioSystem.STREAM_MUSIC, - // convert index to internal representation in VolumeStreamState - a2dpVolume * 10, - AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, "onSetA2dpSinkConnectionState"); - } - makeA2dpDeviceAvailable(address, BtHelper.getName(btDevice), - "onSetA2dpSinkConnectionState", a2dpCodec); } }