Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40b644d2 authored by Michał Narajowski's avatar Michał Narajowski Committed by Automerger Merge Worker
Browse files

CachedBluetoothDevice: Fix detecting connect fail am: f9da437a am: 2dbeb96d am: 674de094

parents 134b8a89 674de094
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -210,7 +210,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:
@@ -228,8 +228,21 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                    case BluetoothProfile.STATE_DISCONNECTED:
                        if (mHandler.hasMessages(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);
                            }
                        }
                        break;
                    default:
                        Log.w(TAG, "onProfileStateChanged(): unknown profile state : "
@@ -1205,6 +1218,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;