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
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
index 176e479..4f0aa89 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
@@ -308,19 +308,19 @@
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);
- mAudioManager = context.getSystemService(AudioManager.class);
- mExecutor = context.getMainExecutor();
- mCommunicationDeviceTracker = communicationDeviceTracker;
}
+ if (mFeatureFlags.useRefactoredAudioRouteSwitching()) {
+ mBluetoothHeadsetFuture = new CompletableFuture<>();
+ }
+ mAudioManager = context.getSystemService(AudioManager.class);
+ mExecutor = context.getMainExecutor();
+ mCommunicationDeviceTracker = communicationDeviceTracker;
}
public void setBluetoothRouteManager(BluetoothRouteManager brm) {