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

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

Do not remove duplicate non-LE-only device records

If identity address of the newly bonded device matches with an existing
bonded device, the existing bonded device is removed. This logic was
added to accomodate some LE-only devices which keep changing their IRK
which resulted in duplicate device records.
However this logic also removes the dual mode devices which don't
support CTKD. Pairing on both transport results in separate bond state
events which triggers this logic and removes the bond for both the
transports.

Test: mmm packages/modules/Bluetooth
Test: Manual | Pair on both transport with non-CTKD supporting dual mode
devices
Test: Manual | Repair with LE-only devices which keep changing its IRK
Bug: 322360482
Bug: 333949759

Change-Id: I48fdd9be2f76b854c47f47fb57794584468dbf16
parent 1f1a6668
Loading
Loading
Loading
Loading
+37 −21
Original line number Diff line number Diff line
@@ -674,24 +674,39 @@ class AdapterProperties {
                Flags.identityAddressNullIfUnknown()
                        ? Utils.getBrEdrAddress(device, mService)
                        : mService.getIdentityAddress(address);
        debugLog("cleanupPrevBondRecordsFor: " + device);
        int deviceType = mRemoteDevices.getDeviceProperties(device).getDeviceType();
        debugLog("cleanupPrevBondRecordsFor: " + device + ", device type: " + deviceType);
        if (identityAddress == null) {
            return;
        }

        if (Flags.cleanupLeOnlyDeviceType() && deviceType != BluetoothDevice.DEVICE_TYPE_LE) {
            return;
        }

        for (BluetoothDevice existingDevice : mBondedDevices) {
            String existingAddress = existingDevice.getAddress();
            String existingIdentityAddress =
                    Flags.identityAddressNullIfUnknown()
                            ? Utils.getBrEdrAddress(existingDevice, mService)
                            : mService.getIdentityAddress(existingAddress);

            if (!identityAddress.equals(existingIdentityAddress) || address.equals(
                existingAddress)) {
                continue;
            int existingDeviceType =
                    mRemoteDevices.getDeviceProperties(existingDevice).getDeviceType();

            boolean removeExisting = false;
            if (identityAddress.equals(existingIdentityAddress)
                    && !address.equals(existingAddress)) {
                if (Flags.cleanupLeOnlyDeviceType()) {
                    // Existing device record should be removed only if the device type is LE-only
                    removeExisting = (existingDeviceType == BluetoothDevice.DEVICE_TYPE_LE);
                } else {
                    removeExisting = true;
                }
            }

            // Found an existing device with same identity address but different pseudo address
            if (removeExisting) {
                // Found an existing LE-only device with the same identity address but different
                // pseudo address
                if (mService.getNative().removeBond(Utils.getBytesFromAddress(existingAddress))) {
                    mBondedDevices.remove(existingDevice);
                    infoLog(
@@ -710,6 +725,7 @@ class AdapterProperties {
                break;
            }
        }
    }

    int getDiscoverableTimeout() {
        return mDiscoverableTimeout;
+1 −0
Original line number Diff line number Diff line
@@ -485,6 +485,7 @@ public class RemoteDevices {
        /**
         * @param deviceType the mDeviceType to set
         */
        @VisibleForTesting
        void setDeviceType(int deviceType) {
            synchronized (mObject) {
                this.mDeviceType = deviceType;
+7 −2
Original line number Diff line number Diff line
@@ -101,8 +101,13 @@ public class AdapterPropertiesTest {
    @Test
    public void testCleanupPrevBondRecordsFor() {
        mRemoteDevices.reset();
        mRemoteDevices.addDeviceProperties(TEST_BT_ADDR_BYTES);
        mRemoteDevices.addDeviceProperties(TEST_BT_ADDR_BYTES_2);
        mRemoteDevices
                .addDeviceProperties(TEST_BT_ADDR_BYTES)
                .setDeviceType(BluetoothDevice.DEVICE_TYPE_LE);
        mRemoteDevices
                .addDeviceProperties(TEST_BT_ADDR_BYTES_2)
                .setDeviceType(BluetoothDevice.DEVICE_TYPE_LE);

        BluetoothDevice device1, device2;
        device1 = mRemoteDevices.getDevice(TEST_BT_ADDR_BYTES);
        device2 = mRemoteDevices.getDevice(TEST_BT_ADDR_BYTES_2);