[APP][2.1+][15 Jun - 2.1] Better Wifi on/off

Search This thread

chamonix

Recognized Contributor
Nov 7, 2008
5,048
19,623
Berlin
Google Pixel 6 Pro
Good to know. Nice phone. The only problem I have is a battery. It drains 2-3% hourly on idle :(
Hate to see ~60% at the end of working day if I didn't use it much. I just started with this phone but my previous one (Droid X) had an excellent battery life so I never even had a need to use tools like BBS and Wi-Fi was always on at home.

I hope both of your tools together will help me to solve the battery life situation. :)
I'll post in BBS thread in case I wouldn't able to figure out it on my own but if you have some general observations/recommendations on SSIII settings please let me know.


On v. 0.1 app failed to turn Wi-Fi ON when I unlocked phone complaining that it was put OFF by user (and I didn't). Changed sleep policy to "Always" and it still complaining occasionally.
Happy to report that so far v. 0.2 works all the time. :)

---------- Post added at 04:24 PM ---------- Previous post was at 03:37 PM ----------


Just got the same situation again. App failed to return it to On state. Wi-Fi is OFF now. Here is what I see in a log:
2012-07-30 10:15:03 Received Broadcast ACTION_SCREEN_OFF
2012-07-30 10:15:03 scheduleOffAlarm called
2012-07-30 10:15:03 cancelAlarm
2012-07-30 10:15:34 cancelWifiConnectedAlarm
2012-07-30 11:08:30 Received Broadcast ACTION_SCREEN_ON
2012-07-30 11:08:30 cancelAlarm
2012-07-30 11:08:30 scheduleWifiConnectedAlarm called
2012-07-30 11:08:32 Received Broadcast ACTION_USER_PRESENT
2012-07-30 11:08:32 cancelAlarm
2012-07-30 11:08:32 scheduleWifiConnectedAlarm called
2012-07-30 11:09:02 cancelWifiConnectedAlarm

How can I put in a log everything that is on app console?
Not sure what could put Wi-Fi OFF. I'm using Llama to identify that I'm Home and Wi-Fi should be On. Llama still shows I'm Home.
Any idea?

You could post a logcat, it contains the same info and more.
What I'd be interested in:
I assume the case you talk about is at 11:08. Have you enabled Wifi to stay on only if a connection could be established (means your phone has a valid IP) and if yes, did the phone get one (logcat will tell us that). Please also tell me what version you are on.
I have added an issue as it seems that not all actions are in the on-screen log.
Edit: that's issue #5 on github
 
Last edited:

alexinna

Senior Member
Nov 27, 2010
150
56
You could post a logcat, it contains the same info and more.
What I'd be interested in:
I assume the case you talk about is at 11:08. Have you enabled Wifi to stay on only if a connection could be established (means your phone has a valid IP) and if yes, did the phone get one (logcat will tell us that). Please also tell me what version you are on.
I have added an issue as it seems that not all actions are in the on-screen log.
Edit: that's issue #5 on github

1. Yes I was referring to 11:08.
2. "Have you enabled Wifi to stay on only if a connection could be established ..." Yes
3. I can't re-create the same situation. v. 0.2
4. logcat for working case attached

My understanding that I don't need Llama any more to manage Wi-Fi On at Home and Off if not. This app will do it for me every time I lock/unlock the screen. In my case I'm only using Wi-Fi at home so no need to check it anywhere else but it's not possible yet until cell location will be implemented. Is this a correct understanding?
 

Attachments

  • betterwifionoff_logcat.txt
    3.3 KB · Views: 8
Last edited:

chamonix

Recognized Contributor
Nov 7, 2008
5,048
19,623
Berlin
Google Pixel 6 Pro

yhrn

Senior Member
Mar 25, 2011
527
339
Stockholm
Sweet!
Just installed and will give more feedback later. The one thing I know already is that the planned "whitelist AP" feature is a must for me. My home wifi is very battery friendly and I want several scheduled things to happen during the night, e.g. sync Titanium Backup to Dropbox, even if the phone is not plugged in.
 
  • Like
Reactions: chamonix

Edwrib

Senior Member
Sep 22, 2010
427
43
Sorry, could you elaborate a little?

I would like to keep my WiFi running faster as possible, without need to be plugged in charger.

Normally I do this with any other app that have wifi-lock, like unified remote, I keep them running while I need WiFi fast with screen off:
bb161065-2d76-8914.jpg
 
Last edited:

chamonix

Recognized Contributor
Nov 7, 2008
5,048
19,623
Berlin
Google Pixel 6 Pro
I would like to keep my WiFi running faster as possible, without need to be plugged in charger.

Normally I do this with any other app that have wifi-lock, like unified remote, I keep them running while I need WiFi fast with screen off:
bb161065-2d76-8914.jpg

