summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-28 13:22:57 -0800
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2025-02-28 13:22:57 -0800
commit21e8ae7d77e09bed069ca58b5da06f53617b9ff5 (patch)
tree6379b34b8f4eee05f94170e5993e4806850b06dd
parentc808054f56f869dfedd8b1bed1f268ed837bc903 (diff)
parent986b1903a1a0c2f81fe7dfa0afe102b39f7ce28d (diff)
Merge "[le audio broadcast] Avoid unexpected device activation when starting broadcast" into main
-rw-r--r--android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java2
-rw-r--r--android/app/src/com/android/bluetooth/le_audio/LeAudioService.java13
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java13
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());