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

Commit 7d0f22db authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

Fix profiles being marked as FORBIDDEN before bonding is attempted.

Consider folowing scenario:

1. Device connects over LE transport. Service discovery is triggered.
2. UUIDS discovered event is propagated through stack, profile
   connection is triggered, which can mark some profiles as FORBIDDEN.
3. Bonding is triggered during same connection.
4. Service discovery, and DIS read is triggered after bonding.
5. Profile connection can't happen, because some profiles were already
   marked as FORBIDDEN in steap 2.

Only Battery Service is allowed to connect while not bonded, therefore
separate profile connection logic to treat it separately, and deal with
remaining profiles only when BONDING or BONDED.

Bug: 356325069
Bug: 355109861
Flag: unbonded_profile_forbid_fix
Test: perform subsequent FP pairing couple of times
Change-Id: I5bc5559b8e9007d6f41d313f170b935e50d50bcc
parent 2110c70f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -202,7 +202,7 @@ final class BondStateMachine extends StateMachine {
                        Log.e(
                                TAG,
                                "In stable state, received invalid newState: "
                                        + state2str(newState));
                                        + bondStateToString(newState));
                    }
                    break;
                case BONDED_INTENT_DELAY:
@@ -599,9 +599,9 @@ final class BondStateMachine extends StateMachine {
                "Bond State Change Intent:"
                        + device
                        + " "
                        + state2str(oldState)
                        + bondStateToString(oldState)
                        + " => "
                        + state2str(newState));
                        + bondStateToString(newState));
    }

    void bondStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
@@ -803,7 +803,7 @@ final class BondStateMachine extends StateMachine {
        }
    }

    private String state2str(int state) {
    public static String bondStateToString(int state) {
        if (state == BluetoothDevice.BOND_NONE) {
            return "BOND_NONE";
        } else if (state == BluetoothDevice.BOND_BONDING) {
+12 −2
Original line number Diff line number Diff line
@@ -1125,9 +1125,19 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
     * @param uuids are the services supported by the remote device
     */
    void onUuidsDiscovered(BluetoothDevice device, ParcelUuid[] uuids) {
        debugLog("onUuidsDiscovered: discovered services for device " + device);
        int bondState = mAdapterService.getBondState(device);
        debugLog(
                "onUuidsDiscovered: discovered services for device "
                        + device
                        + " ("
                        + BondStateMachine.bondStateToString(bondState)
                        + ")");
        if (uuids != null) {
            if (!Flags.unbondedProfileForbidFix() || bondState != BluetoothDevice.BOND_NONE) {
                processInitProfilePriorities(device, uuids);
            } else {
                debugLog("Device in BOND_NONE state, won't connect profiles" + device);
            }
        } else {
            warnLog("onUuidsDiscovered: uuids is null for device " + device);
        }