Estimote / Android-Proximity-SDK

Estimote Proximity SDK for Android
https://developer.estimote.com
MIT License
82 stars 42 forks source link

Unable to create bluetooth LE scanner instance #43

Closed francisco-rg closed 6 years ago

francisco-rg commented 6 years ago

Prerequisites

Basic information

Estimote SDK version: [0.4.1 and mustard:0.2.1]

Android devices affected: [Android Lollipop 5.1.1 Api 22, Android Nougat 7.0 Api 24]

Android OS version affected: [Samsung Galaxy J1 Ace, Samsung Note 5,Huawei P10 (VTR-L09), Huawei P10 (WAS-LX3)]

Beacon hardware version: [F3.3 / Estimote OS 4.13.2]

Description

[When our app start and began to scan for beacons it crash, see below for log details, if need we have crashlytics info]

example case:

  1. [stop buetooth services]
  2. [restart or initialize the app]
  3. [ask for permisssion, answer yes]
  4. [Wait for first scan and Crashes

Expected behavior: [Scan for beacons, zone event should be fired upon a beacon detection, no to crash the app]

Actual behavior: [After bluetooh has been active and scans happens, app shouldn't crash]

Additional information

Might be the same case as issue #36 or at least related, the behavior and the way to created it is almost the same


Fatal Exception: java.lang.IllegalStateException
Unable to create bluetooth LE scanner instance
arrow_right
com.estimote.scanning_plugin.packet_provider.scanner.AlwaysErrorEstimoteScaner.scan (AlwaysErrorEstimoteScaner.kt:13)
com.estimote.scanning_plugin.packet_provider.use_cases.EstimoteLocationScanUseCase.run (EstimoteLocationScanUseCase.kt:22)
com.estimote.scanning_plugin.packet_provider.EstimotePacketProvider.provideEstimoteLocation (EstimotePacketProvider.kt:43)
com.estimote.scanning_plugin.api.EstimoteBluetoothScanner$estimoteLocationScan$1.invoke (EstimoteBluetoothScanner.kt:16)
com.estimote.scanning_plugin.api.EstimoteBluetoothScanner$estimoteLocationScan$1.invoke (EstimoteBluetoothScanner.kt:10)
com.estimote.scanning_plugin.api.use_cases.ScanUseCase$scanForPacketsAccordingToSettings$1.apply (ScanUseCase.kt:22)
com.estimote.scanning_plugin.api.use_cases.ScanUseCase$scanForPacketsAccordingToSettings$1.apply (ScanUseCase.kt:8)
io.reactivex.internal.operators.observable.ObservableScalarXMap$ScalarXMapObservable.subscribeActual (ObservableScalarXMap.java:142)
io.reactivex.Observable.subscribe (Observable.java:10903)
io.reactivex.Observable.subscribe (Observable.java:10889)
io.reactivex.Observable.subscribe (Observable.java:10818)
com.estimote.scanning_plugin.api.use_cases.ScanUseCase.notifyUserCallbacks (ScanUseCase.kt:28)
com.estimote.scanning_plugin.api.use_cases.ScanUseCase.run (ScanUseCase.kt:14)
com.estimote.scanning_plugin.api.scan_launchers.BaseScannerScanLauncher.start (BaseScannerScanLauncher.kt:25)
com.estimote.scanning_plugin.api.scan_launchers.BaseScannerScanLauncher.start (BaseScannerScanLauncher.kt:8)
com.estimote.proximity_sdk.monitoring.estimote_monitoring.SimpleEstimoteMonitor$startEstimoteLocationScan$1.subscribe (SimpleEstimoteMonitor.kt:45)
io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual (ObservableCreate.java:40)
io.reactivex.Observable.subscribe (Observable.java:10903)
pawelDylag commented 6 years ago

Hello @francisco-rg

The internal Bluetooth scanner object is being initialised only once upon building the ProximityObserver object (using ProximityObserverBuilder). If you build it at the same moment when the Bluetooth is disabled, the scanner object will be initialized with AlwaysErrorEstimoteScanner implementation, and will throw... wait for it... an error whenever it will be started.

My strong suggestion is to build your ProximityObserver only when the Bluetooth is enabled. Doing this directly in onRequirementsFulfilled: action in our RequirementsChecker should prevent from getting Unable to create bluetooth LE scanner instance.

Kind regards, Paweł

francisco-rg commented 6 years ago

Hi Pawel,

Yeah this actually fix it or so it seems at least after a couple of test, I will try in a few others phones and a few more times just to be sure.

Thanks

pawelDylag commented 6 years ago

Hey @francisco-rg
Using RequirementsChecker should prevent this issue. Now since the new version 0.4.2 no uncaught exception should be thrown anyway - it will be properly reported in onErrorAction set via ProximityObserverBuilder.