[MOD][XPOSED][KK] Wi-Fi Deep Sleep

Search This thread

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
Only for Android KitKat.

Once installed this mod prevents Wi-Fi from waking up during device sleep mode and when you turn on the screen without unlocking it (to look at the clock, for example).

Background

Normally Wi-Fi can be awakened and kept on due to Wifi locks held by certain applications that often use to abuse this opportunity. This results in Wi-Fi being turned on over up to the half of the total sleep time (or even more) which in turn of course eats the battery. Another issue is that once turned on by a single application it notifies and awakes lots of other apps that may start, for example, their heavy synchronization tasks, etc., making everything even worse.

Auto Wi-Fi apps

Nevertheless, Wifi lock is a good mechanism when used carefully, and generally it should be respected when deciding whether to switch Wi-Fi on and off. This becomes a problem for most of Wi-Fi management apps found in Play Market: they can switch Wi-Fi off in the middle of a Skype call just because the screen was turned off.

The solution

This mod alters a system state machine responsible for managing Wi-Fi so that once put to sleep it can not be woken up by any application that requests a lock. Wi-Fi is only put asleep when no application holds a lock. That is it doesn't cancel locks held already, but once all of them are gone, no one else is able to aquire a new lock until the screen is turned on and unlocked. This doesn't apply to special high performance Wifi lock, it still can be aquired as usual even in asleep mode (anyway, it seems that applications does not use to use this lock too often, so the battery should not became an issue).

Installation
  1. Download and install Xposed framework
  2. Then install Wi-Fi Deep Sleep module and activate it
  3. Reboot
Usage

To make the mod to take an effect proceed to Settings -> Wi-Fi -> Advanced and make sure that:

  • Keep Wi-Fi on during sleep is either Only when plugged in or Never (increases data usage)
  • Scanning always available is turned off
The module provides no user interface, nor it runs any services in a background: only modifies a corresponding part of Android. You won't be able to notice it in the main menu or in a task manager. Think of it as a patch that can be turned on and off through Xposed installer.

Source
The mod is open source (with permissive MIT licence), the source code is available on my GitHub.


XDA:DevDB Information
Wi-Fi Deep Sleep, Xposed for all devices (see above for details)

Contributors
abusalimov
Xposed Package Name: ru.abusalimov.xposed.wifideepsleep

Version Information
Status: Stable
Current Stable Version: 1.0

Created 2014-05-16
Last Updated 2014-05-15
 

Kocane

Senior Member
Apr 29, 2012
1,680
309
Yes, unless there is a mobile network available. That is the mod would be more useful for a phone rather than for a tablet.

If mobile data is enabled while wifi is connected and running, then screen turns off and wifi goes to deepsleep, does it then use mobile data? I'm having issues sometimes where a "suspend_backoff" wakelock can keep my phone awake indefinitely and it's wifi related. Perhapsthis module could help.

Ah it took me until now to notice it's KK. No chance of a jb version?
 
Last edited:

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
If mobile data is enabled while wifi is connected and running, then screen turns off and wifi goes to deepsleep, does it then use mobile data? I'm having issues sometimes where a "suspend_backoff" wakelock can keep my phone awake indefinitely and it's wifi related. Perhapsthis module could help.

Yes, once Wi-Fi goes asleep, it instantly connects to use mobile data. This behavior is similar to default one, the only difference is that once it goes to sleep it will not wake up and try reconnect to Wi-Fi constantly, instead it will continue to use mobile data until you turn on and unlock the screen again.

Regarding a weird wakelock, the simplest answer is to try by yourself. Personally I got rid of "wlan_rx_wake" locks (drastically though not completely). I guess this depends on a device.
 

verynuclear

Senior Member
Aug 24, 2010
1,032
296
UAE
Great module
I was looking for something like this great idea.
Thanks a lot.

Sent from my HTC One using Tapatalk
 

robneymcplum

Senior Member
Oct 22, 2007
737
154
midlands
Probably a really stupid, obvious question but.....

If I turn wifi off manually, as I normally do leaving the house...etc... I assume this module will be of no use to me? Would only work if wifi was on, but not being accesed or used by me? Having wifi off means its off, right?
 

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
But if i was downloading a file?

This depends on a downloading application. Personally I was only concerned about Skype, which takes necessary locks and prevents this mod to turn off Wi-Fi during a call (unlike most of other apps that turn Wi-Fi off unconditionally).

Again, the mod itself doesn't make a big change to a default behavior. If you switch "Keep Wi-Fi on during sleep" to "Only when plugged in" or "Never" then downloading a file will or will not be interrupted regardless whether you have this mod installed or not. Try the default behavior without the mod to see if downloading will go on after the screen is switched off (plus about 15 minutes timeout). If everything's OK, then installing the mod shouldn't make if worse (it will however prevent an app from using Wi-Fi to download a new file by itself during the night after Wi-Fi goes asleep).
 

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
Probably a really stupid, obvious question but.....

If I turn wifi off manually, as I normally do leaving the house...etc... I assume this module will be of no use to me? Would only work if wifi was on, but not being accesed or used by me? Having wifi off means its off, right?

Yes, you're right. The mod only affects a code which come into play when Wi-Fi is switched on manually (see also "Usage" for necessary settings).
 

Shels

Senior Member
Aug 11, 2012
501
105
Will this mod work with touchwiz kit Kat?

Sent from my SGH-I747 using XDA Premium 4 mobile app
 

Creed0

Member
Nov 21, 2013
34
3
So I've had the wlan Rx wake lock for some time now and am really blooming forward to this fixing it. However once I enabled this module my drain got worse and I made the WiFi setting changes..
5ehysyby.jpg
ype3e5y6.jpg


