diff --git a/CHANGELOG.md b/CHANGELOG.md index 9635721e9..d14c7b8cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Show toast in case no app is installed which can handle GPX files * Mi Band 4/Amazfit Bip Lite: Trim white spaces and new lines from auth key * Mi Band 4/Amazfit Bip Lite: Display a toast and do not try to pair if there was no auth key supplied +* Skip service scan if supported device could be recognized without uuids during discovery #### Version 0.36.2 * Amazfit Bip: Untested support for Lite variant diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DiscoveryActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DiscoveryActivity.java index f88c692cf..f197af416 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DiscoveryActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DiscoveryActivity.java @@ -196,8 +196,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView private final BluetoothAdapter.LeScanCallback leScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { - LOG.warn(device.getName() + ": " + ((scanRecord != null) ? scanRecord.length : -1)); - logMessageContent(scanRecord); + //logMessageContent(scanRecord); handleDeviceFound(device, (short) rssi); } }; @@ -339,6 +338,12 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView } private void handleDeviceFound(BluetoothDevice device, short rssi) { + if (device.getName() != null) { + if (handleDeviceFound(device,rssi, null)) { + LOG.info("found supported device " + device.getName() + " without scanning services, skipping service scan."); + return; + } + } ParcelUuid[] uuids = device.getUuids(); if (uuids == null) { if (device.fetchUuidsWithSdp()) { @@ -350,7 +355,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView } - private void handleDeviceFound(BluetoothDevice device, short rssi, ParcelUuid[] uuids) { + private boolean handleDeviceFound(BluetoothDevice device, short rssi, ParcelUuid[] uuids) { LOG.debug("found device: " + device.getName() + ", " + device.getAddress()); if (LOG.isDebugEnabled()) { if (uuids != null && uuids.length > 0) { @@ -360,7 +365,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView } } if (device.getBondState() == BluetoothDevice.BOND_BONDED) { - return; // ignore already bonded devices + return true; // ignore already bonded devices } GBDeviceCandidate candidate = new GBDeviceCandidate(device, rssi, uuids); @@ -375,7 +380,9 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView deviceCandidates.add(candidate); } cadidateListAdapter.notifyDataSetChanged(); + return true; } + return false; } /** diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java index 52d22230a..b087dbe1d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java @@ -46,11 +46,6 @@ public class MiBand2Coordinator extends HuamiCoordinator { @NonNull @Override public DeviceType getSupportedType(GBDeviceCandidate candidate) { - if (candidate.supportsService(HuamiService.UUID_SERVICE_MIBAND2_SERVICE)) { - return DeviceType.MIBAND2; - } - - // and a heuristic for now try { BluetoothDevice device = candidate.getDevice(); String name = device.getName(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java index baada67ff..e1af93727 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java @@ -82,14 +82,13 @@ public class DeviceHelper { private static final Logger LOG = LoggerFactory.getLogger(DeviceHelper.class); private static final DeviceHelper instance = new DeviceHelper(); + // lazily created + private List coordinators; public static DeviceHelper getInstance() { return instance; } - // lazily created - private List coordinators; - public DeviceType getSupportedType(GBDeviceCandidate candidate) { for (DeviceCoordinator coordinator : getAllCoordinators()) { DeviceType deviceType = coordinator.getSupportedType(candidate); @@ -203,15 +202,15 @@ public class DeviceHelper { private List createCoordinators() { List result = new ArrayList<>(); - result.add(new MiScale2DeviceCoordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new AmazfitBipCoordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new AmazfitBipLiteCoordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new AmazfitCorCoordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new AmazfitCor2Coordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new MiBand3Coordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new MiBand4Coordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new MiBand2HRXCoordinator()); // Note: must come before MiBand2 because detection is hacky, atm - result.add(new MiBand2Coordinator()); // Note: MiBand2 must come before MiBand because detection is hacky, atm + result.add(new MiScale2DeviceCoordinator()); + result.add(new AmazfitBipCoordinator()); + result.add(new AmazfitBipLiteCoordinator()); + result.add(new AmazfitCorCoordinator()); + result.add(new AmazfitCor2Coordinator()); + result.add(new MiBand3Coordinator()); + result.add(new MiBand4Coordinator()); + result.add(new MiBand2HRXCoordinator()); + result.add(new MiBand2Coordinator()); // Note: MiBand2 and all of the above must come before MiBand because detection is hacky, atm result.add(new MiBandCoordinator()); result.add(new PebbleCoordinator()); result.add(new VibratissimoCoordinator());