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

Commit f85caecd authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Wait for disconnection to remove properties of temporarily paired device

BT stack always generate BOND_NONE bond state change on completing
temporary pairing. This event ends up removing the device properties for
devices connected using insecure connections.
This fix will now wait for the devices to be disconnected to remove the
device properties when bond was not outright removed.

Test: mmm packages/modules/Bluetooth
Test: Manual | CtsVerifier app > Bluetooth Test > Insecure Client and Insecure
Flag: com.android.bluetooth.flags.temporary_pairing_device_properties
Bug: 341196265
Bug: 342202557
Change-Id: I1ece44dd68ce2a1db841984d827b7b131e53f94f
parent 494ebdfb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -489,7 +489,7 @@ final class BondStateMachine extends StateMachine {
            return;
        }

        mRemoteDevices.onBondStateChange(device, newState);
        mRemoteDevices.onBondStateChange(device, oldState, newState);

        if (devProp != null) {
            oldState = devProp.getBondState();
+16 −2
Original line number Diff line number Diff line
@@ -1243,9 +1243,23 @@ public class RemoteDevices {
        }
    }

    void onBondStateChange(BluetoothDevice device, int newState) {
    void onBondStateChange(BluetoothDevice device, int oldState, int newState) {
        String address = device.getAddress();
        if (Flags.temporaryPairingDeviceProperties() && oldState != BluetoothDevice.BOND_BONDED) {
            DeviceProperties deviceProperties = mDevices.get(address);
            int leConnectionHandle =
                    deviceProperties.getConnectionHandle(BluetoothDevice.TRANSPORT_LE);
            int bredrConnectionHandle =
                    deviceProperties.getConnectionHandle(BluetoothDevice.TRANSPORT_BREDR);
            if (leConnectionHandle != BluetoothDevice.ERROR
                    || bredrConnectionHandle != BluetoothDevice.ERROR) {
                // Device still connected, wait for disconnection to remove the properties
                return;
            }
        }

        if (Flags.removeAddressMapOnUnbond() && newState == BluetoothDevice.BOND_NONE) {
            removeAddressMapping(device.getAddress());
            removeAddressMapping(address);
        }
    }