CachedBluetoothDevice: Fix detecting connect fail am: f9da437a5f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2465935

Change-Id: If1af40f811dba7ca8d5eadbd61cb90f43a5b5e9d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Michał Narajowski
2023-03-07 10:09:18 +00:00
committed by Automerger Merge Worker

View File

@@ -208,7 +208,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
synchronized (mProfileLock) {
if (profile instanceof A2dpProfile || profile instanceof HeadsetProfile
|| profile instanceof HearingAidProfile) {
|| profile instanceof HearingAidProfile || profile instanceof LeAudioProfile) {
setProfileConnectedStatus(profile.getProfileId(), false);
switch (newProfileState) {
case BluetoothProfile.STATE_CONNECTED:
@@ -226,7 +226,20 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
case BluetoothProfile.STATE_DISCONNECTED:
if (mHandler.hasMessages(profile.getProfileId())) {
mHandler.removeMessages(profile.getProfileId());
setProfileConnectedStatus(profile.getProfileId(), true);
if (profile.getConnectionPolicy(mDevice) >
BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
/*
* If we received state DISCONNECTED and previous state was
* CONNECTING and connection policy is FORBIDDEN or UNKNOWN
* then it's not really a failure to connect.
*
* Connection profile is considered as failed when connection
* policy indicates that profile should be connected
* but it got disconnected.
*/
Log.w(TAG, "onProfileStateChanged(): Failed to connect profile");
setProfileConnectedStatus(profile.getProfileId(), true);
}
}
break;
default:
@@ -1194,6 +1207,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
}
private boolean isProfileConnectedFail() {
Log.d(TAG, "anonymizedAddress=" + mDevice.getAnonymizedAddress()
+ " mIsA2dpProfileConnectedFail=" + mIsA2dpProfileConnectedFail
+ " mIsHearingAidProfileConnectedFail=" + mIsHearingAidProfileConnectedFail
+ " mIsLeAudioProfileConnectedFail=" + mIsLeAudioProfileConnectedFail
+ " mIsHeadsetProfileConnectedFail=" + mIsHeadsetProfileConnectedFail
+ " isConnectedSapDevice()=" + isConnectedSapDevice());
return mIsA2dpProfileConnectedFail || mIsHearingAidProfileConnectedFail
|| (!isConnectedSapDevice() && mIsHeadsetProfileConnectedFail)
|| mIsLeAudioProfileConnectedFail;