I will need to investigate on that. I don't understand what a wifi lock can be or how it can be different from a wakelock: either the phone is prevented from sleeping and that is a wakelock or it sleeps and then the cpu is stopped so there is no way any data tranfer can occur. Of course I could add a wakelock to stick even if the phone is unplugged but then I wonder what even should turn if off.
 

Edwrib

Senior Member
Sep 22, 2010
427
43
I will need to investigate on that. I don't understand what a wifi lock can be or how it can be different from a wakelock: either the phone is prevented from sleeping and that is a wakelock or it sleeps and then the cpu is stopped so there is no way any data tranfer can occur. Of course I could add a wakelock to stick even if the phone is unplugged but then I wonder what even should turn if off.

Look into this: http://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html

Note that WifiLocks cannot override the user-level "Wi-Fi Enabled" setting, nor Airplane Mode. They simply keep the radio from turning off when Wi-Fi is already on but the device is idle.
 
  • Like
Reactions: chamonix

chamonix

Recognized Contributor
Nov 7, 2008
5,048
19,623
Berlin
Google Pixel 6 Pro

Ok I got it. It makes sense and I will change the wakelock I use currently
Code:
PowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, some-name);
to a Wifilock.

I understand it will be released whenever Wifi is turned off or if the user releases it (I need a botton for that).

Now it brings me to this feature request: https://github.com/asksven/BetterWifiOnOff/issues/2

It would be great if I could detect if there is another WifiLock before turning off Wifi but at least the public API does not allow that. On the other hand looking at http://grepcode.com/file/repository.../4.0.4_r1.2/android/net/wifi/WifiManager.java

I found a member mActiveLockCount that is incremented/decremented when creating/releasing locks. I love reflections and it shouldn't be that hard to read out that private member and decide to set an alarm for checking again and not turn off Wifi straight away. Doing so and assuming the app needing Wifi sticks to the conventions and holds a Wifi lock it won't be interrupted by BetterWifiOnOff.

I hope this makes sense :)
 

Edwrib

Senior Member
Sep 22, 2010
427
43
Ok I got it. It makes sense and I will change the wakelock I use currently
Code:
PowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, some-name);
to a Wifilock.

I understand it will be released whenever Wifi is turned off or if the user releases it (I need a botton for that).

Now it brings me to this feature request: https://github.com/asksven/BetterWifiOnOff/issues/2

It would be great if I could detect if there is another WifiLock before turning off Wifi but at least the public API does not allow that. On the other hand looking at http://grepcode.com/file/repository.../4.0.4_r1.2/android/net/wifi/WifiManager.java

I found a member mActiveLockCount that is incremented/decremented when creating/releasing locks. I love reflections and it shouldn't be that hard to read out that private member and decide to set an alarm for checking again and not turn off Wifi straight away. Doing so and assuming the app needing Wifi sticks to the conventions and holds a Wifi lock it won't be interrupted by BetterWifiOnOff.

I hope this makes sense :)

Make sense and anxious to test :)
 

