From 9230580a0174b7a88ae15f3fc239d908f6b7af08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Wed, 13 Sep 2023 20:14:52 +0100 Subject: [PATCH] Display devices with unknown name during scan --- .../discovery/DiscoveryActivityV2.java | 2 +- .../discovery/GBScanEventProcessor.java | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java index d7854db54..1e03e4769 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/DiscoveryActivityV2.java @@ -104,7 +104,7 @@ public class DiscoveryActivityV2 extends AbstractGBActivity implements AdapterVi private final Handler handler = new Handler(); private static final long SCAN_DURATION = 30000; // 30s - private static final long LIST_REFRESH_THRESHOLD_MS = 2500L; + private static final long LIST_REFRESH_THRESHOLD_MS = 1000L; private long lastListRefresh = System.currentTimeMillis(); private final ScanCallback bleScanCallback = new BleScanCallback(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/GBScanEventProcessor.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/GBScanEventProcessor.java index 53db69da3..8df8e31d7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/GBScanEventProcessor.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/discovery/GBScanEventProcessor.java @@ -217,10 +217,12 @@ public final class GBScanEventProcessor implements Runnable { String previousName = null; ParcelUuid[] previousUuids = null; + boolean firstTime = false; if (candidate == null) { // First time we see this device LOG.debug("Found {} for the first time", address); + firstTime = true; final GBScanEvent firstEvent = events.get(0); events.remove(0); candidate = new GBDeviceCandidate(firstEvent.getDevice(), firstEvent.getRssi(), firstEvent.getServiceUuids()); @@ -248,22 +250,22 @@ public final class GBScanEventProcessor implements Runnable { LOG.error("SecurityException on candidate.getDevice().getUuids()"); } - if (Objects.equals(candidate.getName(), previousName) && Arrays.equals(candidate.getServiceUuids(), previousUuids)) { - // Neither name nor uuids changed, do not reprocess - LOG.trace("Not reprocessing {} due to no changes", address); - return false; + if (!firstTime) { + if (Objects.equals(candidate.getName(), previousName) && Arrays.equals(candidate.getServiceUuids(), previousUuids)) { + // Neither name nor uuids changed, do not reprocess + LOG.trace("Not reprocessing {} due to no changes", address); + return false; + } } - if (candidate.isNameKnown()) { - if (processCandidate(candidate)) { - LOG.info( - "Device {} ({}) is supported as '{}' without scanning services", - candidate.getDevice(), - candidate.getName(), - candidate.getDeviceType() - ); - return true; - } + if (processCandidate(candidate)) { + LOG.info( + "Device {} ({}) is supported as '{}' without scanning services", + candidate.getDevice(), + candidate.getName(), + candidate.getDeviceType() + ); + return true; } if (candidate.getServiceUuids().length == 0 || (candidate.getServiceUuids().length == 1 && candidate.getServiceUuids()[0].equals(ZERO_UUID))) {