AltBeacon / android-beacon-library

Allows Android apps to interact with BLE beacons
Apache License 2.0
2.83k stars 834 forks source link

IntentScanningStrategy continues when the apk was updated to use ForegroundServiceScanning #1136

Open jlasic opened 1 year ago

jlasic commented 1 year ago

I stumbled on a bug when testing scanning strategies for our use-case. We had phones running the app for long periods of time and were connected to remote logging solution so we had the logs to be observed.

We tested IntentScanningStrategy first and then via an app updated switched the app to use ForegroundServiceScanning.

Expected behavior

After the update all IntentScanningStrategy broadcasts should stop, ie. app is unregistered from Android BluetoothLE pending intent callbacks

Actual behavior

Foreground service starts scanning, but the app is also receiving intents in StartupBroadcastReceiver#L37

Steps to reproduce this behavior

We used remote logging solution so I saw this behaviour on one of our phones, other 3 phones in the tests were not impacted, nor could I reproduce the issue on my local device.

What I observed from the sdk code is that in case of a process restart with a different scanning strategy ScanHelper#stopAndroidOBackgroundScan is never called since the sdk doesn't have any reference to previous intent scanning strategy startup, even when calling BeaconManager#setIntentScanningStrategyEnabled(false).

What I suggest is explicitly calling BluetoothLeScanner#stopScan(getScanCallbackIntent()) when client calls BeaconManager#setIntentScanningStrategyEnabled(false)

Mobile device model and OS version

Affected device in our tests: Galaxy S9 (SM-G960U1), Android 10

Android Beacon Library version

2.19.5-beta9

davidgyoung commented 1 year ago

Thank you for this report. I know that boundary conditions associated with switching strategies is not well tested, so I believe you are probably correct here.