Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when trying to stop scan in background using BackgroundScanner when Bluetooth is disabled #481

Closed
gryffindor14 opened this issue Sep 17, 2018 · 2 comments
Assignees
Labels
bug Bug that is caused by the library

Comments

@gryffindor14
Copy link

gryffindor14 commented Sep 17, 2018

Summary

When Bluetooth is not enabled, calling client.getBackgroundScanner().stopScan(Pending) causes NPE

I assume this is due to BluetoothAdapter#getBluetoothLEScanner() returns null if the BluetoothAdapter is off.

Library version

1.7.0

Preconditions

Bluetooth is on and client returns State.READY for client state

Steps to reproduce actual result


1. startScanningWith background scanner (client.getBackgroundScanner().scanBleDeviceInBackground(settings, filter, PendingIntent)

2. turn off bluetooth

3. stop scanning in background client.getBackgroundScanner().stopScanningInBackground(PendingIntent)

Minimum code snippet reproducing the issue

Logs from the application running with setting RxBleLog.setLogLevel(RxBleLog.VERBOSE)

 Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.stopScan(android.app.PendingIntent)' on a null object reference
        at com.polidea.rxandroidble2.internal.util.RxBleAdapterWrapper.stopLeScan(RxBleAdapterWrapper.java:62)
        at com.polidea.rxandroidble2.internal.scan.BackgroundScannerImpl.stopBackgroundBleScan(BackgroundScannerImpl.java:74)

Actual result

Uncatchable NPE

Expected result

No Exception or BluetoothScanException with Code for Bluetooth being off

@dariuszseweryn dariuszseweryn self-assigned this Sep 24, 2018
@dariuszseweryn dariuszseweryn added the bug Bug that is caused by the library label Sep 24, 2018
@gryffindor14
Copy link
Author

gryffindor14 commented Sep 25, 2018

Somewhat related, there is a different internal exception when trying to start scanning in the background while bluetooth is disabled.

java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission: Neither user 10188 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
        at android.os.Parcel.createException(Parcel.java:1942)
        at android.os.Parcel.readException(Parcel.java:1910)
        at android.os.Parcel.readException(Parcel.java:1860)
        at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScanForIntent(IBluetoothGatt.java:977)
        at android.bluetooth.le.BluetoothLeScanner.startScan(BluetoothLeScanner.java:249)
        at android.bluetooth.le.BluetoothLeScanner.startScan(BluetoothLeScanner.java:166)
        at com.polidea.rxandroidble2.internal.util.RxBleAdapterWrapper.startLeScan(RxBleAdapterWrapper.java:57)
        at com.polidea.rxandroidble2.internal.scan.BackgroundScannerImpl.scanBleDeviceInBackground(BackgroundScannerImpl.java:56)

@dariuszseweryn
Copy link
Owner

This case should also be handled by the fix on fix/background_scanner_npe branch as it checks if adapter is on. I have created a different issue as potentially a SecurityException may also be thrown when specific settings will be passed to the scan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is caused by the library
Projects
None yet
Development

No branches or pull requests

2 participants