Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf860e6f authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

BluetoothLeAudio: Return early from getLeAudioConnectedDevices

If LeAudio is not supported or there is no known groups, function can
return early.

It also fixes flake testLeAudioServiceDisconnect() test:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.bluetooth.BluetoothDevice android.bluetooth.BluetoothLeAudio.getConnectedGroupLeadDevice(int)' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'android.bluetooth.BluetoothDevice android.bluetooth.BluetoothLeAudio.getConnectedGroupLeadDevice(int)' on a null object reference
	at com.android.server.telecom.bluetooth.BluetoothDeviceManager.getLeAudioConnectedDevices(BluetoothDeviceManager.java:219)
	at com.android.server.telecom.bluetooth.BluetoothDeviceManager.getNumConnectedDevices(BluetoothDeviceManager.java:232)
	at com.android.server.telecom.tests.BluetoothDeviceManagerTest.testLeAudioServiceDisconnect(BluetoothDeviceManagerTest.java:299)

Bug: 150670922
Test: atest TelecomUnitTest
Change-Id: Ic27732771a7e87d5b5a87584f50996cf3fd97b48
parent e97e5593
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -214,6 +214,10 @@ public class BluetoothDeviceManager {
            // Let's get devices which are a group leaders
            ArrayList<BluetoothDevice> devices = new ArrayList<>();

            if (mGroupsByDevice.isEmpty() || mBluetoothLeAudioService == null) {
                return devices;
            }

            for (LinkedHashMap.Entry<BluetoothDevice, Integer> entry : mGroupsByDevice.entrySet()) {
               if (Objects.equals(entry.getKey(),
                        mBluetoothLeAudioService.getConnectedGroupLeadDevice(entry.getValue()))) {