Fix crash prone code in BluetoothDeviceManager.
Bug: 237751446
Bug: 240215018
Test: BluetoothDeviceManagerTest
Merged-In: I722dded7744759f4485407d5f12e3a57d23b5fbf
Change-Id: I722dded7744759f4485407d5f12e3a57d23b5fbf
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
index 58c74fc..627fa44 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
@@ -27,6 +27,7 @@
import android.content.Context;
import android.media.AudioManager;
import android.media.AudioDeviceInfo;
+import android.media.audio.common.AudioDevice;
import android.telecom.Log;
import android.util.LocalLog;
@@ -425,8 +426,9 @@
Log.i(this, "clearLeAudioCommunicationDevice: mAudioManager is null");
return;
}
- if (mAudioManager.getCommunicationDevice() != null
- && mAudioManager.getCommunicationDevice().getType()
+
+ AudioDeviceInfo audioDeviceInfo = mAudioManager.getCommunicationDevice();
+ if (audioDeviceInfo != null && audioDeviceInfo.getType()
== AudioDeviceInfo.TYPE_BLE_HEADSET) {
mBluetoothRouteManager.onAudioLost(mAudioManager.getCommunicationDevice().getAddress());
mAudioManager.clearCommunicationDevice();
@@ -442,8 +444,9 @@
Log.i(this, "clearHearingAidCommunicationDevice: mAudioManager is null");
return;
}
- if (mAudioManager.getCommunicationDevice() != null
- && mAudioManager.getCommunicationDevice().getType()
+
+ AudioDeviceInfo audioDeviceInfo = mAudioManager.getCommunicationDevice();
+ if (audioDeviceInfo != null && audioDeviceInfo.getType()
== AudioDeviceInfo.TYPE_HEARING_AID) {
mAudioManager.clearCommunicationDevice();
}