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

Commit 7477eed9 authored by Mallikarjuna GB's avatar Mallikarjuna GB Committed by Pavlin Radoslavov
Browse files

Properly update profile connection state

When DUT is toggled between various paired Headsets Connection
state is not updated properly in some scenarios. This is causing
Bluetooth icon to be in connected state even when no Headsets are
connected.

With this patch we will broadcast connection states in case of
failure and will make sure connected, connecting, disconnecting
devices count is never negative.

Test: Toggle between various paired devices in settings
Bug: 35657640
Change-Id: Icb1a7215ff6d9491afbb5f7f203ca0a2c6b7f43a
(cherry picked from commit 921e34fc7ffd18b4f831bbcf0cf38e7268a00613)
parent 8499f61c
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -625,6 +625,10 @@ final class A2dpStateMachine extends StateMachine {
                        broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                                       BluetoothProfile.STATE_CONNECTING);
                        break;
                    } else {
                        broadcastConnectionState(mCurrentDevice,
                                BluetoothProfile.STATE_DISCONNECTING,
                                BluetoothProfile.STATE_CONNECTED);
                    }

                    synchronized (A2dpStateMachine.this) {
@@ -643,7 +647,7 @@ final class A2dpStateMachine extends StateMachine {
                                   BluetoothProfile.STATE_CONNECTED);
                    if (!disconnectA2dpNative(getByteAddress(device))) {
                        broadcastConnectionState(device, BluetoothProfile.STATE_CONNECTED,
                                       BluetoothProfile.STATE_DISCONNECTED);
                                BluetoothProfile.STATE_DISCONNECTING);
                        break;
                    }
                    synchronized (A2dpStateMachine.this) {
+12 −3
Original line number Diff line number Diff line
@@ -503,15 +503,24 @@ class AdapterProperties {
    private boolean updateCountersAndCheckForConnectionStateChange(int state, int prevState) {
        switch (prevState) {
            case BluetoothProfile.STATE_CONNECTING:
                if (mProfilesConnecting > 0)
                    mProfilesConnecting--;
                else
                    Log.e(TAG, "mProfilesConnecting " + mProfilesConnecting);
                break;

            case BluetoothProfile.STATE_CONNECTED:
                if (mProfilesConnected > 0)
                    mProfilesConnected--;
                else
                    Log.e(TAG, "mProfilesConnected " + mProfilesConnected);
                break;

            case BluetoothProfile.STATE_DISCONNECTING:
                if (mProfilesDisconnecting > 0)
                    mProfilesDisconnecting--;
                else
                    Log.e(TAG, "mProfilesDisconnecting " + mProfilesDisconnecting);
                break;
        }

+4 −0
Original line number Diff line number Diff line
@@ -753,6 +753,10 @@ final class HeadsetStateMachine extends StateMachine {
                    if (mConnectedDevicesList.contains(device)) {
                        Log.w(TAG, "Connected: CONNECT, device " + device + " is connected");
                        break;
                    } else {
                        broadcastConnectionState(mCurrentDevice,
                                BluetoothProfile.STATE_DISCONNECTING,
                                BluetoothProfile.STATE_CONNECTED);
                    }
                    if (mConnectedDevicesList.size() >= max_hf_connections) {
                        BluetoothDevice DisconnectConnectedDevice = null;