Wifi Sleeps, Even with Lock

Wifi sleeps, even with Lock

There are numerous bugs on the Android bug tracker to do with wifi sleep/power saving mode and even apps available that attempt to rectify this. So it is quite likely that you are not doing anything wrong.

http://code.google.com/p/android/issues/detail?id=9781

http://code.google.com/p/android/issues/detail?id=1698

Also check out wififixer which is an open source project which may help you with code to keep the connection alive

http://wififixer.wordpress.com/

Android: Wifi is turned off even with WifiLock

As ahmedre noted this is a bug with Android. I now create a response from the client to make sure the message was received. Otherwise try again momentarily. This is to get around the problem of sending a message when the Wifi just died.

Update

I have not seen this particular issue on newer devices. Originally this behavior occured on the Galaxy Tab.

Keep WiFi Connection active even iPad is going into sleep mode/locked in iOS 5

Phew... Finally I got a solution with idleTimerDisabled.

Its a Boolean value that controls whether the idle timer is disabled for the application .

Its the way to prevent the iPad from sleeping while my application is running.

The default value of this property is NO. When most applications have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims.

This is done for the purposes of conserving power. However, applications that don't have user input except for the accelerometer—games, for instance—can, by setting this property to YES, disable the “idle timer” to avert system sleep.

I just set the value to YES while I'm sending a bulk chunk of data through WiFi and have set the value to NO when the process is completed.

Example:[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Note: Be sure to reset this property to NO when your app does not need to prevent screen locking.

You can see more details here

Can Wi-Fi or the CPU go to sleep when screen is on?

Can Wi-Fi or the CPU go to sleep when screen is on?

No.

There are WakeLocks and WifiLocks on Android -- but do I need these if my screen is never turning off?

I am not quite clear how your screen is never turning off. At the end of the day, AFAIK, a WakeLock is always involved. Whether you need the WakeLock or whether that WakeLock is managed by framework classes (e.g., android:keepScreenOn) or the OS (e.g., Settings option to keep the screen on), would depend on what you are doing.

I have never seen an Android device power down WiFi while the screen is on (and not at the lockscreen). I can't rule out the possibility that WiFi might be powered down due to low battery conditions in some manufacturer's extreme power-saving mode.

Will my screen being always on be sufficient to prevent the device from losing those connections (if we assume that the connection remains available and the server is fine)?

I would phrase it more as "keeping the screen on will help". Or, better, letting the device go into sleep mode will normally drop your WiFi connections.

To keep the screen on, I use the standard way: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Which means that you're using a WakeLock. It just so happens that it is one that is managed for you, and since you can't screw it up, you don't need the WAKE_LOCK permission.

the Wi-Fi radio or the CPU may go to sleep mode or turn off when the user does not interact with the device for a longer time (even if the screen is still on)?

For a normal device, no. I can't rule out some manufacturer doing some sort of e-ink thing that might have that behavior.

And, more specifically, may a background task's (e.g. IntentService) Wi-Fi or mobile data connection go to sleep when there is still an Activity that keeps the screen on?

It shouldn't. In particular, the mobile data connection never goes to sleep.


All this being said, the reliability of what you are doing is going to suck unless this is a completely controlled environment. You are making a lot of assumptions:

  • Some sort of permanent power source

  • Nobody messing with the device to move your activity to the background or BACK button out of it

  • Nobody messing with the WiFi network, either in general or fussing with settings on the device (e.g., putting it in airplane mode)

  • Etc.

If this is some sort of industrial process monitor or in-kiosk device, the odds of you controlling these things perfectly is decent but not great. You get much beyond that, and the odds of these things holding up tail off rapidly.


Do you have any references?

In an ideal world, all of this would be perfectly documented, there would be peace among all peoples, and Hayley Atwell would think that I'm a decent chap.

This is not an ideal world.

Not only is this stuff largely undocumented, but it is really up to the device manufacturers. That's why if this is not a very controlled environment, while you are welcome to try to get this sort of behavior, the real world is very messy, and you should not assume that you can keep a connection open indefinitely.

WiFi lock is not working when device goes to sleep mode

Try to use Services. Just insert you wifi connection code in a service, and this will run forever in background.



Related Topics



Leave a reply



Submit