use of com.polidea.rxandroidble2.scan.ScanFilter in project xDrip by NightscoutFoundation.
the class ScanMeister method scan.
// /
public synchronized void scan() {
extendWakeLock((scanSeconds + 1) * Constants.SECOND_IN_MS);
stopScan("Scan start");
UserError.Log.d(TAG, "startScan called: hunting: " + address + " " + name);
ScanFilter filter = this.customFilter;
if (filter == null) {
final ScanFilter.Builder builder = new ScanFilter.Builder();
if (address != null) {
try {
builder.setDeviceAddress(address);
} catch (IllegalArgumentException e) {
UserError.Log.wtf(TAG, "Invalid bluetooth address: " + address);
}
}
// TODO scanning by name doesn't build a filter
filter = builder.build();
} else {
UserError.Log.d(TAG, "Overriding with custom filter");
}
scanSubscription = new Subscription(rxBleClient.scanBleDevices(new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(), legacyNoFilterWorkaround ? ScanFilter.empty() : filter).timeout(scanSeconds, // is unreliable
TimeUnit.SECONDS).subscribeOn(Schedulers.io()).subscribe(this::onScanResult, this::onScanFailure));
Inevitable.task(STOP_SCAN_TASK_ID, scanSeconds * Constants.SECOND_IN_MS, this::stopScanWithTimeoutCallback);
}
use of com.polidea.rxandroidble2.scan.ScanFilter in project xDrip by NightscoutFoundation.
the class Ob1G5CollectionService method scan_for_device.
private synchronized void scan_for_device() {
if (state == SCAN) {
msg(gs(R.string.scanning));
stopScan();
// did we already find it?
tryLoadingSavedMAC();
if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) {
// reset if set
scan_next_run = false;
// reset if set
transmitterMAC = null;
last_scan_started = JoH.tsl();
scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7);
// "" if unset
historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID);
ScanFilter filter;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5) {
filter = new ScanFilter.Builder().setDeviceAddress(historicalTransmitterMAC).build();
} else {
final String localTransmitterID = transmitterID;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) {
filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build();
} else {
filter = new ScanFilter.Builder().build();
}
}
scanSubscription = new Subscription(rxBleClient.scanBleDevices(new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY).build(), // scan filter doesn't work reliable on android sdk 23+
filter).subscribeOn(Schedulers.io()).subscribe(this::onScanResult, this::onScanFailure));
if (minimize_scanning) {
// Must be less than fail over timeout
Inevitable.task(STOP_SCAN_TASK_ID, 320 * Constants.SECOND_IN_MS, this::stopScanWithTimeoutAndReschedule);
}
UserError.Log.d(TAG, "Scanning for: " + getTransmitterBluetoothName());
} else {
UserError.Log.d(TAG, "Transmitter mac already known: " + transmitterMAC);
changeState(CONNECT);
}
} else {
UserError.Log.wtf(TAG, "Attempt to scan when not in SCAN state");
}
}
use of com.polidea.rxandroidble2.scan.ScanFilter in project xDrip-plus by jamorham.
the class ScanMeister method scan.
// /
public synchronized void scan() {
extendWakeLock((scanSeconds + 1) * Constants.SECOND_IN_MS);
stopScan("Scan start");
UserError.Log.d(TAG, "startScan called: hunting: " + address + " " + name);
ScanFilter filter = this.customFilter;
if (filter == null) {
final ScanFilter.Builder builder = new ScanFilter.Builder();
if (address != null) {
try {
builder.setDeviceAddress(address);
} catch (IllegalArgumentException e) {
UserError.Log.wtf(TAG, "Invalid bluetooth address: " + address);
}
}
// TODO scanning by name doesn't build a filter
filter = builder.build();
} else {
UserError.Log.d(TAG, "Overriding with custom filter");
}
scanSubscription = new Subscription(rxBleClient.scanBleDevices(new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(), legacyNoFilterWorkaround ? ScanFilter.empty() : filter).timeout(scanSeconds, // is unreliable
TimeUnit.SECONDS).subscribeOn(Schedulers.io()).subscribe(this::onScanResult, this::onScanFailure));
Inevitable.task(STOP_SCAN_TASK_ID, scanSeconds * Constants.SECOND_IN_MS, this::stopScanWithTimeoutCallback);
}
use of com.polidea.rxandroidble2.scan.ScanFilter in project xDrip-plus by jamorham.
the class Ob1G5CollectionService method scan_for_device.
private synchronized void scan_for_device() {
if (state == SCAN) {
msg(gs(R.string.scanning));
stopScan();
// did we already find it?
tryLoadingSavedMAC();
if (always_scan || scan_next_run || (transmitterMAC == null) || (!transmitterID.equals(transmitterIDmatchingMAC)) || (static_last_timestamp < 1)) {
// reset if set
scan_next_run = false;
// reset if set
transmitterMAC = null;
last_scan_started = JoH.tsl();
scanWakeLock = JoH.getWakeLock("xdrip-jam-g5-scan", (int) Constants.MINUTE_IN_MS * 7);
// "" if unset
historicalTransmitterMAC = PersistentStore.getString(OB1G5_MACSTORE + transmitterID);
ScanFilter filter;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && historicalTransmitterMAC.length() > 5) {
filter = new ScanFilter.Builder().setDeviceAddress(historicalTransmitterMAC).build();
} else {
final String localTransmitterID = transmitterID;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && localTransmitterID != null && localTransmitterID.length() > 4) {
filter = new ScanFilter.Builder().setDeviceName(getTransmitterBluetoothName()).build();
} else {
filter = new ScanFilter.Builder().build();
}
}
scanSubscription = new Subscription(rxBleClient.scanBleDevices(new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).setScanMode(android_wear ? ScanSettings.SCAN_MODE_BALANCED : minimize_scanning ? ScanSettings.SCAN_MODE_BALANCED : ScanSettings.SCAN_MODE_LOW_LATENCY).build(), // scan filter doesn't work reliable on android sdk 23+
filter).subscribeOn(Schedulers.io()).subscribe(this::onScanResult, this::onScanFailure));
if (minimize_scanning) {
// Must be less than fail over timeout
Inevitable.task(STOP_SCAN_TASK_ID, 320 * Constants.SECOND_IN_MS, this::stopScanWithTimeoutAndReschedule);
}
UserError.Log.d(TAG, "Scanning for: " + getTransmitterBluetoothName());
} else {
UserError.Log.d(TAG, "Transmitter mac already known: " + transmitterMAC);
changeState(CONNECT);
}
} else {
UserError.Log.wtf(TAG, "Attempt to scan when not in SCAN state");
}
}
Aggregations