Managing wakelocks

Post your questions and help other users.

Moderator: Martin

Post Reply
Mubli
Posts: 2
Joined: 08 Apr 2014 14:31

Managing wakelocks

Post by Mubli » 08 Apr 2014 14:57

First off, kudos to the developers. This product is AWESOME! So incredibly powerful, flexible, and most important intuitive. I had a stint as a Microsoft Office/VBA developer for several years which I enjoyed immensely but have since moved on to more manager type stuff and using this scratches that itch nicely.

On to the real question. I have developed a set of flows that will turn mobile data, wifi, and auto sync on and off based on screen state in conjunction with global variables I have set to determine what states to leave the data in when the request comes in to turn on and off. The goal is to reduce power consumption. They are leave mobile data on/off and wifi on/off/if connected. The way it is constructed is the screen on and off triggers are both in the same flow. Then a screen on condition sends it down 1 of 2 paths (on or off obviously). Then at the end it calls a separate flow that actually manages the data (so it can be called from multiple flows) based on a local variable set during the screen trigger. So walking down the on flow for example:

Flow: Screen
Trigger: Display state on
Condition: Screen on = True
action set Autosync State = On
action script datastate (local variable) = on
action execute Flows = Manage data

Then the manage data flow takes over and:

Flow: Manage data
condition expression datastate = on
condition Wifi connected = false proceed (otherwise its an end point)
action set mobile data = on
action set wifi = on
condition if global variable leave wifi on = on = false (so true is an end point)
action sleep for global variable wifi connect time and set to not keep awake (currently 30 seconds to allow to connect)
condition wifi connected = false
action set wifi state off

In the screen trigger there is a similar off flow and in the manage data flow there is a similar off branch.

My question is when looking at better battery states and wakelock detector it indicates these two flows (screen & manage data) are pretty big consumers. To give you an idea using wakelock detector from when I toggle the screen off and back on it registers about 5-6 seconds of CPU wakelock between running through this chain twice (one for off and one for on). This makes some sense since they trigger every time I turn the screen on and off but I'm now wondering if its actually consuming more power to run the flows than it would to just leave the data on. I took the tact that consolidating flows into reusable functions would be better but maybe its more power efficient to make each flow have the absolute minimum steps and have more flows. I.e. make screen on and off separate and have the data handling actually in each one? Or does anyone have a suggestion for a better way to attack this? If easier I can just post the flows but will have to wait till am at home to be able to save them off and load since I am at work.

Thanks

Mubli
Posts: 2
Joined: 08 Apr 2014 14:31

Re: Managing wakelocks

Post by Mubli » 09 Apr 2014 20:01

I decided to re construct my design and so far it seems to be making a difference. I don't have enough total time yet to be sure but so far looks promising. I moved the handling of wifi off into its own flow based on enabled and disconnect triggers. So when wifi is enabled if it doesn't connect in my global variable timeout window it will disable. Same thing for disconnecting. It will also disable data if wifi connects. I also split out my manage data flow into 2. One for on and one for off which also allowed me to shorten my screen on and off flows. So it seems that maybe having more shorter flows is looking more battery efficient than longer but fewer. I also have a hypothesis that triggers firing is better than a condition causing a flow to fire. Makes reuse of flows a little more complex but worth it if the battery use is less.

Post Reply