Skip to content

Commit 150ddfa

Browse files
author
yaoliang1
committed
BtHelper: handle BT crash
Wrapped the calls to the BT proxies with try/catch as the notification that a profile disconnected can happen while the proxy is used Bug:351925855 Test: BT crash case in bug Change-Id: Ied1c5e064c25153c263869c61125a227f9c4a2b8 Signed-off-by: yaoliang1 <yaoliang1@xiaomi.com>
1 parent d2a053e commit 150ddfa

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

services/core/java/com/android/server/audio/BtHelper.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,13 @@ && connectBluetoothScoAudioHelper(mBluetoothHeadset,
436436
if (mBluetoothHeadset == null || mBluetoothHeadsetDevice == null) {
437437
return false;
438438
}
439-
return mBluetoothHeadset.getAudioState(mBluetoothHeadsetDevice)
440-
== BluetoothHeadset.STATE_AUDIO_CONNECTED;
439+
try {
440+
return mBluetoothHeadset.getAudioState(mBluetoothHeadsetDevice)
441+
== BluetoothHeadset.STATE_AUDIO_CONNECTED;
442+
} catch (Exception e) {
443+
Log.e(TAG, "Exception while getting audio state of " + mBluetoothHeadsetDevice, e);
444+
}
445+
return false;
441446
}
442447

443448
// @GuardedBy("mDeviceBroker.mSetModeLock")
@@ -1051,12 +1056,16 @@ private static boolean connectBluetoothScoAudioHelper(BluetoothHeadset bluetooth
10511056
}
10521057

10531058
private void checkScoAudioState() {
1054-
if (mBluetoothHeadset != null
1055-
&& mBluetoothHeadsetDevice != null
1056-
&& mScoAudioState == SCO_STATE_INACTIVE
1057-
&& mBluetoothHeadset.getAudioState(mBluetoothHeadsetDevice)
1058-
!= BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
1059-
mScoAudioState = SCO_STATE_ACTIVE_EXTERNAL;
1059+
try {
1060+
if (mBluetoothHeadset != null
1061+
&& mBluetoothHeadsetDevice != null
1062+
&& mScoAudioState == SCO_STATE_INACTIVE
1063+
&& mBluetoothHeadset.getAudioState(mBluetoothHeadsetDevice)
1064+
!= BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
1065+
mScoAudioState = SCO_STATE_ACTIVE_EXTERNAL;
1066+
}
1067+
} catch (Exception e) {
1068+
Log.e(TAG, "Exception while getting audio state of " + mBluetoothHeadsetDevice, e);
10601069
}
10611070
}
10621071

0 commit comments

Comments
 (0)