yashsingh1/xdaforums huggingface dataset:
[Android Apps and Games] Pkt_Lnt:
Yes, your understanding it correct.

It works fine as wanted as long as I leave the "turn off with screen off" NOT checked. When I arrive home, I turn on the screen and get connected to my home ssid and then it stays connected.

It is the times during the day that it seems to be trying to connect to all other wifi networks out there that I am wanting to have more control options, and definitely turn wifi off with screen off.

Thanks for looking at this.
[Android Apps and Games] chamonix:
This is indeed a feature I have not though of: leaving Wifi on if a whitelisted access point is detected. To me it looks like there are two part to this:

- add 3) to not turn off Wifi if a whitelisted access point is connected to

- add some code handling the state change for losing the connection to this access point as Wifi must then finally be switched off (this can easily be done with the event handler that does loging right now (ConnectionStatshandler).

I have added that to #51.

The magic to turn on Wifi based on location would be part of #11.

Point 1: correct

Point 2: correct. Based on your comment below I have now renamed "Connection timeout" and moved it one level higher as it is used for both "leave on" and "turn off" rules

Point 3: correct for the first part but there is no check for wakelocks here. The handler is WifiConnectedAlarmReceiver and this handler checks if there is a connection at all, and if yes goes through the rules "whitelisted a/p", "caged". The first failing rule causes wifi to be turned off

Point 4: correct, the handler in that case is WifiOffAlarmReceiver

Point 5: correct. "In call" does nothing to wifi and does not check later again as going out of a call will turn the screen on again. "If activity" reschedules a check, "tethering does not". At that point and when the rules result in the decision that wifi sould be turned off the "wakelock" rule is checked (this is outside of the alarm handler and done in the service turning wifi off (SetWifiStateService) for specific reasons mentioned in the comments if of interest).

The repeated checks are done 5 times with increasing delays SetWifiStateService.scheduleRetryWifiOffAlarm).

I don't see the mix in the two set of rules that you mention but that's maybe because I am blinded by the code. If you still feel that way after reading my comments we should go on with this interesting discussion.

