Merge "[Audiosharing] Block pairing if there exists temp bond device" into main

This commit is contained in:
Yiyi Shen
2025-03-03 04:38:46 -08:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 4 deletions

View File

@@ -54,6 +54,7 @@ import com.android.settingslib.utils.ThreadUtils;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -315,11 +316,15 @@ public final class Utils {
CachedBluetoothDeviceManager deviceManager = localBtManager.getCachedDeviceManager();
List<BluetoothDevice> connectedDevices =
assistant == null ? ImmutableList.of() : assistant.getAllConnectedDevices();
Collection<CachedBluetoothDevice> bondedDevices =
deviceManager == null ? ImmutableList.of() : deviceManager.getCachedDevicesCopy();
// Block the pairing if there is ongoing audio sharing session and
// a) there is already one temp bond sink connected
// a) there is already one temp bond sink bonded
// or b) there are already two sinks joining the audio sharing
return assistant != null && deviceManager != null
&& (connectedDevices.stream().anyMatch(BluetoothUtils::isTemporaryBondDevice)
&& (bondedDevices.stream().anyMatch(
d -> BluetoothUtils.isTemporaryBondDevice(d.getDevice())
&& d.getBondState() == BluetoothDevice.BOND_BONDED)
|| connectedDevices.stream().filter(
d -> BluetoothUtils.hasActiveLocalBroadcastSourceForBtDevice(d,
localBtManager))