summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src
diff options
context:
space:
mode:
author Yiyi Shen <yiyishen@google.com> 2025-03-20 15:08:33 +0800
committer Yiyi Shen <yiyishen@google.com> 2025-03-20 15:52:17 +0800
commit11a0ee96606234ece4ca046a92b38207d1046148 (patch)
tree34634cb8e635332b275ccb1d5f34ac2f01b4b183 /packages/SettingsLib/src
parentdaa6e12a0b1e75c28cdb26870167cce7fc9c9267 (diff)
[Audiosharing] Remove source for sinks disconnected/unpaired from Settings
Test: atest Bug: 404299137 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I4c0e5e23ea16676062eff4bf6e618ff7c58afaaf
Diffstat (limited to 'packages/SettingsLib/src')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
index e81c8220d707..78b307e7b816 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -25,6 +25,7 @@ import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHearingAid;
+import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.content.Context;
@@ -58,6 +59,7 @@ import com.android.settingslib.flags.Flags;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.AdaptiveOutlineDrawable;
+import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -397,6 +399,9 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
}
}
Log.d(TAG, "Disconnect " + this);
+ if (Flags.enableLeAudioSharing()) {
+ removeBroadcastSource(ImmutableSet.of(mDevice));
+ }
mDevice.disconnect();
}
// Disconnect PBAP server in case its connected
@@ -609,6 +614,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
final BluetoothDevice dev = mDevice;
if (dev != null) {
mUnpairing = true;
+ if (Flags.enableLeAudioSharing()) {
+ Set<BluetoothDevice> devicesToRemoveSource = new HashSet<>();
+ devicesToRemoveSource.add(dev);
+ if (getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
+ for (CachedBluetoothDevice member : getMemberDevice()) {
+ devicesToRemoveSource.add(member.getDevice());
+ }
+ }
+ removeBroadcastSource(devicesToRemoveSource);
+ }
final boolean successful = dev.removeBond();
if (successful) {
releaseLruCache();
@@ -623,6 +638,25 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
}
}
+ @WorkerThread
+ private void removeBroadcastSource(Set<BluetoothDevice> devices) {
+ if (mProfileManager == null || devices.isEmpty()) return;
+ LocalBluetoothLeBroadcast broadcast = mProfileManager.getLeAudioBroadcastProfile();
+ LocalBluetoothLeBroadcastAssistant assistant =
+ mProfileManager.getLeAudioBroadcastAssistantProfile();
+ if (broadcast != null && assistant != null && broadcast.isEnabled(null)) {
+ for (BluetoothDevice device : devices) {
+ for (BluetoothLeBroadcastReceiveState state : assistant.getAllSources(device)) {
+ if (BluetoothUtils.D) {
+ Log.d(TAG, "Remove broadcast source " + state.getBroadcastId()
+ + " from device " + device.getAnonymizedAddress());
+ }
+ assistant.removeSource(device, state.getSourceId());
+ }
+ }
+ }
+ }
+
public int getProfileConnectionState(LocalBluetoothProfile profile) {
return profile != null
? profile.getConnectionStatus(mDevice)