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

Commit 6ec66047 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

BASS: Fix unable to disconnect from settings

Intentional disconnect does not mean changing the connection policy.
We need an additional flag to distinct the intentional disconnection
through the API call from the unintentional one.

Bug: 234312519
Fixes: 234312519
Tag: #feature
Test: atest BassClientStateMachineTest --no-bazel-mode
Change-Id: I989652de2081082af89388aea91be05a8967e39c
parent 207b3e45
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ public class BassClientStateMachine extends StateMachine {
    private boolean mForceSB = false;
    private int mBroadcastSourceIdLength = 3;
    private byte mNextSourceId = 0;
    private boolean mAllowReconnect = false;

    BluetoothGatt mBluetoothGatt = null;
    BluetoothGattCallback mGattCallback = null;
@@ -1080,7 +1081,7 @@ public class BassClientStateMachine extends StateMachine {
                        mDevice, mLastConnectionState, BluetoothProfile.STATE_DISCONNECTED);
                if (mLastConnectionState != BluetoothProfile.STATE_DISCONNECTED) {
                    // Reconnect in background if not disallowed by the service
                    if (mService.okToConnect(mDevice)) {
                    if (mService.okToConnect(mDevice) && mAllowReconnect) {
                        connectGatt(false);
                    }
                }
@@ -1107,6 +1108,7 @@ public class BassClientStateMachine extends StateMachine {
                        mBluetoothGatt.close();
                        mBluetoothGatt = null;
                    }
                    mAllowReconnect = true;
                    if (connectGatt(mIsAllowedList)) {
                        transitionTo(mConnecting);
                    } else {
@@ -1115,6 +1117,7 @@ public class BassClientStateMachine extends StateMachine {
                    break;
                case DISCONNECT:
                    // Disconnect if there's an ongoing background connection
                    mAllowReconnect = false;
                    if (mBluetoothGatt != null) {
                        log("Cancelling the background connection to " + mDevice);
                        mBluetoothGatt.disconnect();
@@ -1473,6 +1476,7 @@ public class BassClientStateMachine extends StateMachine {
                    break;
                case DISCONNECT:
                    log("Disconnecting from " + mDevice);
                    mAllowReconnect = false;
                    if (mBluetoothGatt != null) {
                        mBluetoothGatt.disconnect();
                        mBluetoothGatt.close();
@@ -1735,6 +1739,7 @@ public class BassClientStateMachine extends StateMachine {
                    break;
                case DISCONNECT:
                    Log.w(TAG, "DISCONNECT requested!: " + mDevice);
                    mAllowReconnect = false;
                    if (mBluetoothGatt != null) {
                        mBluetoothGatt.disconnect();
                        mBluetoothGatt.close();