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

Commit be05f751 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Gerrit Code Review
Browse files

Merge "Do not remove duplicate non-LE-only device records" into main

parents 776b8f9a f6abd63d
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);