Friday, March 30, 2012

Re: [android-developers] Wifi and phone sleep state



30.03.2012 16:31, Mark Murphy написал:
IMHO, the SwitchPreference where tapping on the preference *also* launches a nested PreferenceScreen is lousy UX. I keep forgetting there are options under the WiFi one, until I'm trying to connect to some new AP and then eventually stumble upon it. And, of course, buried inside of there are the advanced settings.

It's worse than that - not only is it necessary to enter the screen that lists networks, it's also necessary to use the Menu (button or the famous three little dots) and bring up "Advanced (Additional) settings"

 FWIW, the Galaxy Nexus default seems to be always-on -- I toggled mine back to only-when-plugged-in.

Yes, the default seems to have changed starting with 2.3 (perhaps together with better power management - keeping the WiFi hardware in some kind of low-power mode... that's pure speculation on my part), but I wouldn't count on all manufacturers being consistent with each other.

And then, some users do discover the setting to change the policy.


> From an application's point of view, though, it's just same old > ConnectivityManager.getActiveNetworkInfo - the connection is either there > and it's WiFi, or it's not. 
Well, the decision on whether to use a WifiLock would be based in part on WIFI_SLEEP_POLICY -- if WIFI_SLEEP_POLICY is WIFI_SLEEP_POLICY_NEVER, you do not need the WifiLock. That was the point behind your original post on this thread IIRC.

Checking this setting isn't necessary.

If the WiFi chip is actually on (sleep policy "never" or "plugged in" and the device is in fact plugged in), there will be a connection unless there is nothing to connect to. In the latter case acquiring a WiFi lock is pointless.

If the sleep policy is "off when the screen is off", and the hardware really is off, WifiManager.isWifiEnabled() will still return true, and that's when you'll need to acquire a WiFi lock to set things in motion.

I've only seen this fail on an HTC Hero with 2.1, but that's ancient history. A Moto Milestone also with 2.1 behaves like more current devices.

-- K

No comments:

Post a Comment