startScan() in WifiManager deprecated in Android P

22,489

Solution 1

Google has now documented the limitations for startScan() function in Android P:

"We are further limiting the number of scans apps can request to improve network performance and improve battery life.

The WifiManager.startScan() usage is limited to: - Each foreground app is restricted to 4 scans every 2 minutes. - All background apps combined are restricted to one scan every 30 minutes."

Source: https://issuetracker.google.com/issues/79906367

Edit 8-Aug-2018: Information has been added also here: https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling

Solution 2

I think in API level P they're planning to move startScan() to a different class (WifiScanner) all together with some key differences.

See: https://android.googlesource.com/platform/frameworks/base/+/android-p-preview-1/wifi/java/android/net/wifi/WifiScanner.java

If there's an alternative solution to this, I'd love to hear it as well.

For now, I might just use startScan() until official docs are released.

Solution 3

startScan() is actually pretty buggy on P, as I raised Google Issue 79906367.

I don't think that WifiScanner is the replacement either, as that is marked as a SystemApi which means no access for Apps...

Hopefully we will hear soon, as RTT still means you need to scan for APs which support 802.11mc using ScanResult is80211mcResponder which you check before performing RTT Ranging on the AP.

Solution 4

I would guess the intention is to have developers/users use WifiRttManager instead for indoor location atleast [1]. Or rely on usual Google Play location services, which is an option in some use cases, but definitely not all. It's optimised for the average use case. No use case is the average use case.

Unfortunately with the way WifiRttManager calculates location it requires the wifi accesspoints to have 802.11mc. However you don't need to connect to these points. Virtually 0 routers today have this standard. [2] [3] [4] With 3 access points you can get location close to 1-2m accuracy.

Who knows if they'll place restrictions on this functionality as well though. I'm not happy that this functionality is being taken away from users and developers - all it needs is a permission.

So it appears there will be a dark age for indoor location over the next few years until 802.11mc is popular. Perhaps a workaround is to have devices you are connected to and ping them.

[1] https://developer.android.com/reference/android/net/wifi/rtt/WifiRttManager [2] https://github.com/Plinzen/android-rttmanager-sample

Additional reading [3] https://en.wikipedia.org/wiki/IEEE_802.11mc [4] https://fit-iot.com/web/wifi-indoor-positioning/

Solution 5

From WifiManager#EXTRA_RESULTS_UPDATED

Note: Apps holding android.Manifest.permission.NETWORK_SETTINGS permission are exempted from scan throttling.

Note: This is a system permission, regular apps can't use it without rooting and moving the app to the 'privileged' location or having it baked into a custom ROM.

Share:
22,489

Related videos on Youtube

EAK TEAM
Author by

EAK TEAM

" The more quieter you become, the more you are able to hear ... "

Updated on July 09, 2022

Comments

  • EAK TEAM
    EAK TEAM almost 2 years

    How to get scan result from wifi for example every 3 seconds, without mWifimanager.startScan();

    Google says :

    startScan() This method was deprecated in API level P. The ability for apps to trigger scan requests will be removed in a future release.

    Notice for this API level i'm using List<ScanResult> results = mWifiManager.getScanResults(); without calling startScan , the list contains the wifi AP's but it makes updated very very slow

    Update to 12 January 2019 : https://issuetracker.google.com/issues/112688545

    • Marc Estrada
      Marc Estrada about 6 years
      Are you targeting 26+?
    • oseiskar
      oseiskar almost 6 years
      This is an intentional dick move from Google, and logical continuation of transforming Android to an iOS-like closed platform, where certain capabilities, like background tracking, are reserved to the platform vendors' own services (which documentedly use them for privacy violations)
    • EAK TEAM
      EAK TEAM over 5 years
      @oseiskar , comment to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • Ernest Zamelczyk
    Ernest Zamelczyk almost 6 years
    So they're going to remove it and not provide any workaround? I'm actually developing app for business application and they're relying on frequent wifi scanning in a closed environment. The android devices will be constantly hooked up to power source so that isn't an issue. The app won't even be in Play store. I think they should provide a workaround just for these kind of applications. Maybe a system permission or something like that?
  • Manmohan Soni
    Manmohan Soni over 5 years
    then for that you should customise android os for those devices... i.e. is the only way to achieve it.
  • EAK TEAM
    EAK TEAM over 5 years
    Yes, now they clearly explain that ... But maybe there will be any update to help developers use more frequent scanning... We hope so. :)
  • EAK TEAM
    EAK TEAM over 5 years
    Google says : Permissions with the protection level signature, privileged or signatureOrSystem are only granted to system apps. If an app is a regular non-system app, it will never be able to use these permissions.
  • EAK TEAM
    EAK TEAM over 5 years
    Comment or Upvote to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • EAK TEAM
    EAK TEAM over 5 years
    Comment or Upvote to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • EAK TEAM
    EAK TEAM over 5 years
    Comment or Upvote to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • EAK TEAM
    EAK TEAM over 5 years
    Comment or Upvote to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • EAK TEAM
    EAK TEAM over 5 years
    Comment or Upvote to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • EAK TEAM
    EAK TEAM over 5 years
    Comment or Upvote to this report to support WiFi scanning issuetracker.google.com/issues/112688545
  • Sevenate
    Sevenate over 5 years
    @EAKTEAM well at least you can have it in the side loaded app.
  • EAK TEAM
    EAK TEAM about 5 years
    Hope that this will be changed in latest Android Q (BETA) , we are all waiting for this change ! It's crazy to limit developers from using this tool ... All we can do is to wait.