Loading src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +12 −24 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; public class BluetoothDeviceManager { Loading Loading @@ -168,8 +169,15 @@ public class BluetoothDeviceManager { private List<BluetoothDevice> getLeAudioConnectedDevices() { synchronized (mLock) { // Filter out disconnected devices and/or those that have no group assigned ArrayList<BluetoothDevice> devices = new ArrayList<>(mGroupsByDevice.keySet()); // Let's get devices which are a group leaders ArrayList<BluetoothDevice> devices = new ArrayList<>(); for (LinkedHashMap.Entry<BluetoothDevice, Integer> entry : mGroupsByDevice.entrySet()) { if (Objects.equals(entry.getKey(), mBluetoothLeAudioService.getConnectedGroupLeadDevice(entry.getValue()))) { devices.add(entry.getKey()); } } devices.removeIf(device -> !mLeAudioDevicesByAddress.containsValue(device)); return devices; } Loading Loading @@ -223,28 +231,8 @@ public class BluetoothDeviceManager { } } Set<Integer> seenGroupIds = new LinkedHashSet<>(); if (mBluetoothAdapter != null) { for (BluetoothDevice device : mBluetoothAdapter.getActiveDevices( BluetoothProfile.LE_AUDIO)) { if (device != null) { result.add(device); seenGroupIds.add(mGroupsByDevice.getOrDefault(device, -1)); break; } } } synchronized (mLock) { for (BluetoothDevice d : getLeAudioConnectedDevices()) { int groupId = mGroupsByDevice.getOrDefault(d, BluetoothLeAudio.GROUP_ID_INVALID); if (groupId == BluetoothLeAudio.GROUP_ID_INVALID || seenGroupIds.contains(groupId)) { continue; } result.add(d); seenGroupIds.add(groupId); } if (mBluetoothLeAudioService != null) { result.addAll(getLeAudioConnectedDevices()); } return Collections.unmodifiableCollection(result); Loading tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +5 −1 Original line number Diff line number Diff line Loading @@ -164,6 +164,8 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); receiverUnderTest.onReceive(mContext, buildGroupNodeStatusChangedIntent(1, device5, BluetoothLeAudio.GROUP_NODE_ADDED)); when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device5); receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_DISCONNECTED, device1, BluetoothDeviceManager.DEVICE_TYPE_HEADSET)); Loading @@ -172,6 +174,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); receiverUnderTest.onReceive(mContext, buildGroupNodeStatusChangedIntent(2, device6, BluetoothLeAudio.GROUP_NODE_ADDED)); when(mBluetoothLeAudio.getConnectedGroupLeadDevice(2)).thenReturn(device6); receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device3, BluetoothDeviceManager.DEVICE_TYPE_HEADSET)); Loading Loading @@ -220,7 +223,8 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); receiverUnderTest.onReceive(mContext, buildGroupNodeStatusChangedIntent(1, device6, BluetoothLeAudio.GROUP_NODE_ADDED)); assertEquals(3, mBluetoothDeviceManager.getNumConnectedDevices()); when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device5); assertEquals(2, mBluetoothDeviceManager.getNumConnectedDevices()); assertEquals(2, mBluetoothDeviceManager.getUniqueConnectedDevices().size()); } Loading Loading
src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +12 −24 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; public class BluetoothDeviceManager { Loading Loading @@ -168,8 +169,15 @@ public class BluetoothDeviceManager { private List<BluetoothDevice> getLeAudioConnectedDevices() { synchronized (mLock) { // Filter out disconnected devices and/or those that have no group assigned ArrayList<BluetoothDevice> devices = new ArrayList<>(mGroupsByDevice.keySet()); // Let's get devices which are a group leaders ArrayList<BluetoothDevice> devices = new ArrayList<>(); for (LinkedHashMap.Entry<BluetoothDevice, Integer> entry : mGroupsByDevice.entrySet()) { if (Objects.equals(entry.getKey(), mBluetoothLeAudioService.getConnectedGroupLeadDevice(entry.getValue()))) { devices.add(entry.getKey()); } } devices.removeIf(device -> !mLeAudioDevicesByAddress.containsValue(device)); return devices; } Loading Loading @@ -223,28 +231,8 @@ public class BluetoothDeviceManager { } } Set<Integer> seenGroupIds = new LinkedHashSet<>(); if (mBluetoothAdapter != null) { for (BluetoothDevice device : mBluetoothAdapter.getActiveDevices( BluetoothProfile.LE_AUDIO)) { if (device != null) { result.add(device); seenGroupIds.add(mGroupsByDevice.getOrDefault(device, -1)); break; } } } synchronized (mLock) { for (BluetoothDevice d : getLeAudioConnectedDevices()) { int groupId = mGroupsByDevice.getOrDefault(d, BluetoothLeAudio.GROUP_ID_INVALID); if (groupId == BluetoothLeAudio.GROUP_ID_INVALID || seenGroupIds.contains(groupId)) { continue; } result.add(d); seenGroupIds.add(groupId); } if (mBluetoothLeAudioService != null) { result.addAll(getLeAudioConnectedDevices()); } return Collections.unmodifiableCollection(result); Loading
tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +5 −1 Original line number Diff line number Diff line Loading @@ -164,6 +164,8 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); receiverUnderTest.onReceive(mContext, buildGroupNodeStatusChangedIntent(1, device5, BluetoothLeAudio.GROUP_NODE_ADDED)); when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device5); receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_DISCONNECTED, device1, BluetoothDeviceManager.DEVICE_TYPE_HEADSET)); Loading @@ -172,6 +174,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); receiverUnderTest.onReceive(mContext, buildGroupNodeStatusChangedIntent(2, device6, BluetoothLeAudio.GROUP_NODE_ADDED)); when(mBluetoothLeAudio.getConnectedGroupLeadDevice(2)).thenReturn(device6); receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device3, BluetoothDeviceManager.DEVICE_TYPE_HEADSET)); Loading Loading @@ -220,7 +223,8 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO)); receiverUnderTest.onReceive(mContext, buildGroupNodeStatusChangedIntent(1, device6, BluetoothLeAudio.GROUP_NODE_ADDED)); assertEquals(3, mBluetoothDeviceManager.getNumConnectedDevices()); when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device5); assertEquals(2, mBluetoothDeviceManager.getNumConnectedDevices()); assertEquals(2, mBluetoothDeviceManager.getUniqueConnectedDevices().size()); } Loading