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

Commit 7ca8bddd authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

Do not return null as active device

getActiveDevices can return at most one device for A2DP. Some places
would check just the count, not the value, and treat null as active
device causing crashes later in code.

Bug: 222743223
Test: play music using LE Audio, ensure no crashes in A2DP code
Change-Id: I48d8e43945e75de0a230a61d09dd6e9f3a734772
parent 4024c5ee
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -860,6 +860,7 @@ public class AdapterService extends Service {
            errorLog(
                    "Cannot switch buffer size. The number of A2DP active devices is "
                            + activeDevices.size());
            return;
        }
        mA2dpService.switchCodecByBufferSize(activeDevices.get(0), isLowLatencyBufferSize);
    }
@@ -4100,16 +4101,22 @@ public class AdapterService extends Service {
                if (mHeadsetService == null) {
                    Log.e(TAG, "getActiveDevices: HeadsetService is null");
                } else {
                    activeDevices.add(mHeadsetService.getActiveDevice());
                    Log.i(TAG, "getActiveDevices: Headset device: " + activeDevices.get(0));
                    BluetoothDevice device = mHeadsetService.getActiveDevice();
                    if (device != null) {
                        activeDevices.add(device);
                    }
                    Log.i(TAG, "getActiveDevices: Headset device: " + device);
                }
                break;
            case BluetoothProfile.A2DP:
                if (mA2dpService == null) {
                    Log.e(TAG, "getActiveDevices: A2dpService is null");
                } else {
                    activeDevices.add(mA2dpService.getActiveDevice());
                    Log.i(TAG, "getActiveDevices: A2dp device: " + activeDevices.get(0));
                    BluetoothDevice device = mA2dpService.getActiveDevice();
                    if (device != null) {
                        activeDevices.add(device);
                    }
                    Log.i(TAG, "getActiveDevices: A2dp device: " + device);
                }
                break;
            case BluetoothProfile.HEARING_AID: