From 14e56413217bedbf1ba011ef521316b91fb9fed2 Mon Sep 17 00:00:00 2001 From: Michał Narajowski Date: Thu, 2 Mar 2023 15:08:18 +0000 Subject: CachedBluetoothDevice: Add missing LeAudioProfile LeAudioProfile state changes were not handled and so we couldn't detect timeouts on this profile. Bug: 268587046 Test: BluetoothInstrumentationTest Change-Id: I492bfc970103a3235a2ec07ebea88016753507d9 --- .../src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/SettingsLib/src') diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index c8187b89b0ed..445e282c65a2 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -208,7 +208,7 @@ public class CachedBluetoothDevice implements Comparable 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: -- cgit v1.2.3-59-g8ed1b From f9da437a5fcb84346a12bd0fac8659cc8f5dab59 Mon Sep 17 00:00:00 2001 From: Michał Narajowski Date: Thu, 2 Mar 2023 15:09:23 +0000 Subject: 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 --- .../bluetooth/CachedBluetoothDevice.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'packages/SettingsLib/src') diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 445e282c65a2..8b2eebe8afe5 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -226,7 +226,20 @@ public class CachedBluetoothDevice implements Comparable 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: @@ -1188,6 +1201,13 @@ public class CachedBluetoothDevice implements Comparable } 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; -- cgit v1.2.3-59-g8ed1b