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

Commit d18a54d4 authored by jiangyou li's avatar jiangyou li Committed by Myles Watson
Browse files

Avoid a NullPointerException in getDevicesMatchingConnectionStates

In the method of getDevicesMatchingConnectionStates, use local variables repeat mAdapterService.
to avoid to mAdapterService is NullPointerException

Fixes:120749867
Test: manual
  1. Turn on Bluetooth and connect to the Bluetooth headset.
  2. Disconnect the connected Bluetooth headset from DUT and turn off Bluetooth.
  3. Repeat step 1 and step 2

Change-Id: I4afa346d937b2fca40c59d5985efdf384be1fc99
parent 914dfeec
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -220,7 +220,9 @@ public class HeadsetService extends ProfileService {
        mStateMachinesThread.quitSafely();
        mStateMachinesThread = null;
        // Step 1: Clear
        synchronized (mStateMachines) {
            mAdapterService = null;
        }
        return true;
    }

@@ -771,14 +773,14 @@ public class HeadsetService extends ProfileService {
    public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        ArrayList<BluetoothDevice> devices = new ArrayList<>();
        if (states == null) {
        synchronized (mStateMachines) {
            if (states == null || mAdapterService == null) {
                return devices;
            }
            final BluetoothDevice[] bondedDevices = mAdapterService.getBondedDevices();
            if (bondedDevices == null) {
                return devices;
            }
        synchronized (mStateMachines) {
            for (BluetoothDevice device : bondedDevices) {
                final ParcelUuid[] featureUuids = mAdapterService.getRemoteUuids(device);
                if (!BluetoothUuid.containsAnyUuid(featureUuids, HEADSET_UUIDS)) {