From 12ceada15124ae0240b1f854c69639dbc0c11c7a Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 8 Jun 2023 18:44:20 +0200 Subject: [PATCH] AudioDeviceInventory: do not clear a2dp/Le suspend on device connection Only clear the internal LE/A2DP suspend state when a device is connected but leave external suspend state received from the BT stack. This avoids temporarily resetting The suspended state when the A2DP profile is connected after the HFP profile and SCO audio is already active. Bug: 282992099 Test: repro steps in bug Change-Id: Id28a96641e7d23938ce1635aca03c533b91a2efb --- .../android/server/audio/AudioDeviceBroker.java | 16 ++++++++++------ .../server/audio/AudioDeviceInventory.java | 4 ++-- .../com/android/server/audio/AudioService.java | 1 - .../java/com/android/server/audio/BtHelper.java | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index fc72a771fa9c4..29a19417b8fdb 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -1018,13 +1018,15 @@ import java.util.concurrent.atomic.AtomicBoolean; } } - /*package*/ void clearA2dpSuspended() { + /*package*/ void clearA2dpSuspended(boolean internalOnly) { if (AudioService.DEBUG_COMM_RTE) { - Log.v(TAG, "clearA2dpSuspended"); + Log.v(TAG, "clearA2dpSuspended, internalOnly: " + internalOnly); } synchronized (mBluetoothAudioStateLock) { mBluetoothA2dpSuspendedInt = false; - mBluetoothA2dpSuspendedExt = false; + if (!internalOnly) { + mBluetoothA2dpSuspendedExt = false; + } updateAudioHalBluetoothState(); } } @@ -1046,13 +1048,15 @@ import java.util.concurrent.atomic.AtomicBoolean; } } - /*package*/ void clearLeAudioSuspended() { + /*package*/ void clearLeAudioSuspended(boolean internalOnly) { if (AudioService.DEBUG_COMM_RTE) { - Log.v(TAG, "clearLeAudioSuspended"); + Log.v(TAG, "clearLeAudioSuspended, internalOnly: " + internalOnly); } synchronized (mBluetoothAudioStateLock) { mBluetoothLeSuspendedInt = false; - mBluetoothLeSuspendedExt = false; + if (!internalOnly) { + mBluetoothLeSuspendedExt = false; + } updateAudioHalBluetoothState(); } } diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index 219dda398ebfc..ec85d577a8e7d 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -1547,7 +1547,7 @@ public class AudioDeviceInventory { } // Reset A2DP suspend state each time a new sink is connected - mDeviceBroker.clearA2dpSuspended(); + mDeviceBroker.clearA2dpSuspended(true /* internalOnly */); // The convention for head tracking sensors associated with A2DP devices is to // use a UUID derived from the MAC address as follows: @@ -1970,7 +1970,7 @@ public class AudioDeviceInventory { "LE Audio device addr=" + address + " now available").printLog(TAG)); } // Reset LEA suspend state each time a new sink is connected - mDeviceBroker.clearLeAudioSuspended(); + mDeviceBroker.clearLeAudioSuspended(true /* internalOnly */); UUID sensorUuid = UuidUtils.uuidFromAudioDeviceAttributes(ada); mConnectedDevices.put(DeviceInfo.makeDeviceListKey(device, address), diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index ac03c82260f96..c177c4efb5ef3 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -353,7 +353,6 @@ public class AudioService extends IAudioService.Stub private static final int MSG_PLAY_SOUND_EFFECT = 5; private static final int MSG_LOAD_SOUND_EFFECTS = 7; private static final int MSG_SET_FORCE_USE = 8; - private static final int MSG_BT_HEADSET_CNCT_FAILED = 9; private static final int MSG_SET_ALL_VOLUMES = 10; private static final int MSG_UNLOAD_SOUND_EFFECTS = 15; private static final int MSG_SYSTEM_READY = 16; diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java index e46c3cc4a2853..c8a17e5eea5a4 100644 --- a/services/core/java/com/android/server/audio/BtHelper.java +++ b/services/core/java/com/android/server/audio/BtHelper.java @@ -445,8 +445,8 @@ public class BtHelper { /*package*/ synchronized void resetBluetoothSco() { mScoAudioState = SCO_STATE_INACTIVE; broadcastScoConnectionState(AudioManager.SCO_AUDIO_STATE_DISCONNECTED); - mDeviceBroker.clearA2dpSuspended(); - mDeviceBroker.clearLeAudioSuspended(); + mDeviceBroker.clearA2dpSuspended(false /* internalOnly */); + mDeviceBroker.clearLeAudioSuspended(false /* internalOnly */); mDeviceBroker.setBluetoothScoOn(false, "resetBluetoothSco"); }