Java Code Examples for com.polidea.rxandroidble2.exceptions.BleScanException#BLUETOOTH_DISABLED

The following examples show how to use com.polidea.rxandroidble2.exceptions.BleScanException#BLUETOOTH_DISABLED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackgroundScannerImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@RequiresApi(26 /* Build.VERSION_CODES.O */)
@Override
public void scanBleDeviceInBackground(@NonNull PendingIntent callbackIntent, ScanSettings scanSettings, ScanFilter... scanFilters) {
    if (Build.VERSION.SDK_INT < 26 /* Build.VERSION_CODES.O */) {
        RxBleLog.w("PendingIntent based scanning is available for Android O and higher only.");
        return;
    }
    if (!rxBleAdapterWrapper.isBluetoothEnabled()) {
        RxBleLog.w("PendingIntent based scanning is available only when Bluetooth is ON.");
        throw new BleScanException(BleScanException.BLUETOOTH_DISABLED);
    }

    RxBleLog.i("Requesting pending intent based scan.");
    final List<android.bluetooth.le.ScanFilter> nativeScanFilters = scanObjectsConverter.toNativeFilters(scanFilters);
    final android.bluetooth.le.ScanSettings nativeScanSettings = scanObjectsConverter.toNativeSettings(scanSettings);
    final int scanStartResult = rxBleAdapterWrapper.startLeScan(nativeScanFilters, nativeScanSettings, callbackIntent);

    if (scanStartResult != NO_ERROR) {
        final BleScanException bleScanException = new BleScanException(scanStartResult);
        RxBleLog.w(bleScanException, "Failed to start scan"); // TODO?
        throw bleScanException;
    }
}
 
Example 2
Source File: PendiqService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void onScanFailure(Throwable throwable) {
    UserError.Log.d(TAG, "onScanFailure: " + throwable);
    if (throwable instanceof BleScanException) {
        final String info = handleBleScanException((BleScanException) throwable);
        //   lastScanError = info;
        UserError.Log.d(TAG, info);
        if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) {
            // Attempt to turn bluetooth on
            if (ratelimit("bluetooth_toggle_on", 30)) {
                UserError.Log.d(TAG, "Pause before Turn Bluetooth on");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    //
                }
                UserError.Log.e(TAG, "Trying to Turn Bluetooth on");
                JoH.setBluetoothEnabled(xdrip.getAppContext(), true);
            }
        }
    }
    // TODO count scan duration
    stopScan();
    releaseWakeLock();
    background_automata(5000);
}
 
Example 3
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void onScanFailure(Throwable throwable) {
    UserError.Log.d(TAG, "onScanFailure: " + throwable);
    if (throwable instanceof BleScanException) {
        final String info = handleBleScanException((BleScanException) throwable);
        //   lastScanError = info;
        UserError.Log.d(TAG, info);
        if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) {
            // Attempt to turn bluetooth on
            if (ratelimit("bluetooth_toggle_on", 30)) {
                UserError.Log.d(TAG, "Pause before Turn Bluetooth on");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    //
                }
                UserError.Log.e(TAG, "Trying to Turn Bluetooth on");
                JoH.setBluetoothEnabled(xdrip.getAppContext(), true);
            }
        }
    }
    // TODO count scan duration
    stopScan();
    releaseWakeLock();
    background_automata(5000);
}
 
Example 4
Source File: ScanPreconditionsVerifierApi18.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
public void verify(boolean checkLocationProviderState) {
    if (!rxBleAdapterWrapper.hasBluetoothAdapter()) {
        throw new BleScanException(BleScanException.BLUETOOTH_NOT_AVAILABLE);
    } else if (!rxBleAdapterWrapper.isBluetoothEnabled()) {
        throw new BleScanException(BleScanException.BLUETOOTH_DISABLED);
    } else if (!locationServicesStatus.isLocationPermissionOk()) {
        throw new BleScanException(BleScanException.LOCATION_PERMISSION_MISSING);
    } else if (checkLocationProviderState && !locationServicesStatus.isLocationProviderOk()) {
        throw new BleScanException(BleScanException.LOCATION_SERVICES_DISABLED);
    }
}
 
Example 5
Source File: ScanMeister.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
protected synchronized void onScanFailure(Throwable throwable) {
    UserError.Log.d(TAG, "onScanFailure: " + throwable);
    if (throwable instanceof BleScanException) {
        final String info = HandleBleScanException.handle(TAG, (BleScanException) throwable);
        UserError.Log.d(TAG, "Scan failure: " + info);
        if (!lastFailureReason.equals(info) || JoH.ratelimit("scanmeister-fail-error", 600)) {
            UserError.Log.e(TAG, "Failed to scan: " + info);
            lastFailureReason = info;
        }
        if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) {
            // Attempt to turn bluetooth on
            if (ratelimit("bluetooth_toggle_on", 30)) {
                UserError.Log.d(TAG, "Pause before Turn Bluetooth on");
                JoH.threadSleep(2000);
                UserError.Log.e(TAG, "Trying to Turn Bluetooth on");
                JoH.setBluetoothEnabled(xdrip.getAppContext(), true);
            }
        }
        processCallBacks(address, SCAN_FAILED_CALLBACK);
    } else if (throwable instanceof TimeoutException) {
        // note this code path not always reached - see inevitable task
        processCallBacks(address, SCAN_TIMEOUT_CALLBACK);
    }

    stopScan("Scan failure");
    releaseWakeLock();
}
 
