WifiUtils icon indicating copy to clipboard operation
WifiUtils copied to clipboard

Android 9 throttling

Open fernando-s97 opened this issue 2 years ago • 5 comments

image

In Android 9, when I execute the code below 5 times , in the 5th attempt, I won't be able to connect. That's because every time I make a connection, a scan is triggered. Why's that? Is it really necessary?

WifiUtils.withContext(requireContext())
            .connectWith("ssid", "pass")
            .setTimeout(5000)
            .onConnectionResult(object : ConnectionSuccessListener {
                override fun success() {
                    isConnected = true
                    Toast.makeText(activity, "Connect success!", Toast.LENGTH_SHORT)
                        .show()
                }

                override fun failed(errorCode: ConnectionErrorCode) {
                    Toast.makeText(
                        activity,
                        "Failed to connect: $errorCode",
                        Toast.LENGTH_SHORT
                    ).show()
                }
            })
            .start()

fernando-s97 avatar Nov 08 '21 20:11 fernando-s97

Hello,

At the moment WiFIUtils indeed performs a scan before connecting to a wifi and there is currently no way to override this behavior.

This was a design choice back in the day when android wouldn't impose throttling on wifi scanning.

It is a good idea to deprecate that behavior now. Hopefully I will get around to it as soon as I find some time. Pull requests are also welcome.

ThanosFisherman avatar Nov 08 '21 21:11 ThanosFisherman

Got it! I'll see if I can work on that and make a PR

fernando-s97 avatar Nov 09 '21 02:11 fernando-s97

Is it not possible to use the old scan results instead of scanning all the time? I mean if the scan fails then provide the old scan results. This is what the official document says, how to perform a network scan.

ansuman87 avatar Jan 29 '22 13:01 ansuman87

Got it! I'll see if I can work on that and make a PR

any progress yet?

vanenshi avatar Feb 03 '22 07:02 vanenshi

@vanenshi I ended up not being to take a look at it, and I think I won't be to do it in the next 1 or 2 months

fernando-s97 avatar Feb 03 '22 13:02 fernando-s97