diff options
author | 2025-02-27 19:07:22 +0000 | |
---|---|---|
committer | 2025-02-27 15:46:41 -0800 | |
commit | 986b1903a1a0c2f81fe7dfa0afe102b39f7ce28d (patch) | |
tree | ba083ee210b7a89857bdb3581cbc2c2fee8f2e5c | |
parent | a08fe33a7cb22f71d40f2e1b0d31e32f0b123f2a (diff) |
[le audio broadcast] Avoid unexpected device activation when starting broadcast
Before starting broadcast session, current active device will be inactivated first. ActiveDeviceManager will set the other device to be active once the previous device is inactivated.
When broadcast is starting, we should avoid such unexpected device activation by checking both isBroadcastActive() -> broadcast active and isBroadcastReadyToBeReActivated() -> broadcast to be activated.
With this change, the sequence is
1. App requests to start broadcast with 2 group, A(active fallback) & B
2. Stack will set A to be inactive
3. ActiveDeviceManager check isBroadcastingAudio(), isBroadcastActive() -> false and isBroadcastReadyToBeReActivated() -> true, and skip switching active device to B
4. Once A is inactivated, LEA service will continue to start broadcast, isBroadcastActive() -> true.
Bug: 399677373
Flag: EXEMPT, trivial fix covered by unit tests
Test: atest ActiveDeviceManagerTest
Change-Id: I04a68a78743597030bab91fafa0890b3f5b6c78d
3 files changed, 14 insertions, 14 deletions
diff --git a/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java b/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java index 0669bc4ac2..95c6661be4 100644 --- a/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +++ b/android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java @@ -1368,7 +1368,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac return false; } - if (leAudioService.getAllBroadcastMetadata().isEmpty()) { + if (!leAudioService.isBroadcastStarted()) { Log.d(TAG, "isBroadcastingAudio: false - getAllBroadcastMetadata is empty"); return false; } diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java index 1bb21c562b..ebc84a9cbd 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java @@ -1565,6 +1565,15 @@ public class LeAudioService extends ProfileService { } /** + * Check if broadcast is active or ready to be re-activated + * + * @return true if there is active broadcast or ready to be re-activated, false otherwise + */ + public boolean isBroadcastStarted() { + return isBroadcastActive() || isBroadcastReadyToBeReActivated(); + } + + /** * Get the maximum number of supported simultaneous broadcasts. * * @return number of supported simultaneous broadcasts @@ -3146,10 +3155,6 @@ public class LeAudioService extends ProfileService { mHfpHandoverDevice = null; } - boolean isBroadcastStarted() { - return isBroadcastActive() || isBroadcastReadyToBeReActivated(); - } - /* Return true if Fallback Unicast Group For Broadcast is the given groupId and broadcast is * active or ready to be activated. */ diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java index 0dc5c6de3a..62fd253195 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java @@ -44,7 +44,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothSinkAudioPolicy; import android.content.Context; @@ -1757,8 +1756,7 @@ public class ActiveDeviceManagerTest { */ @Test public void a2dpConnectedWhenBroadcasting_notSetA2dpActive() { - final List<BluetoothLeBroadcastMetadata> metadataList = mock(List.class); - when(mLeAudioService.getAllBroadcastMetadata()).thenReturn(metadataList); + when(mLeAudioService.isBroadcastStarted()).thenReturn(true); a2dpConnected(mA2dpDevice, false); mTestLooper.dispatchAll(); verify(mA2dpService, never()).setActiveDevice(any()); @@ -1773,8 +1771,7 @@ public class ActiveDeviceManagerTest { */ @Test public void headsetConnectedWhenBroadcasting_notSetHeadsetActive() { - final List<BluetoothLeBroadcastMetadata> metadataList = mock(List.class); - when(mLeAudioService.getAllBroadcastMetadata()).thenReturn(metadataList); + when(mLeAudioService.isBroadcastStarted()).thenReturn(true); headsetConnected(mHeadsetDevice, false); mTestLooper.dispatchAll(); verify(mHeadsetService, never()).setActiveDevice(any()); @@ -1789,8 +1786,7 @@ public class ActiveDeviceManagerTest { */ @Test public void hearingAidConnectedWhenBroadcasting_notSetHearingAidActive() { - final List<BluetoothLeBroadcastMetadata> metadataList = mock(List.class); - when(mLeAudioService.getAllBroadcastMetadata()).thenReturn(metadataList); + when(mLeAudioService.isBroadcastStarted()).thenReturn(true); hearingAidConnected(mHearingAidDevice); mTestLooper.dispatchAll(); verify(mHearingAidService, never()).setActiveDevice(any()); @@ -1802,8 +1798,7 @@ public class ActiveDeviceManagerTest { */ @Test public void leHearingAidConnectedWhenBroadcasting_notSetLeHearingAidActive() { - final List<BluetoothLeBroadcastMetadata> metadataList = mock(List.class); - when(mLeAudioService.getAllBroadcastMetadata()).thenReturn(metadataList); + when(mLeAudioService.isBroadcastStarted()).thenReturn(true); leHearingAidConnected(mLeHearingAidDevice); mTestLooper.dispatchAll(); verify(mLeAudioService, never()).setActiveDevice(any()); |