Alternative for deprecated WifiManager.getConfiguredNetworks and WifiManager.removeNetwork methods on Android Q?
Asked Answered
A

0

6

For a UiTest class setup, I need to begin with no remembered Wifi Networks. To do this I use a combination of the WifiManager.getConfiguredNetworks() and WifiManager.removeNetwork(), both of which are now restricted and deprecated for Android Q.

Now, since I am running the tests in privileged mode (super user), the getConfiguredNetworks() method actually returns a full list of the networks, and the removeNetwork() removes networks I pass by returned WifiConfiguration's Ids, even though I run this code on an Android Q device.

TLDR: My issue is more about these two methods being deprecated without being properly replaced, not that they now are worthless to use. At least not to my knowing, which is why I am asking; are there any way I, with my testapplication run as Super-user, can:

  1. Retrieve all Wifi Configurations
  2. Delete them one by one

In the documentation, one can read:

getConfiguredNetworks()

This method was deprecated in API level 29. a) See WifiNetworkSpecifier.Builder#build() for new mechanism to trigger connection to a Wi-Fi network. b) See addNetworkSuggestions(java.util.List), removeNetworkSuggestions(java.util.List) for new API to add Wi-Fi networks for consideration when auto-connecting to wifi. Compatibility Note: For applications targeting Build.VERSION_CODES.Q or above, this API will return an empty list.

The solutions they've linked seem to be for the action of connecting to wifi networks, but that isn't what I am looking for.

PS, I would be at least as happy by executing adb shell commands (in superuser-mode if needed), to do the same thing. Already tried using wpa_cli list_networks to at least list all networks, but doesn't seem to be available.

Also have tried to remove data/misc/wifi/wpa_supplicant and data/misc_ce/0/wifi/WifiConfigStore.xml, to no avail.

Algonquian answered 17/1, 2020 at 16:12 Comment(2)
Hi @MahNas92. Have you found a solution?Bulk
@AlessandroCaliaro, unfortunately I haven't found any viable alternative to date, and am still running the deprecated method(s).Algonquian

© 2022 - 2024 — McMap. All rights reserved.