[Audiosharing] Avoid fallback device update when onSourceRemoved.
Also check if there is playing broadcast before updating the fallback.
Updating fallback device during call audio will hit race condition in
broadcast-unicast switching. Considering there is no use case for
removing source in current product, we will disable fallback device
update when onSourceRemoved.
Bug: 329003470
Test: manual
Change-Id: I3038d2ecff91c26cf1b2fbda44476c8a8e31f4dd
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
index 030fd54..a1d3144 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
@@ -336,7 +336,6 @@
+ ", sourceId = "
+ sourceId);
}
- updateFallbackActiveDeviceIfNeeded();
}
@Override
@@ -468,6 +467,15 @@
mServiceBroadcast.startBroadcast(settings);
}
+ /** Checks if the broadcast is playing. */
+ public boolean isPlaying(int broadcastId) {
+ if (mServiceBroadcast == null) {
+ Log.d(TAG, "check isPlaying failed, the BluetoothLeBroadcast is null.");
+ return false;
+ }
+ return mServiceBroadcast.isPlaying(broadcastId);
+ }
+
private BluetoothLeBroadcastSettings buildBroadcastSettings(
boolean isPublic,
@Nullable String broadcastName,
@@ -1025,6 +1033,16 @@
/** Update fallback active device if needed. */
public void updateFallbackActiveDeviceIfNeeded() {
+ if (mServiceBroadcast == null) {
+ Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to broadcast profile is null");
+ return;
+ }
+ List<BluetoothLeBroadcastMetadata> sources = mServiceBroadcast.getAllBroadcastMetadata();
+ if (sources.stream()
+ .noneMatch(source -> mServiceBroadcast.isPlaying(source.getBroadcastId()))) {
+ Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to no broadcast ongoing");
+ return;
+ }
if (mServiceBroadcastAssistant == null) {
Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to assistant profile is null");
return;