Example 6
Source File: ScanMeister.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
protected synchronized void onScanFailure(Throwable throwable) {
    UserError.Log.d(TAG, "onScanFailure: " + throwable);
    if (throwable instanceof BleScanException) {
        final String info = HandleBleScanException.handle(TAG, (BleScanException) throwable);
        UserError.Log.d(TAG, "Scan failure: " + info);
        if (!lastFailureReason.equals(info) || JoH.ratelimit("scanmeister-fail-error", 600)) {
            UserError.Log.e(TAG, "Failed to scan: " + info);
            lastFailureReason = info;
        }
        if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) {
            // Attempt to turn bluetooth on
            if (ratelimit("bluetooth_toggle_on", 30)) {
                UserError.Log.d(TAG, "Pause before Turn Bluetooth on");
                JoH.threadSleep(2000);
                UserError.Log.e(TAG, "Trying to Turn Bluetooth on");
                JoH.setBluetoothEnabled(xdrip.getAppContext(), true);
            }
        }
        processCallBacks(address, SCAN_FAILED_CALLBACK);
    } else if (throwable instanceof TimeoutException) {
        // note this code path not always reached - see inevitable task
        processCallBacks(address, SCAN_TIMEOUT_CALLBACK);
    }

    stopScan("Scan failure");
    releaseWakeLock();
}
 
Example 7
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
protected synchronized void onScanFailure(Throwable throwable) {
    UserError.Log.d(TAG, "onScanFailure: " + throwable);
    if (throwable instanceof BleScanException) {
        final String info = HandleBleScanException.handle(TAG, (BleScanException) throwable);
        UserError.Log.d(TAG, "Scan failure: " + info);
        if (!lastFailureReason.equals(info) || JoH.ratelimit("scanmeister-fail-error", 600)) {
            UserError.Log.e(TAG, "Failed to scan: " + info);
            lastFailureReason = info;
        }
        if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) {
            // Attempt to turn bluetooth on
            if (ratelimit("bluetooth_toggle_on", 30)) {
                UserError.Log.d(TAG, "Pause before Turn Bluetooth on");
                JoH.threadSleep(2000);
                UserError.Log.e(TAG, "Trying to Turn Bluetooth on");
                JoH.setBluetoothEnabled(xdrip.getAppContext(), true);
            }
        }
        processCallBacks(address, SCAN_FAILED_CALLBACK);
    } else if (throwable instanceof TimeoutException) {
        // note this code path not always reached - see inevitable task
        processCallBacks(address, SCAN_TIMEOUT_CALLBACK);
    }

    stopScan("Scan failure");
    releaseWakeLock();
}
 
Example 8
Source File: ScanMeister.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
protected synchronized void onScanFailure(Throwable throwable) {
    UserError.Log.d(TAG, "onScanFailure: " + throwable);
    if (throwable instanceof BleScanException) {
        final String info = HandleBleScanException.handle(TAG, (BleScanException) throwable);
        UserError.Log.d(TAG, "Scan failure: " + info);
        if (!lastFailureReason.equals(info) || JoH.ratelimit("scanmeister-fail-error", 600)) {
            UserError.Log.e(TAG, "Failed to scan: " + info);
            lastFailureReason = info;
        }
        if (((BleScanException) throwable).getReason() == BleScanException.BLUETOOTH_DISABLED) {
            // Attempt to turn bluetooth on
            if (ratelimit("bluetooth_toggle_on", 30)) {
                UserError.Log.d(TAG, "Pause before Turn Bluetooth on");
                JoH.threadSleep(2000);
                UserError.Log.e(TAG, "Trying to Turn Bluetooth on");
                JoH.setBluetoothEnabled(xdrip.getAppContext(), true);
            }
        }
        processCallBacks(address, SCAN_FAILED_CALLBACK);
    } else if (throwable instanceof TimeoutException) {
        // note this code path not always reached - see inevitable task
        processCallBacks(address, SCAN_TIMEOUT_CALLBACK);
    }

    stopScan("Scan failure");
    releaseWakeLock();
}
 
Example 9
Source File: ScanOperation.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
protected BleException provideException(DeadObjectException deadObjectException) {
    return new BleScanException(BleScanException.BLUETOOTH_DISABLED, deadObjectException);
}