Loading src/com/android/settings/bluetooth/Utils.java +7 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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)) Loading tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java +10 −2 Original line number Diff line number Diff line Loading @@ -117,7 +117,9 @@ public class UtilsTest { when(mDeviceManager.findDevice(device)).thenReturn(cachedDevice); when(cachedDevice.getGroupId()).thenReturn(1); when(cachedDevice.getDevice()).thenReturn(device); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(device)); when(mDeviceManager.getCachedDevicesCopy()).thenReturn(ImmutableList.of(cachedDevice)); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); when(state.getBroadcastId()).thenReturn(1); when(mAssistant.getAllSources(device)).thenReturn(ImmutableList.of(state)); Loading @@ -133,9 +135,11 @@ public class UtilsTest { when(mDeviceManager.findDevice(device)).thenReturn(cachedDevice); when(cachedDevice.getGroupId()).thenReturn(1); when(cachedDevice.getDevice()).thenReturn(device); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(device)); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mDeviceManager.getCachedDevicesCopy()).thenReturn(ImmutableList.of(cachedDevice)); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); when(state.getBroadcastId()).thenReturn(1); when(state.getBroadcastId()).thenReturn(0); when(mAssistant.getAllSources(device)).thenReturn(ImmutableList.of(state)); when(device.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)) .thenReturn(TEMP_BOND_METADATA.getBytes()); Loading @@ -154,9 +158,13 @@ public class UtilsTest { when(mDeviceManager.findDevice(device2)).thenReturn(cachedDevice2); when(cachedDevice1.getGroupId()).thenReturn(1); when(cachedDevice2.getGroupId()).thenReturn(2); when(cachedDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice1.getDevice()).thenReturn(device1); when(cachedDevice2.getDevice()).thenReturn(device2); when(cachedDevice2.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(device1, device2)); when(mDeviceManager.getCachedDevicesCopy()).thenReturn( ImmutableList.of(cachedDevice1, cachedDevice2)); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); when(state.getBroadcastId()).thenReturn(1); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(state)); Loading Loading
src/com/android/settings/bluetooth/Utils.java +7 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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)) Loading
tests/robotests/src/com/android/settings/bluetooth/UtilsTest.java +10 −2 Original line number Diff line number Diff line Loading @@ -117,7 +117,9 @@ public class UtilsTest { when(mDeviceManager.findDevice(device)).thenReturn(cachedDevice); when(cachedDevice.getGroupId()).thenReturn(1); when(cachedDevice.getDevice()).thenReturn(device); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(device)); when(mDeviceManager.getCachedDevicesCopy()).thenReturn(ImmutableList.of(cachedDevice)); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); when(state.getBroadcastId()).thenReturn(1); when(mAssistant.getAllSources(device)).thenReturn(ImmutableList.of(state)); Loading @@ -133,9 +135,11 @@ public class UtilsTest { when(mDeviceManager.findDevice(device)).thenReturn(cachedDevice); when(cachedDevice.getGroupId()).thenReturn(1); when(cachedDevice.getDevice()).thenReturn(device); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(device)); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); when(mDeviceManager.getCachedDevicesCopy()).thenReturn(ImmutableList.of(cachedDevice)); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); when(state.getBroadcastId()).thenReturn(1); when(state.getBroadcastId()).thenReturn(0); when(mAssistant.getAllSources(device)).thenReturn(ImmutableList.of(state)); when(device.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)) .thenReturn(TEMP_BOND_METADATA.getBytes()); Loading @@ -154,9 +158,13 @@ public class UtilsTest { when(mDeviceManager.findDevice(device2)).thenReturn(cachedDevice2); when(cachedDevice1.getGroupId()).thenReturn(1); when(cachedDevice2.getGroupId()).thenReturn(2); when(cachedDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice1.getDevice()).thenReturn(device1); when(cachedDevice2.getDevice()).thenReturn(device2); when(cachedDevice2.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(device1, device2)); when(mDeviceManager.getCachedDevicesCopy()).thenReturn( ImmutableList.of(cachedDevice1, cachedDevice2)); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); when(state.getBroadcastId()).thenReturn(1); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(state)); Loading