CachedBluetoothDevice: Fix detecting connect fail
Transition from CONNECTING to DISCONNECTED doesn't have to mean that the connection has failed. Add check to verify that connection policy for profile is ALLOWED and only then trigger connection failed. Setting connection failed results in "Problem connecting." in Bluetooth connected devices UI. Bug: 268587046 Test: BluetoothInstrumentationTest Change-Id: I1eb116e4ae1735fafe3d7f35fc0bf51d21cb87d3
This commit is contained in:
@@ -226,8 +226,21 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
case BluetoothProfile.STATE_DISCONNECTED:
|
case BluetoothProfile.STATE_DISCONNECTED:
|
||||||
if (mHandler.hasMessages(profile.getProfileId())) {
|
if (mHandler.hasMessages(profile.getProfileId())) {
|
||||||
mHandler.removeMessages(profile.getProfileId());
|
mHandler.removeMessages(profile.getProfileId());
|
||||||
|
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);
|
setProfileConnectedStatus(profile.getProfileId(), true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.w(TAG, "onProfileStateChanged(): unknown profile state : "
|
Log.w(TAG, "onProfileStateChanged(): unknown profile state : "
|
||||||
@@ -1188,6 +1201,13 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isProfileConnectedFail() {
|
private boolean isProfileConnectedFail() {
|
||||||
|
Log.d(TAG, "anonymizedAddress=" + mDevice.getAnonymizedAddress()
|
||||||
|
+ " mIsA2dpProfileConnectedFail=" + mIsA2dpProfileConnectedFail
|
||||||
|
+ " mIsHearingAidProfileConnectedFail=" + mIsHearingAidProfileConnectedFail
|
||||||
|
+ " mIsLeAudioProfileConnectedFail=" + mIsLeAudioProfileConnectedFail
|
||||||
|
+ " mIsHeadsetProfileConnectedFail=" + mIsHeadsetProfileConnectedFail
|
||||||
|
+ " isConnectedSapDevice()=" + isConnectedSapDevice());
|
||||||
|
|
||||||
return mIsA2dpProfileConnectedFail || mIsHearingAidProfileConnectedFail
|
return mIsA2dpProfileConnectedFail || mIsHearingAidProfileConnectedFail
|
||||||
|| (!isConnectedSapDevice() && mIsHeadsetProfileConnectedFail)
|
|| (!isConnectedSapDevice() && mIsHeadsetProfileConnectedFail)
|
||||||
|| mIsLeAudioProfileConnectedFail;
|
|| mIsLeAudioProfileConnectedFail;
|
||||||
|
|||||||
Reference in New Issue
Block a user