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

IllegalStateException when starting monitoring on SDK 0.9.6 #137

Closed
rafalniski opened this issue Jan 18, 2016 · 3 comments
Closed

IllegalStateException when starting monitoring on SDK 0.9.6 #137

rafalniski opened this issue Jan 18, 2016 · 3 comments

Comments

@rafalniski
Copy link

Hi,

after update from 0.8.8 to 0.9.6 we were starting getting this exception:

Fatal Exception: java.lang.IllegalStateException: BT Adapter is not turned ON
   at android.bluetooth.le.BluetoothLeUtils.checkAdapterStateOn(BluetoothLeUtils.java:136)
   at android.bluetooth.le.BluetoothLeScanner.startScan(BluetoothLeScanner.java:106)
   at android.bluetooth.le.BluetoothLeScanner.startScan(BluetoothLeScanner.java:101)
   at com.estimote.sdk.service.internal.LollipopBluetoothAdapter.start(LollipopBluetoothAdapter.java:146)
   at com.estimote.sdk.service.internal.LollipopBluetoothAdapter.updateScanSettings(LollipopBluetoothAdapter.java:97)
   at com.estimote.sdk.service.BeaconService.updateScanPeriods(BeaconService.java:453)
   at com.estimote.sdk.service.BeaconService.startScanning(BeaconService.java:415)
   at com.estimote.sdk.service.BeaconService.startMonitoring(BeaconService.java:358)
   at com.estimote.sdk.service.BeaconService.access$500(BeaconService.java:77)
   at com.estimote.sdk.service.BeaconService$IncomingHandler$1.run(BeaconService.java:537)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.os.HandlerThread.run(HandlerThread.java:61)

And the code for starting monitoring looks like:

if (SystemRequirementsHelper.isBluetoothLeAvailable(context) && SystemRequirementsHelper.isBluetoothEnabled(context)) {
    beaconManager.startMonitoring(ALL_ESTIMOTE_BEACONS_REGION);
    LOG.debug("monitoring started");
}

Any idea on what is the cause?

@rafalniski rafalniski changed the title IllegalStateException when starting monitoroing on SDK 0.9.6 IllegalStateException when starting monitoring on SDK 0.9.6 Jan 18, 2016
@pwittchen
Copy link
Contributor

My guess: something is wrong with SystemRequirementsHelper and isBluetoothEnabled(context) method doesn't work properly and returns true when it shouldn't. Probably it's a bug. You can wait for an update of Estimote SDK or try to solve it yourself. You can try the following code snippet:

public boolean isBluetoothEnabled() {
  BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  return adapter != null && adapter.isEnabled();
}

I cannot guarantee, it's the right solution and if will work on any device and Android API, but I think it should and you can try.

In the code snippet above, adapter will be null, when a specific device doesn't support Bluetooth.

Poberro added a commit that referenced this issue Jan 19, 2016
- Packet parser errors are logged and should not crash whole application.
- Fixed threading issue that cause scanning to continue when service was stopped (on some devices).
- onExitRegion should be now working on devices with pre-Lollipop Androids.
- Fixed (#135): Fails getting RSSI on Android >=5.0 (Samsung Galaxies)
- Fixed (#137): IllegalStateException when starting monitoring on SDK 0.9.6
@Poberro
Copy link
Contributor

Poberro commented Jan 19, 2016

Actually it is the new behavior of BluetoothLeScanner that throws an exception when state of BluetoothAdapter is not on (adapter may be enabled but it is not turned on). Old scanning API just returned false, new one crashes an app. It should be fixed in SDK 0.9.7.

@Poberro Poberro closed this as completed Jan 19, 2016
Poberro added a commit that referenced this issue Jan 19, 2016
- Packet parser errors are logged and should not crash whole application.
- Fixed threading issue that cause scanning to continue when service was stopped (on some devices).
- onExitRegion should be now working on devices with pre-Lollipop Androids.
- Fixed (#135): Fails getting RSSI on Android >=5.0 (Samsung Galaxies)
- Fixed (#137): IllegalStateException when starting monitoring on SDK 0.9.6
@rafalniski
Copy link
Author

After upgrade to 0.9.7 the issue still happens:

Fatal Exception: java.lang.IllegalStateException: BT Adapter is not turned ON
   at android.bluetooth.le.BluetoothLeUtils.checkAdapterStateOn(BluetoothLeUtils.java:136)
   at android.bluetooth.le.BluetoothLeScanner.startScan(BluetoothLeScanner.java:106)
   at android.bluetooth.le.BluetoothLeScanner.startScan(BluetoothLeScanner.java:101)
   at com.estimote.sdk.service.internal.LollipopBluetoothAdapter.start(LollipopBluetoothAdapter.java:160)
   at com.estimote.sdk.service.internal.LollipopBluetoothAdapter.updateFilters(LollipopBluetoothAdapter.java:133)
   at com.estimote.sdk.service.BeaconService$1.onRegionsChanged(BeaconService.java:246)
   at com.estimote.sdk.service.internal.RegionObserver.onRegionsChanged(RegionObserver.java:90)
   at com.estimote.sdk.service.internal.RegionObserver.add(RegionObserver.java:51)
   at com.estimote.sdk.service.BeaconService.startMonitoring(BeaconService.java:358)
   at com.estimote.sdk.service.BeaconService.access$600(BeaconService.java:77)
   at com.estimote.sdk.service.BeaconService$IncomingHandler$1.run(BeaconService.java:541)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.os.HandlerThread.run(HandlerThread.java:61)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants