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

Commit bda07b4b authored by Yuanru Qian's avatar Yuanru Qian
Browse files

Fix the reconnection logic on uuid event update: the ACL...

Fix the reconnection logic on uuid event update: the ACL connection/disconnection should consider both BREDR & LE transport.

Test: locally tested
Bug: b/395573845
Flag: EXEMPT minor fix
Change-Id: I45cb7e4743d7c869edc90a363d91d69878521c3e
parent b40cb9b3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -585,7 +585,9 @@ public class BluetoothEventManager {
                    Log.w(TAG, "ActiveDeviceChangedHandler: unknown action " + action);
                    return;
            }
            activeDevice.onAclStateChanged(state);
            int transport = intent
                    .getIntExtra(BluetoothDevice.EXTRA_TRANSPORT, BluetoothDevice.TRANSPORT_BREDR);
            activeDevice.onAclStateChanged(state, transport);
            dispatchAclStateChanged(activeDevice, state);
        }
    }
+32 −5
Original line number Diff line number Diff line
@@ -142,9 +142,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     * If an ACTION_UUID intent comes in within
     * MAX_UUID_DELAY_FOR_AUTO_CONNECT milliseconds, we will try auto-connect
     * again with the new UUIDs
     * The value is reset if a manual disconnection happens.
     * The value is reset if a disconnection happens.
     */
    private long mConnectAttempted = -1;
    private boolean isAclConnectedBrEdr = false;
    private boolean isAclConnectedLe = false;

    // Active device state
    private boolean mIsActiveDeviceA2dp = false;
@@ -1121,14 +1123,39 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        }
    }

    void onAclStateChanged(int state) {
        if (state == BluetoothAdapter.STATE_DISCONNECTED) {
            mConnectAttempted = -1;
        } else {
    void onAclStateChanged(int state, int transport) {
        if (BluetoothUtils.D) {
            Log.d(
                    TAG,
                    "onAclStateChanged: device "
                            + mDevice.getAnonymizedAddress()
                            + ", state "
                            + state
                            + ", transport "
                            + transport);
        }
        boolean isUpdatedToConnected = state == BluetoothAdapter.STATE_CONNECTED;
        if (isUpdatedToConnected) {
            // Only update timestamp for the first ACL connection
            if (!isAclConnectedLe && !isAclConnectedBrEdr) {
                mConnectAttempted = SystemClock.elapsedRealtime();
            }
        }

        if (transport == BluetoothDevice.TRANSPORT_LE) {
            isAclConnectedLe = isUpdatedToConnected;
        } else {
            isAclConnectedBrEdr = isUpdatedToConnected;
        }

        if (!isUpdatedToConnected) {
            // Reset the connection time if both classic and LE are disconnected.
            if (!isAclConnectedLe && !isAclConnectedBrEdr) {
                mConnectAttempted = -1;
            }
        }
    }

    public Timestamp getBondTimestamp() {
        return mBondTimestamp;
    }