Sent from my Nexus 5 using Tapatalk
 
  • Like
Reactions: abusalimov

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
So I've had the wlan Rx wake lock for some time now and am really blooming forward to this fixing it. However once I enabled this module my drain got worse and I made the WiFi setting changes..

Thank you for reporting, I'll try to investigate this. This is weird though, I didn't experience anything like this on my Nexus 5. Does this battery drain remain even after rebooting?
 

Creed0

Member
Nov 21, 2013
34
3
Well I rebooted after enabling the module. And I'm not sure if these would interfere but I'm running the Franco kernel and had the pia VPN app running during the log above. The only reason the battery lasted for 16 hours or so is because I have WiFi-o-matic auto switching off WiFi overnight.

Sent from my Nexus 5 using Tapatalk
 

abusalimov

Senior Member
Mar 27, 2014
59
68
34
St. Petersburg
Well I rebooted after enabling the module. And I'm not sure if these would interfere but I'm running the Franco kernel and had the pia VPN app running during the log above. The only reason the battery lasted for 16 hours or so is because I have WiFi-o-matic auto switching off WiFi overnight.

Sent from my Nexus 5 using Tapatalk

Ah, wait, it seems that I've found a suspicious piece of code that I might miss to handle properly. But it is only responsible for updating battery stats, not for real battery consumption. I'll fix it soon.

BTW I use franco kernel too, but this can't be related to the issue. Thanks for the info though. ;)

P.S. I'm not sure how it will work with WiFi-o-matic, the mod is designed to work with stock Wi-Fi management (no apps).
 
Last edited:
  • Like
Reactions: Creed0

Top Liked Posts

  • There are no posts matching your filters.
  • 13
    Only for Android KitKat.

    Once installed this mod prevents Wi-Fi from waking up during device sleep mode and when you turn on the screen without unlocking it (to look at the clock, for example).

    Background

    Normally Wi-Fi can be awakened and kept on due to Wifi locks held by certain applications that often use to abuse this opportunity. This results in Wi-Fi being turned on over up to the half of the total sleep time (or even more) which in turn of course eats the battery. Another issue is that once turned on by a single application it notifies and awakes lots of other apps that may start, for example, their heavy synchronization tasks, etc., making everything even worse.

    Auto Wi-Fi apps

    Nevertheless, Wifi lock is a good mechanism when used carefully, and generally it should be respected when deciding whether to switch Wi-Fi on and off. This becomes a problem for most of Wi-Fi management apps found in Play Market: they can switch Wi-Fi off in the middle of a Skype call just because the screen was turned off.

    The solution

    This mod alters a system state machine responsible for managing Wi-Fi so that once put to sleep it can not be woken up by any application that requests a lock. Wi-Fi is only put asleep when no application holds a lock. That is it doesn't cancel locks held already, but once all of them are gone, no one else is able to aquire a new lock until the screen is turned on and unlocked. This doesn't apply to special high performance Wifi lock, it still can be aquired as usual even in asleep mode (anyway, it seems that applications does not use to use this lock too often, so the battery should not became an issue).

    Installation
    1. Download and install Xposed framework
    2. Then install Wi-Fi Deep Sleep module and activate it
    3. Reboot
    Usage

    To make the mod to take an effect proceed to Settings -> Wi-Fi -> Advanced and make sure that:

    • Keep Wi-Fi on during sleep is either Only when plugged in or Never (increases data usage)
    • Scanning always available is turned off
    The module provides no user interface, nor it runs any services in a background: only modifies a corresponding part of Android. You won't be able to notice it in the main menu or in a task manager. Think of it as a patch that can be turned on and off through Xposed installer.

    Source
    The mod is open source (with permissive MIT licence), the source code is available on my GitHub.


    XDA:DevDB Information
    Wi-Fi Deep Sleep, Xposed for all devices (see above for details)

    Contributors
    abusalimov
    Xposed Package Name: ru.abusalimov.xposed.wifideepsleep

    Version Information
    Status: Stable
    Current Stable Version: 1.0

    Created 2014-05-16
    Last Updated 2014-05-15
    2
    Probably a really stupid, obvious question but.....

    If I turn wifi off manually, as I normally do leaving the house...etc... I assume this module will be of no use to me? Would only work if wifi was on, but not being accesed or used by me? Having wifi off means its off, right?

    Yes, you're right. The mod only affects a code which come into play when Wi-Fi is switched on manually (see also "Usage" for necessary settings).
    1
    Interesting. I assume this would mean no push notifications, etc.

    Yes, unless there is a mobile network available. That is the mod would be more useful for a phone rather than for a tablet.
    1
    So I've had the wlan Rx wake lock for some time now and am really blooming forward to this fixing it. However once I enabled this module my drain got worse and I made the WiFi setting changes..
    5ehysyby.jpg
    ype3e5y6.jpg


    Sent from my Nexus 5 using Tapatalk
    1
    Well I rebooted after enabling the module. And I'm not sure if these would interfere but I'm running the Franco kernel and had the pia VPN app running during the log above. The only reason the battery lasted for 16 hours or so is because I have WiFi-o-matic auto switching off WiFi overnight.

    Sent from my Nexus 5 using Tapatalk

    Ah, wait, it seems that I've found a suspicious piece of code that I might miss to handle properly. But it is only responsible for updating battery stats, not for real battery consumption. I'll fix it soon.

    BTW I use franco kernel too, but this can't be related to the issue. Thanks for the info though. ;)

    P.S. I'm not sure how it will work with WiFi-o-matic, the mod is designed to work with stock Wi-Fi management (no apps).