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

Commit b55fe920 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Fix NPE in BluetoothDeviceManager

The NPE was caused by a null check on mBluetoothAdapter in the constructor which skipped over the instantiation of mBluetoothHeadsetFuture. We should move the initialization of fields that aren't dependent on the adapter outside of the if block so that we don't run into other potential NPEs.

Bug: 380284503
Change-Id: I9a18630202af3ae4b329394d0cf688af71b90749
Flag: EXEMPT bugfix
Test: m Telecom
parent b0aeb39c
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -308,20 +308,20 @@ public class BluetoothDeviceManager {
        mFeatureFlags = featureFlags;
        if (bluetoothAdapter != null) {
            mBluetoothAdapter = bluetoothAdapter;
            if (mFeatureFlags.useRefactoredAudioRouteSwitching()) {
                mBluetoothHeadsetFuture = new CompletableFuture<>();
            }
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
                    BluetoothProfile.HEADSET);
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
                    BluetoothProfile.HEARING_AID);
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
                    BluetoothProfile.LE_AUDIO);
        }
        if (mFeatureFlags.useRefactoredAudioRouteSwitching()) {
            mBluetoothHeadsetFuture = new CompletableFuture<>();
        }
        mAudioManager = context.getSystemService(AudioManager.class);
        mExecutor = context.getMainExecutor();
        mCommunicationDeviceTracker = communicationDeviceTracker;
    }
    }

    public void setBluetoothRouteManager(BluetoothRouteManager brm) {
        mBluetoothRouteManager = brm;