Skip to content

Commit 1b10472

Browse files
Treehugger RobotGerrit Code Review
Treehugger Robot
authored and
Gerrit Code Review
committed
Merge "BtHelper: handle BT crash" into main
2 parents 8dcf47d + 150ddfa commit 1b10472

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)