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

Commit 392b4812 authored by Yongqin Liu's avatar Yongqin Liu
Browse files

BluetoothDeviceManager.java: add null check before call mBluetoothAdapter.getActiveDevices



As the bluetoothAdapter might be null, we need to check first before
we call mBluetoothAdapter.getActiveDevices like before.
Otherwise we would get following crash errors when there is no bluetooth feature
with the platform.

    10-09 16:12:33.654   953   953 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: main
    10-09 16:12:33.654   953   953 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List android.bluetooth.BluetoothAdapter.getActiveDevices(int)' on a null object reference
    10-09 16:12:33.654   953   953 E AndroidRuntime:    at com.android.server.telecom.bluetooth.BluetoothDeviceManager.getUniqueConnectedDevices(BluetoothDeviceManager.java:160)
    10-09 16:12:33.654   953   953 E AndroidRuntime:    at com.android.server.telecom.bluetooth.BluetoothRouteManager.getConnectedDevices(BluetoothRouteManager.java:611)
    10-09 16:12:33.654   953   953 E AndroidRuntime:    at com.android.server.telecom.CallAudioRouteStateMachine.getInitialAudioState(CallAudioRouteStateMachine.java:1810)
    10-09 16:12:33.654   953   953 E AndroidRuntime:    at com.android.server.telecom.CallAudioRouteStateMachine.initialize(CallAudioRouteStateMachine.java:1524)
    10-09 16:12:33.654   953   953 E AndroidRuntime:    at com.android.server.telecom.CallsManager.<init>(CallsManager.java:524)
    10-09 16:12:33.654   953   953 E AndroidRuntime:    at com.android.server.telecom.TelecomSystem.<init>(TelecomSystem.java:322)

Test: boot tested with x15 build

Signed-off-by: default avatarYongqin Liu <yongqin.liu@linaro.org>
Change-Id: Ib42ba98211dc74dcc59fab8171e6a41795161334
parent 4dffc62f
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ public class BluetoothDeviceManager {
        Set<Long> seenHiSyncIds = new LinkedHashSet<>();
        // Add the left-most active device to the seen list so that we match up with the list
        // generated in BluetoothRouteManager.
        if (mBluetoothAdapter != null) {
            for (BluetoothDevice device : mBluetoothAdapter.getActiveDevices(
                        BluetoothProfile.HEARING_AID)) {
                if (device != null) {
@@ -165,6 +166,7 @@ public class BluetoothDeviceManager {
                    break;
                }
            }
        }
        synchronized (mLock) {
            for (BluetoothDevice d : mHearingAidDevicesByAddress.values()) {
                long hiSyncId = mHearingAidDeviceSyncIds.getOrDefault(d, -1L);
@@ -244,12 +246,14 @@ public class BluetoothDeviceManager {
    }

    public void disconnectAudio() {
        if (mBluetoothAdapter != null) {
            for (BluetoothDevice device: mBluetoothAdapter.getActiveDevices(
                        BluetoothProfile.HEARING_AID)) {
                if (device != null) {
                    mBluetoothAdapter.setActiveDevice(null, BluetoothAdapter.ACTIVE_DEVICE_ALL);
                }
            }
        }
        disconnectSco();
    }

@@ -295,6 +299,7 @@ public class BluetoothDeviceManager {
    }

    public void cacheHearingAidDevice() {
        if (mBluetoothAdapter != null) {
            for (BluetoothDevice device : mBluetoothAdapter.getActiveDevices(
                        BluetoothProfile.HEARING_AID)) {
                if (device != null) {
@@ -302,6 +307,7 @@ public class BluetoothDeviceManager {
                }
            }
        }
    }

    public void restoreHearingAidDevice() {
        if (mBluetoothHearingAidActiveDeviceCache != null) {