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

Commit a56d1c72 authored by Nick Pelly's avatar Nick Pelly
Browse files

Fix AudioService on HFP power off due to new Bluetooth API.

HEADSET_STATE_CHANGED_ACTION contains a null BluetoothDevice when the HFP
disconnects.
parent 77035a31
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -1391,11 +1391,15 @@ public class AudioService extends IAudioService.Stub {
            } else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) {
                int state = intent.getIntExtra(BluetoothIntent.HEADSET_STATE,
                                               BluetoothHeadset.STATE_ERROR);
                BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothIntent.DEVICE);
                String address = btDevice.getAddress();
                int device = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
                int btClass = btDevice.getBluetoothClass();
                if (BluetoothClass.Device.Major.getDeviceMajor(btClass) == BluetoothClass.Device.Major.AUDIO_VIDEO) {
                BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothIntent.DEVICE);
                String address = null;
                int btClass = BluetoothClass.ERROR;
                if (btDevice != null) {
                    address = btDevice.getAddress();
                    btClass = btDevice.getBluetoothClass();
                    if (BluetoothClass.Device.Major.getDeviceMajor(btClass) ==
                                BluetoothClass.Device.Major.AUDIO_VIDEO) {
                        switch (BluetoothClass.Device.getDevice(btClass)) {
                        case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
                        case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
@@ -1408,6 +1412,7 @@ public class AudioService extends IAudioService.Stub {
                            break;
                        }
                    }
                }

                boolean isConnected = (mConnectedDevices.containsKey(device) &&
                                       ((String)mConnectedDevices.get(device)).equals(address));