radiocells-scanner-android icon indicating copy to clipboard operation
radiocells-scanner-android copied to clipboard

No wifi collected when sleeping on Android 9/Radiocells 0.8.18

Open TimSC opened this issue 7 years ago • 6 comments

  • On an Android 9 (OnePlus 6) phone,
  • Go to Setting-s> Wi-Fi & Internet -> Wi-Fi -> Wi-Fi preferences
  • Set "Scanning always available" to enabled
  • Start Radiocells 0.8.18
  • Start recording by pressing plus (this works fine, wifi and cells are recorded)
  • Hit power button to make phone go to sleep
  • Wait a bit, move around.
  • Hit power button to show app. No wifis have been logged while sleeping. (Cell towers work correctly.) log.txt

TimSC avatar Nov 29 '18 00:11 TimSC

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 avatar Nov 29 '18 04:11 TimSC

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

TimSC avatar Nov 29 '18 04:11 TimSC

looks like i've same issue on op3t lineageos 15.1

532910 avatar Dec 13 '18 11:12 532910

@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.

vubma avatar Feb 20 '19 04:02 vubma

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

532910 avatar Feb 22 '19 00:02 532910

@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/

TimSC avatar Apr 14 '19 06:04 TimSC