Top Liked Posts

  • There are no posts matching your filters.
  • 159
    Better Wifi on/off is the latest creation of project better. It is an agent managing your Wifi state based on heuristics (set of rules).

    This app aims at giving you the control of the Wifi state, optimizing your battery life without losing on user experience.

    Better Wifi on/off releases are available from Google Play. Development versions will be made available on xda for testing new features / fixes.
    chart


    The app is free, fully featured with ads.
    If you want to support me and/or get rid of the ads you can purchase a "support-the-dev" version on google play.

    What is the motivation behind controlling Wifi?
    On paper Wifi is less power hungry than 3G but... some apps behave differently when Wifi is on (DropBox / Google+ uploads, Google Maps location caching), the well known wlan_rx kernel wakelock is a symptom of wakeups caused by uncontrolled Wifi hotspots, the Wifi sleep policy is not working consistently and does solve all problems.

    Settings to control Wifi
    The preferences allow you to control Wifi.

    The basic rules for keeping Wifi on / turning Wifi off are (will vary based on your settings):

    When device is turned on Wifi stays on if: "network is connected" AND "the access point is whitelisted" && "wifi is not caged (a connection to google.com can be made)"
    When screen goes off Wifi stays on if: "phone is in call" OR "network activity was detected" OR "tethering is on" OR "wakelocks from other apps using network were detected"

    There are of course plenty of settings to change that behavior like e.g. keep Wifi on if connected to A/C, leave Wifi on as long as connected to a whitelisted SSID.

    Sources
    This project is open source und the Apache license. Please feel free to browser the repo, review, fork it as you like: https://github.com/asksven/BetterWifiOnOff

    Bugs / Feature requests
    Open bugs and feature requests can be found on github here: https://github.com/asksven/BetterWifiOnOff/issues

    If you want to report a bug you can to it there but also simply post it here, I'll take care of documenting it and reply with the issue number for an easier tracking.

    Changelog:
    V.2.1
    - no changes from RC3

    V.2.1RC3
    - updated russian translation
    - added more logging on detected connected SSIDs

    V.2.1RC2
    #120: a hopefully better fix for cage check timings
    #125: added a pref for leaving wfi on when screen goes off but a connection is active

    V.2.1RC1
    Added direct link to gplay from main screen

    V.2.1B3
    #120: start thread for cage check earlier (at wifi on)
    Added timed checks
    Loading application whitelist is asynchronous

    V.2.1B2
    #115 threaded cage check
    Added more logging to solve the "alarm: null" error
    Updated russian language file
    Added timestamps to logcat output

    V.2.1B1
    #115: better cage detection
    #116: inconsistent messages when enabling/disabling from the widget
    #117: inconsistent plug/unplug event messages
    #119: null pointer exception with message alarm: null
    Fix for detection support the dev version


    Older changelogs


    V.1.3.0.2
    #92: enable/disable messages are shown multiple times and are not consistent to the user events

    V.1.3.0.1
    #91: Wifi should be turned off when screen is off and whitelisted a/p gets disconnected

    V.1.3.0.0 on Google Play
    No changes from latest RC
    V.2.0
    Merged to master

    V.2.0RC8
    #112: A better fix for donation detection


    V.2.0RC7
    #112: Fixed donation detection
    ActionBar style for pre-ICS phones

    V.2.0RC6
    #110: fixed CDMA cell collection

    V.2.0RC5
    #104: added share/save feature
    #105: handle CDMA cells
    #106: event log on whitelist shows %s instead of real value
    #107: added "clear cell log"
    #108: null pointer is cellinfo is null
    #109: blank SSID causes the A/P to be handled as whitelisted

    V.2.0RC4
    #103: fixed issue with unfinished database transation
    Removed pull-to-refresh as no longer maintained
    Optimized dialogs

    V.2.0RC3
    #11: added cell tower awareness and rule to turn Wifi on only if connected of known cell
    #102: app wihtelist does not keep checked apps

    V.2.0RC2
    #98: add check for whitelisted app: when running Wifi will not be turned off

    V.2.0RC1
    Uses ActionBarSherlock for same UX on all android versions
    Use Pull-to-Refresh to update list
    #95: enabling with widget turns wifi on
    #96: avoid scheduling wifi off when screen goes off but wifi is off already
    #100: preference to select between light and dark theme
    Added russian

    V.1.3.0.0RC2
    #90: wrong message when user disables/enables processing by tapping the widget

    V.1.3.0.0RC1
    #88: When disregard airplane mode is enabled wifi is not turned on when screen is turned on
    #89: disabling / enabling handling based on user action on wifi outside of BWOF should be logged
    New readme and rate dialogs

    V.1.2.0.0
    No change from RC1

    V.1.2.0.0RC1
    #82: pref to re-enable BWOF when Wifi is turned on manually
    #84: conneting power does not respect airplane mode
    #85: when pref is undefined turning screen on enables wifi even if this action is set on unlock

    V.1.1.1.0
    Fixed various FC conditions from logs/gplay dumps

    V.1.1.0.1
    #83: potential FC when opening preferences

    V.1.1
    No change. Grab it from Google Play

    V.1.1RC2
    no changes, done all the merging and prepared for release

    V.1.1RC1
    #39: advanced pref to connect to best available network
    #80: make sure to always cancel pending alarms when screen is turned on
    #81: allow to disable Wifi on function completely

    V.1.1B3
    #77: widget bg is not 100% transparent
    #78: screen on/unlock should always make sure that pending alarms for Wifi-off are canceled
    #79: losing connection to access point should never cause handling to get disabled, only user turning Wifi off

    V.1.1B2
    #19: disable processing when user turns Wifi off using the settings
    #70: add second URL for cage detection check
    #76: fixed API returning quoted SSIDs (bug found on 4.2)
    Compiled with new SDK

    V.1.1B1
    #69: locale/tasker plugin to enable/disable processing
    #71: reduce event logging
    #73: fixes for french
    #74: widget to control processing (enable/disable)
    #75: pref to ignore airplane mode and still enable/disable Wifi

    V1RC9
    #68: fixed cage detection

    V1RC8
    #67: fixed SQLite exception and missing perm

    V1RC7
    #65: respect airplane mode for all screen events

    V1RC6
    #61: fixed event log sorting to DESC
    #62: whitelist shows quotes around some SSIDs
    #63: inconsistent placement of pref "if plugged" between simple and expert mode prefs
    #64: changes in SSID whitelist are not reflected immediately

    V1RC5
    New fix for not always visible event log (is not persisitent)
    Check for turning Wifi off now goes on every 15 minutes instead of stopping after 5 retries (needed for #51)
    #51: rule for leaving Wifi on when screen goes off and SSID whitelisted
    #57: fixed whitelist detection not working in RC4
    #58: fixed whitelist prefs for post-GB devices
    #59: encoding in pref for network activity
    #60: SSID should show configured and not available SSIDs

    V1RC4
    #51: added rule to not turn Wifi off when screen goes off but a whitelisted SSID is connected to (pref)
    #54: Alarm should go on every 15 minutes in order to disconnect when whitelisted SSID is not connected anymore
    #55: respect airplane mode (do nothing if detected)
    #56: reordered prefs by rules for leaving wifi on "when screen on" and "when screen off"

    V1RC3
    #50: Wifi off delay labels were misleading
    #52: whitelist is no multi select list on SDK >= 11
    #53: do not check wakelocks when wifi is turned off as a result of "leave Wifi on" rules

    V1RC2
    #49: added perm to read logs (pre JB)

    V1RC1
    Cleaned up home screen, moved "disable" to (advanced) prefs

    V0.10.1
    #48: removed 'grep' command from logcat

    V0.10
    #41, 43: option to save preferences / logcat as debug info
    #42: repertoed typos
    #44: added simple and expert preferences
    #45: removed own logfile

    #46: removed not requires prefs: leave on if in call and if tethering are both always handled

    V0.9
    #40: don't turn Wifi off is Wifi tethering is active
    Added german and french translations
    V0.8.1
    #31: wifi goes off when unplugged but screen is on
    #32: calling the app from notification does not show even log
    #33, 35: make pref labels consistent
    #37: alarm for turning Wifi off should not obcess
    Fix for Wakelock detection

    V0.8
    #36: added wakelock detection to keep Wifi on when background apps (e.g. streaming) are running

    V0.7
    #29: a delay of 0 skips some checks before turning Wifi off
    #30: fixed binder error
    Added better network activity detection before turning Wifi off (besides download manager, see preferences)

    V0.6.1
    #27, #28: added more logging / event logging

    V0.6.
    Added icons to action bar (ics+)
    #17: keep wifi active when screen goes off and downloads are running or queued
    #26: keep wifi active when screen goes off and in a call

    V0.5.
    #20: (another attempt to fix) fast off/on causes Wifi to be turned off be not canceled alarm
    #25: editing SSID whitelist causes the correct connection to be re-validated (after the configured timeout)

    V0.4.1.0
    #21: Wifilock checkbox on main screen is not sticky
    #22: Broadcast handler is not allowed to send events to Service
    #23: Wifilock pref caused FC
    V0.4.0.1
    #20: fast off/on causes Wifi to be turned off be not canceled alarm

    V0.4.0
    #8: Wifilock when connected and permanent
    #9: option to stay on only if connected to a whitelisted SSID
    #13: add Wifi power management: high perf Wifilock
    #15: fixed bug not disabling all functions

    V0.3.1
    #7: fix for FC condition on punplug

    V0.3
    #5: not all actions are documented on screen
    #6: option to hold wakelock during plugged to prevent the phone from sleeping

    V0.2
    #1: removed preference "on only if previously on": far too complex to explain
    #3: added a preference to disable the handling
    #4: preference to leave Wifi on when screen goes off but phone is on charger
    V0.1
    - initial beta release
    10
    Release 0.8.1

    Last release is up after lots of testing on wakelock detection and it now should work. Make sure to disable network traffic detection for testing as having both on may give you a hard time understanding what is going on.
    Other fixes are included too, see post #1 for complete list.

    Please let me know if you see a need for network activity detection now that wakelock detection works. I feel it's not required anymore and too complex in regards to buffering and other caching mechanisms and would like to remove it if it's not vital to anyone.

    I making a feature freeze on 0.8.1 (minus the network activity detection if you agree) and prepare for a 1.0 to be released to google play (UI polish, translations, usability). Once done I will go on with the other feature requests in a release pace of about 1 release per month as I usually do.

    I keep my word and BetterWifiOnOff will stay free with ads but fully featured. There will be a "support the dev" version for 1 EUR turning off ads but without feature enhancement.

    Suggestions are as always welcome
    10
    Release 0.9

    This is the last release till 1.0 to be released to google play. From now on I'll freeze the features till 1.0 and focus on bugfixing and a few UI things.

    Changelog is in post #1
    9
    2.0RC3

    New version is up: fixed app whitelist and introduces cell location awareness for optionally only turning on wifi when the cell id is known.

    Feel free to add your ideas on how we could use the location awareness for optimizing BWOF
    8
    RC1

    Release is now feature comlete. First RC is up. See post #1 for changeog