Fix duplicate devices when multiple mediums scanning requested

The dedupuing logic was already in place, but there was a race
due to managin the list of devices from different threads.

Test: using wear app ensure dup device reproduses without CL, and not with it
Fixes: 160870456
Change-Id: I1526199e8e4fb4b8f7d7f306e9e676359cdca516
This commit is contained in:
Eugene Susla
2020-07-30 14:39:50 -07:00
parent afab5784ea
commit b8b53f3b39
2 changed files with 21 additions and 10 deletions

View File

@@ -141,6 +141,16 @@ public final class BluetoothDeviceFilter implements DeviceFilter<BluetoothDevice
return Objects.hash(mNamePattern, mAddress, mServiceUuids, mServiceUuidMasks);
}
@Override
public String toString() {
return "BluetoothDeviceFilter{"
+ "mNamePattern=" + mNamePattern
+ ", mAddress='" + mAddress + '\''
+ ", mServiceUuids=" + mServiceUuids
+ ", mServiceUuidMasks=" + mServiceUuidMasks
+ '}';
}
@Override
public int describeContents() {
return 0;

View File

@@ -259,18 +259,19 @@ public class DeviceDiscoveryService extends Service {
private void onDeviceFound(@Nullable DeviceFilterPair device) {
if (device == null) return;
if (mDevicesFound.contains(device)) {
return;
}
if (DEBUG) Log.i(LOG_TAG, "Found device " + device);
Handler.getMain().sendMessage(obtainMessage(
DeviceDiscoveryService::onDeviceFoundMainThread, this, device));
}
@MainThread
void onDeviceFoundMainThread(@NonNull DeviceFilterPair device) {
if (mDevicesFound.contains(device)) {
Log.i(LOG_TAG, "Skipping device " + device + " - already among found devices");
return;
}
Log.i(LOG_TAG, "Found device " + device);
if (mDevicesFound.isEmpty()) {
onReadyToShowUI();
}
@@ -432,10 +433,10 @@ public class DeviceDiscoveryService extends Service {
@Override
public String toString() {
return "DeviceFilterPair{" +
"device=" + device +
", filter=" + filter +
'}';
return "DeviceFilterPair{"
+ "device=" + device + " " + getDisplayName()
+ ", filter=" + filter
+ '}';
}
}