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

Commit b8b53f3b authored by Eugene Susla's avatar Eugene Susla
Browse files

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
parent afab5784
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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;
+11 −10
Original line number Diff line number Diff line
@@ -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
                    + '}';
        }
    }