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

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

Remove device address mapping on device removal

Address mapping were not removed on device removal if the devices were not connected.

Test: mma packages/modules/Bluetooth
Test: manual | Pair with a dual mode device using RPA over LE transport, disconnect the device, remove the bond, discover and pair with the device again.

Bug: 326294532
Bug: 326603271
Change-Id: Ia748e27b68f3ae2926441688080970f8805323e2
parent 30a80b24
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.bluetooth.btservice;
import android.bluetooth.OobData;
import android.bluetooth.UidTraffic;

import com.android.bluetooth.flags.Flags;

class JniCallbacks {

    private RemoteDevices mRemoteDevices;
@@ -66,6 +68,9 @@ class JniCallbacks {

    void bondStateChangeCallback(int status, byte[] address, int newState, int hciReason) {
        mBondStateMachine.bondStateChangeCallback(status, address, newState, hciReason);
        if (Flags.removeBondWithAddressMap()) {
            mRemoteDevices.onBondStateChange(address, newState);
        }
    }

    void addressConsolidateCallback(byte[] mainAddress, byte[] secondaryAddress) {
+19 −9
Original line number Diff line number Diff line
@@ -1155,15 +1155,7 @@ public class RemoteDevices {
                Utils.sendBroadcast(mAdapterService, intent, BLUETOOTH_CONNECT,
                        Utils.getTempAllowlistBroadcastOptions());
            } else if (device.getBondState() == BluetoothDevice.BOND_NONE) {
                String key = Utils.getAddressStringFromByte(address);
                synchronized (mDevices) {
                    mDevices.remove(key);
                    mDeviceQueue.remove(key); // Remove from LRU cache

                    // Remove from dual mode device mappings
                    mDualDevicesMap.values().remove(key);
                    mDualDevicesMap.remove(key);
                }
                removeAddressMapping(address);
            }
            if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_TURNING_OFF) {
                mAdapterService.notifyAclDisconnected(device, transportLinkType);
@@ -1246,6 +1238,24 @@ public class RemoteDevices {
        }
    }

    private void removeAddressMapping(byte[] address) {
        String key = Utils.getAddressStringFromByte(address);
        synchronized (mDevices) {
            mDevices.remove(key);
            mDeviceQueue.remove(key); // Remove from LRU cache

            // Remove from dual mode device mappings
            mDualDevicesMap.values().remove(key);
            mDualDevicesMap.remove(key);
        }
    }

    void onBondStateChange(byte[] address, int newState) {
        if (newState == BluetoothDevice.BOND_NONE) {
            removeAddressMapping(address);
        }
    }

    void keyMissingCallback(byte[] address) {
        BluetoothDevice bluetoothDevice = getDevice(address);
        if (bluetoothDevice == null) {