Closed vmetric closed 4 years ago
When scanning stop, these lines occur in logcat: E/BluetoothUtils: Permission denial: Need ACCESS_FINE_LOCATION permission to get scan results I/WifiService: startScan uid=10615 E/WifiService: Permission violation - startScan not allowed for uid=10615, packageName=net.vmetric.find3.find3app, reason=java.lang.SecurityException: UID 10615 has no location permission
I think I remember mentioned someone in the android docs needing to request this permission with every use of the permission (that is, since startScan requires ACCESS_FINE_LOCATION, we need to request that permission before each scan). edit: though I may be incorrect
Fixed permission error by adding permission ACCESS_BACKGROUND_LOCATION (allows app to access location in background).
However, issue persists, and I found why: W/ActivityManager: Stopping service due to app idle: u0a615 -1m25s599ms net.vmetric.find3.find3app/.ScanService
This issue has been an interesting challenge. It boils down to (if I understand correctly):
Thus, the resolution that, so far, is working:
The end result is that our scanService is now a ForegroundService, allowing it to run when the app is not in focus and when our device is locked.
I also went ahead and set the partial wakelock in AlarmReceiverLife to timeout every 30 seconds. Along with this, I set AlarmReceiverLife (ll24 in MainActivity.java, see lines 210 through 227) to repeat every 31 seconds, so that if we stop scanning right after the wakelock has expired, we don't have to wait another 30 seconds for the wakelock to expire. This may not work like I want it to, but we'll see if any bugs pop up from it.
If anything in this explanation doesn't make sense, I apologize - I'm pretty mentally tired. I hope to go back and thoroughly comment on/explain all the code as I understand it and get the time to.
After leaving app, scanning stops.