mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 01:25:50 +01:00
Skip service scan if supported device could be recognized without uuids during discovery
This commit is contained in:
parent
4bf37ea70f
commit
7b5e333601
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
@ -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<DeviceCoordinator> coordinators;
|
||||
|
||||
public static DeviceHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
// lazily created
|
||||
private List<DeviceCoordinator> coordinators;
|
||||
|
||||
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
||||
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
||||
DeviceType deviceType = coordinator.getSupportedType(candidate);
|
||||
@ -203,15 +202,15 @@ public class DeviceHelper {
|
||||
|
||||
private List<DeviceCoordinator> createCoordinators() {
|
||||
List<DeviceCoordinator> 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());
|
||||
|
Loading…
Reference in New Issue
Block a user