Skip to content

Commit

Permalink
Fixes retrying on Scan operation on error
Browse files Browse the repository at this point in the history
  • Loading branch information
BharathMG committed Apr 16, 2017
1 parent 88ee8c5 commit cc1798f
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import rx.Observable;
import rx.functions.Action0;
import rx.functions.Func0;
import rx.functions.Func1;

class RxBleClientImpl extends RxBleClient {
Expand Down Expand Up @@ -55,6 +56,7 @@ class RxBleClientImpl extends RxBleClient {
this.rxBleDeviceProvider = rxBleDeviceProvider;
this.executorService = executorService;
}

@Override
protected void finalize() throws Throwable {
super.finalize();
Expand All @@ -80,19 +82,23 @@ public Set<RxBleDevice> getBondedDevices() {
}

@Override
public Observable<RxBleScanResult> scanBleDevices(@Nullable UUID... filterServiceUUIDs) {

if (!rxBleAdapterWrapper.hasBluetoothAdapter()) {
return Observable.error(new BleScanException(BleScanException.BLUETOOTH_NOT_AVAILABLE));
} else if (!rxBleAdapterWrapper.isBluetoothEnabled()) {
return Observable.error(new BleScanException(BleScanException.BLUETOOTH_DISABLED));
} else if (!locationServicesStatus.isLocationPermissionOk()) {
return Observable.error(new BleScanException(BleScanException.LOCATION_PERMISSION_MISSING));
} else if (!locationServicesStatus.isLocationProviderOk()) {
return Observable.error(new BleScanException(BleScanException.LOCATION_SERVICES_DISABLED));
} else {
return initializeScan(filterServiceUUIDs);
}
public Observable<RxBleScanResult> scanBleDevices(@Nullable final UUID... filterServiceUUIDs) {
return Observable.defer(new Func0<Observable<RxBleScanResult>>() {
@Override
public Observable<RxBleScanResult> call() {
if (!rxBleAdapterWrapper.hasBluetoothAdapter()) {
return Observable.error(new BleScanException(BleScanException.BLUETOOTH_NOT_AVAILABLE));
} else if (!rxBleAdapterWrapper.isBluetoothEnabled()) {
return Observable.error(new BleScanException(BleScanException.BLUETOOTH_DISABLED));
} else if (!locationServicesStatus.isLocationPermissionOk()) {
return Observable.error(new BleScanException(BleScanException.LOCATION_PERMISSION_MISSING));
} else if (!locationServicesStatus.isLocationProviderOk()) {
return Observable.error(new BleScanException(BleScanException.LOCATION_SERVICES_DISABLED));
} else {
return initializeScan(filterServiceUUIDs);
}
}
});
}

private Observable<RxBleScanResult> initializeScan(@Nullable UUID[] filterServiceUUIDs) {
Expand Down

0 comments on commit cc1798f

Please sign in to comment.