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

Commit 20b0acf2 authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Fix crash in AdapterService#disconnectAudio due to

ArrayIndexOutOfBoundsException

Tag: #feature
Bug: 214496804
Test: Manual
Ignore-AOSP-First: Change dependent on prebuilts for SDK 33
Change-Id: I76185f21538e38b719b649399af5e15795a34c24
parent 395cb85e
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -1474,12 +1474,20 @@ public class HeadsetService extends ProfileService {
    }

    int disconnectAudio() {
        int disconnectResult = BluetoothStatusCodes.ERROR_NO_ACTIVE_DEVICES;
        synchronized (mStateMachines) {
            List<BluetoothDevice> activeAudioDevices = getNonIdleAudioDevices();
            BluetoothDevice activeAudioDevice =
                    activeAudioDevices.get(activeAudioDevices.size() - 1);
            return disconnectAudio(activeAudioDevice);
            for (BluetoothDevice device : getNonIdleAudioDevices()) {
                disconnectResult = disconnectAudio(device);
                if (disconnectResult == BluetoothStatusCodes.SUCCESS) {
                    return disconnectResult;
                } else {
                    Log.e(TAG, "disconnectAudio() from " + device + " failed with status code "
                            + disconnectResult);
                }
            }
        }
        logD("disconnectAudio() no active audio connection");
        return disconnectResult;
    }

    int disconnectAudio(BluetoothDevice device) {