openbmap / radiocells-scanner-android

WLAN and cell tower scanner for Radiocells.org
https://www.radiocells.org
Other
59 stars 25 forks source link

No wifi collected when sleeping on Android 9/Radiocells 0.8.18 #225

Open TimSC opened 5 years ago

TimSC commented 5 years ago
TimSC commented 5 years ago

Looks like Android 8+ introduced scan throttling, which is fairly restrictive:

Android 8.0 and Android 8.1:

Each background app can scan one time in a 30-minute period.

https://developer.android.com/guide/topics/connectivity/wifi-scan

Apparently, this is hard to circumvent. Only system tools have access to the android.Manifest.permission.NETWORK_SETTINGS permission https://stackoverflow.com/questions/51901074/prevent-wifi-scan-throttling-on-android-9-pie-with-network-settings-permission

It's in the news: https://www.xda-developers.com/android-pie-throttling-wi-fi-scans-crippling-apps/

The upstream "bug" in Android: https://issuetracker.google.com/issues/79906367

TimSC commented 5 years ago

This is effectively a dup of https://github.com/openbmap/radiocells-scanner-android/issues/218

UPDATE: There is a work around for Android 8 https://github.com/openbmap/radiocells-scanner-android/pull/219 but currently not for Android 9

532910 commented 5 years ago

looks like i've same issue on op3t lineageos 15.1

vubma commented 5 years ago

@TimSC Would it be able to use said permission if the apk is pushed to /system/priv-app? I'm still on 7.1.2 so can't test myself. I believe you also have to add the permission to the app, no? It's not optimal but would at least provide a workaround until a better solution is found.

532910 commented 5 years ago

I'm not pretty sure, but looks like excluding RadioBeacon from battery optimization solves this problem.

TimSC commented 5 years ago

@vubma I've combined my branched version 3d0b0e986939be39778bb9eedf71f1fd98a8f756 with android.permission.NETWORK_SETTINGS in the manifest. I think it has to be a system app because the docs says that permission is "Not for use by third-party or privileged applications." so I put it in /system/app (after rooting my phone obviously). It didn't resolve the performance issue.

I noticed that while android.permission.NETWORK_SETTINGS was shown after install, that permission was revoked by android. After install:

installPermissionsFixed=false
pkgFlags=[ SYSTEM DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP ]
requested permissions:
  android.permission.ACCESS_FINE_LOCATION
  android.permission.ACCESS_COARSE_LOCATION
  android.permission.INTERNET
  android.permission.ACCESS_WIFI_STATE
  android.permission.ACCESS_NETWORK_STATE
  android.permission.WRITE_EXTERNAL_STORAGE
  android.permission.READ_PHONE_STATE
  android.permission.CHANGE_WIFI_STATE
  android.permission.WAKE_LOCK
  android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
  android.permission.NETWORK_SETTINGS
  android.permission.READ_EXTERNAL_STORAGE

After use:

installPermissionsFixed=true
pkgFlags=[ SYSTEM DEBUGGABLE HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP ]
requested permissions:
  android.permission.ACCESS_FINE_LOCATION
  android.permission.ACCESS_COARSE_LOCATION
  android.permission.INTERNET
  android.permission.ACCESS_WIFI_STATE
  android.permission.ACCESS_NETWORK_STATE
  android.permission.WRITE_EXTERNAL_STORAGE
  android.permission.READ_PHONE_STATE
  android.permission.CHANGE_WIFI_STATE
  android.permission.WAKE_LOCK
  android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
  android.permission.READ_EXTERNAL_STORAGE

This is probably due to android:protectionLevel="signature". The docs say "A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission" Presumably "the same certificate as the application that declared the permission" is a google internal key.

@532910 The app works to some extent but the performance is far lower than what I would expect.

This limitation is rumoured to be fixed in Android Q https://web.archive.org/web/20190213065915/https://www.androidpolice.com/2019/01/27/background-location-access-for-third-party-apps-might-return-in-android-q/