Connected devices page did not show correct summary when member device connect

Root Cause: CsipDeviceManager only refreshes UI when switching member device content.

Solution:
* CsipDeviceManager needs to call refresh() on main device when it's new
  member device added.
* UI widget Settings/BluetoothDevice also need to monitor it's member device status to refresh UI.

Bug: 344947362
Test: atest BluetoothDevicePreferenceTest
Flag: EXEMPT bugfix
Change-Id: I58f9e2fc209d4e87631784d0538b1647228f4c1a
This commit is contained in:
jasonwshsu
2024-07-19 19:16:11 +08:00
parent 93b093033a
commit 15c6533ef9
5 changed files with 204 additions and 74 deletions

View File

@@ -48,8 +48,9 @@ import com.android.settingslib.utils.ThreadUtils;
import com.google.common.base.Supplier;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
@@ -239,12 +240,12 @@ public final class Utils {
* @param cachedBluetoothDevice The main cachedBluetoothDevice.
* @return all cachedBluetoothDevices with the same groupId.
*/
public static List<CachedBluetoothDevice> getAllOfCachedBluetoothDevices(
public static Set<CachedBluetoothDevice> findAllCachedBluetoothDevicesByGroupId(
LocalBluetoothManager localBtMgr,
CachedBluetoothDevice cachedBluetoothDevice) {
List<CachedBluetoothDevice> cachedBluetoothDevices = new ArrayList<>();
Set<CachedBluetoothDevice> cachedBluetoothDevices = new HashSet<>();
if (cachedBluetoothDevice == null) {
Log.e(TAG, "getAllOfCachedBluetoothDevices: no cachedBluetoothDevice");
Log.e(TAG, "findAllCachedBluetoothDevicesByGroupId: no cachedBluetoothDevice");
return cachedBluetoothDevices;
}
int deviceGroupId = cachedBluetoothDevice.getGroupId();
@@ -254,7 +255,7 @@ public final class Utils {
}
if (localBtMgr == null) {
Log.e(TAG, "getAllOfCachedBluetoothDevices: no LocalBluetoothManager");
Log.e(TAG, "findAllCachedBluetoothDevicesByGroupId: no LocalBluetoothManager");
return cachedBluetoothDevices;
}
CachedBluetoothDevice mainDevice =
@@ -262,16 +263,14 @@ public final class Utils {
.filter(cachedDevice -> cachedDevice.getGroupId() == deviceGroupId)
.findFirst().orElse(null);
if (mainDevice == null) {
Log.e(TAG, "getAllOfCachedBluetoothDevices: groupId = " + deviceGroupId
Log.e(TAG, "findAllCachedBluetoothDevicesByGroupId: groupId = " + deviceGroupId
+ ", no main device.");
return cachedBluetoothDevices;
}
cachedBluetoothDevice = mainDevice;
cachedBluetoothDevices.add(cachedBluetoothDevice);
for (CachedBluetoothDevice member : cachedBluetoothDevice.getMemberDevice()) {
cachedBluetoothDevices.add(member);
}
Log.d(TAG, "getAllOfCachedBluetoothDevices: groupId = " + deviceGroupId
cachedBluetoothDevices.addAll(cachedBluetoothDevice.getMemberDevice());
Log.d(TAG, "findAllCachedBluetoothDevicesByGroupId: groupId = " + deviceGroupId
+ " , cachedBluetoothDevice = " + cachedBluetoothDevice
+ " , deviceList = " + cachedBluetoothDevices);
return cachedBluetoothDevices;