Merge "Fix incorrect UI issue of "previously connected devices""

This commit is contained in:
TreeHugger Robot
2020-02-11 06:43:02 +00:00
committed by Android (Google) Code Review
2 changed files with 46 additions and 1 deletions

View File

@@ -28,6 +28,9 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import java.util.ArrayList;
import java.util.List;
/**
* Maintain and update saved bluetooth devices(bonded but not connected)
*/
@@ -54,7 +57,10 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
if (mBluetoothAdapter.isEnabled()) {
final CachedBluetoothDeviceManager cachedManager =
mLocalManager.getCachedDeviceManager();
for (BluetoothDevice device : mBluetoothAdapter.getMostRecentlyConnectedDevices()) {
final List<BluetoothDevice> bluetoothDevices =
mBluetoothAdapter.getMostRecentlyConnectedDevices();
removePreferenceIfNecessary(bluetoothDevices, cachedManager);
for (BluetoothDevice device : bluetoothDevices) {
final CachedBluetoothDevice cachedDevice = cachedManager.findDevice(device);
if (cachedDevice != null) {
update(cachedDevice);
@@ -65,6 +71,18 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
}
}
private void removePreferenceIfNecessary(List<BluetoothDevice> bluetoothDevices,
CachedBluetoothDeviceManager cachedManager) {
for (BluetoothDevice device : new ArrayList<>(mPreferenceMap.keySet())) {
if (!bluetoothDevices.contains(device)) {
final CachedBluetoothDevice cachedDevice = cachedManager.findDevice(device);
if (cachedDevice != null) {
removePreference(cachedDevice);
}
}
}
}
@Override
public void update(CachedBluetoothDevice cachedDevice) {
if (isFilterMatched(cachedDevice)) {