I have fixes the "connection timeout" inconsistency by moving the settings outside of the rules and changed its title/summary (#50).
[Android Apps and Games] chamonix:
The way your Wifi behaves when not connected is depending on the Wifi stack and on your kernel. Especially the may multicast and broadcast packets are handled are known causes for wakeups and one of the main reasons it is not a good idea to leave Wifi on all the time.

The IPs the log shows are in decimal form.
[Android Apps and Games] foosion:
I'm using stock Jelly Bean on a Galaxy Nexus.

The phone sitting there without me touching it, but with wifi on, usually uses about 0.7% per hour, give or take. I find this acceptable.

The log includes:

IP address assigned: 2013374656. Wifi is connected

Should this have decimal points (dotted quad)? When this line was generated, wifi was not connected and I was not near any router.
[Android Apps and Games] yhrn:
I checked the code some more and from what I can see both the WifiConnectedAlarmReceiver and the WifiOffAlarmReceiver triggers the SetWifiStateService to turn off wifi and there it looks to me like the wakelock check can stop wifi from being turned off regardless of who started the service. I'm very much prepared to be proved wrong here. Not used to android programming patterns and specific APIs and I'm also only reading the code not debugging. However, I think I also observed this behavior by starting to play music (to cause a wakelock), turning the screen off (for more than the wifi off delay) and back on and then seeing BWON logging that the whitelist check failed (this was expected as I had changed the whitelisted SSIDs) and then logging that wakelock had been detected so wifi was left on.

The behavior I describe above could be the desired one but to me the problem is that by just looking in the settings GUI (and not going through the code) it feels very difficult to understand what rule is applied when and how the different rules interact. For example, the connection, whitelist and cage rules are all applied shortly after unlocking the screen and all need to pass to keep wifi on but then the wakelock rule can override this so the full rule could be described something like this:

keepWifiOn = connected && whitelisted && notCaged || wakelocks

On the other hand when deciding to keep wifi on at screen off the logic seems to be something like:

keepWifiOn = inCall || networkActivitiy || tethering || wakelocks

To me this is not obvious from how the settings are organized. For example, the network activity setting feels like it belongs in the "Rules for turning wifi off" section and if the wakelock check really does work like I described above it could maybe be configured separately for the two checks, once where it is now and once in the "Rules for turning wifi off" section.

I hope this makes some sort of sense.
[Android Apps and Games] yhrn:
Hi again Chamonix,

After writing my previous post I continued thinking (it's true, really!) and i think I might finally have grasped your intentions with the two different checks. The first check goes something along the lines: "Ok, so I've turned on wifi a while ago - do I have a valid connection now? Otherwise I'm turning it off again." The second is more like: "Ok, so the screen has now been turned off, is something still going on? Otherwise I'm turning wifi off".

Not that complicated really :). However, if this is how it is intended I then think that the wakelock rule should be applied only during the second check (might already be the case if I can't read properly).

The one rule that doesn't fit clearly into either check is the whitelist rule as it doesn't really deal with checking if a connection is working and it doesn't really deal with anything that is going on but in my opinion it is more useful during the second check. To me it feels a bit hard to understand the use case for having it in the first check - if I don't want to be connected to some networks even when the screen is on why would I even have them configured in the system settings?

Anyways, I'm going to stop my ramblings now and wait for your feedback on these thoughts. If you do agree on some or most of the things I've written I have a few small ideas on how the expert settings view organization could be improved.
[Android Apps and Games] chamonix:
I told you I may be blind but of course you are right and it is a bug: the wakelock check in SetWifiState should only be checked for when Wifi goess off because screen went off but not when Wifi is turned off because no connection could be made (#53).

I will push a new RC once fixed that one and have added a selection screen for the whitelist (for SDK > 11).

I am really happy that you have detailed the processing and the rules that much, brought me to this inconsistency and wrote a nice summary that I will digest for the OP once released.

Of course your ideas are very welcome
[Android Apps and Games] chamonix:
Release 1.0RC3

New release is up with some fixed. See post #1 for changelog
[Android Apps and Games] Pkt_Lnt:
Still cannot get this app searching Play Store, tried name, then your name, then other dev apps under Better Battery Stats. I want to be ready when this goes Pro. Thanks for this update and to @yhrn for the contribution.
[Android Apps and Games] chamonix:
That's pretty normal as I haven't published to gplay yet. We are still in the RC cycle (pre release) and the pre and test releases are only on xda (true for the future as well).
[Android Apps and Games] Pkt_Lnt:
Ah, I must have gotten confused between BBS and this either here or Twitter about a release. I just searched and no mention, my bad.
[Android Apps and Games] chamonix:
Any feedback on RC3?
[Android Apps and Games] RovG:
Hi Chamonix,

I am still experiencing the problem of the wifi icon on the status bar not initially displaying or animating when BWON turns wifi on.

I was wondering if you could programtically trigger or force a refresh of the status bar/notification area when BWON turns wifi on. I also noticed that when the icon doesn't display Cool Tool shows 0 or N/A for wifi signal strength. That might be a way to programitically check if a status bar refresh is required. What are your thoughts?
[Android Apps and Games] bongster:
Hi there,

I really like your app.

I do not know if I'm the only one with this problem, but when I use the flight mode (turns all connections off) wifi turns on after reactivating the display.

It would be really great if you can add a rule to prevent this behavior.

Best,

Bongster
[Android Apps and Games] chamonix:
This behavior is indeed known but it's a bug in the way the notification bar does not seem to properly be listening to Wifi state changes. There is nothing I can do about that.
[Android Apps and Games] chamonix:
Good idea, I'll try to add that: https://github.com/asksven/BetterWifiOnOff/issues/55
[Android Apps and Games] jlv3:
I just installed it and will report back.

(I do wonder if this will be interfered with by the "turn wifi off" in Car Mode Settings)
[Android Apps and Games] patsmike:
Running fine. I had a little hiccup the other day where wifi didn't turn on after unlocking the phone, I'll see if I can reproduce it
[Android Apps and Games] jlv3:
I have noticed that sometimes when I open the app, there is no log displayed. If I open prefs and then back, I see the log data - sometimes going back hours, or sometimes with just "S/Logging Started" timestamped at that exact same instant. (Seems somewhat like the closed issue 32)

It took me a while to figure out why my wifi was going off even when on a whitelisted access point (because I had turn "off with screen off", as discussed in post 272 and in issue 51).
[Android Apps and Games] Pkt_Lnt:
Yes I wish the white list would override this when applicable, since do want the wifi off immediately in other situations.

-sent via Kindroid Jelly Fire Bean JB 4.1.1
[Android Apps and Games] yhrn:
I have been using it since it was published and I haven't had any problems. On the other hand, I haven't really tested properly either because I've been really busy with other stuff. I'll try to get around to at least test the wakelock fix the next couple of days.
[Android Apps and Games] sorcio91:
Hi, i use yor RC3 and all works fine, only a thing:

Ccan you increase the number of option for Delay time in "Rules for turning off wifi"? Like: 5/10/15 minutes for example.

And: can you make an option to remove notification in "foreground service" mode?

For me would be better, but...good work already :D
[Android Apps and Games] chamonix:
Release 1.0RC4

Added a few important features and resorted prefs for a better readability. Check post #1 for the full changelog
[Android Apps and Games] yhrn:
Here's some feedback on RC4:

The new organization of the rules is a massive improvement in my opinion (this is very similar to what I was going to suggest)

Whitelist for screen off (the new feature) seems to work well

Whitelist for screen on (the old feature) does not seem to work anymore (stays connected even if connected to non-whitelisted network). Note that I have not checked the code this time. I got this behavior when testing but I could be missing something here.

Wakelock check seems to work as expected (does not keep wifi from turning off with screen on but does so when turing off screen)

Whitelist is back to a simple text control. In RC3 I got a list of available Wifi networks with check boxes. Maybe this is on purpose? I thought it was a bit curious that the list contained the currently available networks rather than the remembered ones.

The '>' character in the network activity rule description is entity encoded - >

The changelog in the OP has bad formatting (massive problem for me :))

For me this version is extremely useful. The new "Check whitelist on screen off rule" makes it possible to configure BWON to behave more or less exactly the way I want it.

Thank you!
[Android Apps and Games] chamonix:
Thanks for the feedback!

I hotfixed the change log straight away!

The new categories from the prefs come from your previous post. As I plan to take this post 1:1 to the doc I thought that natural categories should be reflected in the prefs as well.

I have added #57, #58, #59 for whitelist rule / editing not working anymore as well as for the formating in prefs. The whitelist checked listbox should be there for post-GB devices and contain the whitelisted (remembered) and SSID that have a configured connection. I'll check why I broke this.
[Android Apps and Games] yhrn:
Hi again!

Just to clarify how I meant the whitelist dialog was populated with on RC3 for me (I'm on JB, by the way). If I remember correctly (and I'm pretty sure I do) it contained the currently whitelisted SSIDs as well as the SSID of all other networks in range (unchecked). What it did not contain was the SSIDs of networks that I had valid configuration for but that was not currently in range (this is what I meant with "remembered networks" in my previous post.)
[Android Apps and Games] chamonix:
Got it (and already fixed for next RC): #60
[Android Apps and Games] chamonix:
I just have a weird problem with quoted/unquoted duplicates the the screen for selecting the SSID whitelist. Once solved I'll upload RC5
[Android Apps and Games] igogold:
Can you add check is there assigned IP address if a wakelock is present?

When I was at home and had screen on and assigned IP I started poweramp music player. Then I locked screen and went to work. But wifi was on all this time. I think if phone disconnected from wifi it's need not to keep wifi on any more.

And I still have issue with log on main screen of the app. It's need to reopen app to get log on it.
[Android Apps and Games] jackhenry2012:
Nice app ^_^ i should download it
[Android Apps and Games] chamonix:
Disconnect from white listed SSID is properly handled in RC5 as well as event log. I have some tests running and will upload later today
[Android Apps and Games] igogold:
I have no any whitelisted SSID at all. I think it's because of wakelock detection, wakelock has more priority than disconnect from wifi network (lost IP).
[Android Apps and Games] chamonix:
In that case the next RC will help as it will not quit checking (previous version stopped after 5 retries). The alarm is triggered every 15 minutes and as long as the wakelock gets released properly wifi should be shut off.
[Android Apps and Games] chamonix:
Release 1.0RC5

New RC is up, check changelog in post #1
[Android Apps and Games] igogold:
Something wrong in non-expert prefs. It shows "If plugged in" in the section "Rules for leaving wifi on when screen is on". But in expert mode this setting in section "leave on if screen is off". And "Only if connected" doesn't displayed in non-Expert mode.

Also white listing works strange. If I mark saved but non current network as whitelisted and check "If connected to whitelisted" under "leave on if screen on" and unlock phone wifi connected and disconnected after 30 sec. It wrote in log: Access point is not whitelisted: turning Wifi off. Is it correct. I think If phone found whitelisted network it must stay connected even w/o IP address. But for not whitelisted network check another test (valid IP address).

BTW, wifi indicator is animated again! And event log loaded even on first run!

EDIT: It seems to wifi icon not animated more...

EDIT2: Reverse event log was more handy, imho. It's need scrolling to the end now, even after log refresh.
[Android Apps and Games] chamonix:
I'll check on the prefs. But why would you like to leave Wifi on if a connection was made but no IP was granted. That whould be the biggest drain (connection is maintained) without any use as without IP no way to use the connection.

I'll fix the reverted Event log (#61)
[Android Apps and Games] yhrn:
Hi,

Here's some feedback on RC5

#51 - Still works for me but I haven't tested the new "check every 15 min" thing to see if wifi is actually disabled when leaving a whitelisted network.

#57 - This one seems to be fixed - whitelist on screen on now seems to have the desired effect

#58 - Mostly fixed but there seems to be some quoting issue - existing, non-quoted entries are not matched with the quoted entries. See screenshot below. On the other hand, this seems to be more of an upgrade issue - if I select the quoted version and unselect the old unquoted ones, exit the app and go back in the list is only populated with the quoted entries.

#59 - Nice workaround ;). Just kidding - I agree it's better to write it out rather than using >= for non-programmer users.

#60 - Works

The eventlog seems to work perfectly for me now. In all other releases it's been very random if I saw anything there or not.

One thing though - it seems that configuration change sometimes do not take effect immediately. I often have to kill BWON in a task manager and then open it again. I've had this feeling for a while but as the eventlog was acting so erratically I couldn't be sure what the problem really was. However, in this release (with the eventlog fix) when testing the whitelist I could see with certainty that changes to the whitelist first had no effect but after me killing BWON and starting it again the new setting started to have effect. Not sure if this applies to the whitelist only or the settings in general.
[Android Apps and Games] chamonix:
Release 1.0RC6

New RC is up, see first post for changelog.
[Android Apps and Games] azrash:
Hi chamonix, thanks for another useful app after BBS, it definitely reduced my wlan_rx wakelock to a minimum.

One feature request, When I am on the move, I have to kill BWO's service or it'll turn on the wifi every time I unlock the phone. Is it possible to create a simple shortcut or widget that allows us to on / off BWO on the fly? It'll definitely reduce the wifi search overhead when users are on the move.

Thanks!
[Android Apps and Games] sorcio91:
Can you put more options in "Delay"? Like 5/10/15 minutes? I think it will be better!
[Android Apps and Games] bongster:
Hi again,

this morning I used the airplane mode again and wifi still turned on.

For me it looks like the rule works on display on but not when I unlock the phone. Here a screenshot.

Thank you very much!

Bongster
[Android Apps and Games] chamonix:
Confirmed (#65) and already fixed for next RC (coming right away)
[Android Apps and Games] chamonix:
Release 1.0RC7

New RC is up, fixing airplane mode
[Android Apps and Games] RovG:
Hi Chamonix,

With RC7, I have noticed the following in my logs:

10-13 22:37:20.210 E/ActivityManager(2175): 0.8% 13329/com.asksven.betterwifionoff: 0.4% user + 0.4% kernel / faults: 914 minor
10-13 22:37:56.495 E/BetterWifiOnOff.WifiConnectedAlarmReceiver(14652): An error occured receiving the alarmConnectivityService: Neither user 10241 nor current process has android.permission.CHANGE_NETWORK_STATE.
10-13 22:39:20.140 E/SQLiteDatabase(13329): close() was never explicitly called on database '/data/data/com.asksven.betterwifionoff/databases/betterwifionoff'
10-13 22:39:20.140 E/SQLiteDatabase(13329): at com.asksven.betterwifionoff.data.EventDBHelper.<init>(EventDBHelper.java:90)
10-13 22:39:20.140 E/SQLiteDatabase(13329): at com.asksven.betterwifionoff.data.EventDBHelper.getInstance(EventDBHelper.java:76)
10-13 22:39:20.140 E/SQLiteDatabase(13329): at com.asksven.betterwifionoff.data.EventLogger.addEvent(EventLogger.java:50)
10-13 22:39:20.140 E/SQLiteDatabase(13329): at com.asksven.betterwifionoff.data.EventLogger.addUserEvent(EventLogger.java:64)
10-13 22:39:20.140 E/SQLiteDatabase(13329): at com.asksven.betterwifionoff.handlers.ScreenEventHandler.onReceive(ScreenEventHandler.java:67)
[Android Apps and Games] chamonix:
Could you please provide a full logcat? From what I see that error occurs on a screen event (on, off, unlocked) but I can't reproduce. Also I'd like to know if there is something functionally going wrong. CHANGE_NETWORK_STATE is not supposed to be required as we have CHANGE_WIFI_STATE to turn Wifi on/off. Were you in airplane mode when this error occured?

you can add your info directly to the issue
[Android Apps and Games] RovG:
As requested log available at:

http://db.tt/uJmj3h5X

and no I wasn't in airplane mode. I think it is related to screen on and you should find it at about 22:19:57.640

HTH
[Android Apps and Games] chamonix:
Thanks for the feedback, I am studying the log right now. Two more question for a better understanding:

- what Android version are you on?

- did this error impact the functionality or did BetterWifiOnOff still work as expected eventhough the error occured?
[Android Apps and Games] chamonix:
Release 1.0RC8

New RC with fix for #67 is up.
[Android Apps and Games] Pkt_Lnt:
Just installed RC8, and it disconnects my home whitelisted wifi. I grabbed a screenshot and had to turn "if caged" off to stay connected. Also got a log.

http://db.tt/fLoWkT4g

Galaxy Nexus / Tapatalk 2
[Android Apps and Games] RovG:
Hi Chamonix,

I am on 4.0.3 (DXLPB) & Siyah 4.1.5. When the error occurs BetterWifiOnOff is unable to turn wifi on.
[Android Apps and Games] chamonix:
I hope last RC with the perm added fixes that

Mystery solved: that specific perm is related to the API requestRouteToHost that I used to check for caged networks. I'm working on a bug in that check and depending on the fix the perm may become obsolete again
[Android Apps and Games] chamonix:
Sorry but this log shows no activity from BetterWifiOnOff at all and the prefs show cage detection is off. Please post a log reproducing the error.

Edit: nvm, I was able to reproduce. Seems no-one has ever tested caged mode. Next RC will fix it: #68
[Android Apps and Games] Pkt_Lnt:
Try these:

https://www.dropbox.com/s/e89m6s8z9qu3x6y/betterwifionoff-2012-10-15_120325109.txt

https://www.dropbox.com/s/mz0njtrkxxd7b8t/betterwifionoff-2012-10-15_120527030.txt

SSID Whitelist doubled again

https://www.dropbox.com/s/jewomwyt9noepe6/2012-10-15 11.53.34.png

Screen capture of issue ignoring whitelist.

https://www.dropbox.com/s/jzui4crlznbicuz/2012-10-15 12.06.02.png

edit - oops missed your edit while gathering evidence. ;)

Also, the honor airplane mode was not working in RC 8 either, if that matters.

Thanks.
[Android Apps and Games] chamonix:
Cage is fixed but I can't confirm Airplane mode (tested it right now and evet log saying: Airplane mode on: do nothing).
[Android Apps and Games] Pkt_Lnt:
Just comparing screen shots of rc7 and rc8. 8 just kept turning off very quickly no matter what I tried in settings.

Galaxy Nexus / Tapatalk 2
[Android Apps and Games] chamonix:
The xage is a premium I am working on and have a fix in place.

I was mentioning not being able to reproduce the non respect of airplane mode (the second Screenshot is not in airplane mode)
[Android Apps and Games] Pkt_Lnt:
No airplane because rc8 kills wifi so fast and autoAP disconnects airplane.

https://play.google.com/store/apps/details?id=net.geekherd.autoap

You can see the AutoAP in the status bar, but the airplane is off since wifi is off. No where in the rc8 screen can you see any recognition that airplane is/was on, but it was.

Galaxy Nexus / Tapatalk 2
[Android Apps and Games] chamonix:
Release 1.0RC9

Fix for cage detection is up.

If someone still has problems with duplicated in the whitelist please send me a logcat (I added some more logging in that area to RC9)
[Android Apps and Games] pwvandeursen:
Hi,

been following the developments lately. I currently use Y5 but looking for something a bit better. One thing I am really missing is the possibility to integrate this with Locale and shut off wifi completely when needed. with Y5 it doesn't listen to locale, i.e. if in a profile wifi is off, Y5 will continue to switch.