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

Commit 78704c53 authored by Jack He's avatar Jack He Committed by Android (Google) Code Review
Browse files

Merge "Enable remove duplicate device in CachedBluetoothDevice." into main

parents 1bdf95ed b9cd8fe9
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) {