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

Commit b9cd8fe9 authored by chelseahao's avatar chelseahao
Browse files

Enable remove duplicate device in CachedBluetoothDevice.

Bug: 319197962
Test: manual
Change-Id: I910ec38e8e74b7e9fbdc0a35028a5a1009c04fab
parent 40992b0e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -7,3 +7,13 @@ flag {
    bug: "314812750"
}

flag {
    name: "enable_cached_bluetooth_device_dedup"
    namespace: "bluetooth"
    description: "Enable dedup in CachedBluetoothDevice"
    bug: "319197962"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settingslib.bluetooth;

import static com.android.settingslib.flags.Flags.enableCachedBluetoothDeviceDedup;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCsipSetCoordinator;
@@ -377,6 +379,10 @@ public class BluetoothEventManager {
                cachedDevice = mDeviceManager.addDevice(device);
            }

            if (enableCachedBluetoothDeviceDedup() && bondState == BluetoothDevice.BOND_BONDED) {
                mDeviceManager.removeDuplicateInstanceForIdentityAddress(device);
            }

            for (BluetoothCallback callback : mCallbacks) {
                callback.onDeviceBondStateChanged(cachedDevice, bondState);
            }
+14 −0
Original line number Diff line number Diff line
@@ -340,6 +340,20 @@ public class CachedBluetoothDeviceManager {
        }
    }

    synchronized void removeDuplicateInstanceForIdentityAddress(BluetoothDevice device) {
        String identityAddress = device.getIdentityAddress();
        if (identityAddress == null || identityAddress.equals(device.getAddress())) {
            return;
        }
        mCachedDevices.removeIf(d -> {
            boolean shouldRemove = d.getDevice().getAddress().equals(identityAddress);
            if (shouldRemove) {
                Log.d(TAG, "Remove instance for identity address " + d);
            }
            return shouldRemove;
        });
    }

    public synchronized boolean onProfileConnectionStateChangedIfProcessed(CachedBluetoothDevice
            cachedDevice, int state, int profileId) {
        if (profileId == BluetoothProfile.HEARING_AID) {