Post Reply

[FIX] For MANY scripts broken due to missing wait_for_fb_sleep/wake files.

OP zeppelinrox

17th June 2014, 02:42 AM   |  #1  
zeppelinrox's Avatar
OP Senior Member
Flag IN THE FREAKIN' OP
Thanks Meter: 21,307
 
9,313 posts
Join Date:Joined: Dec 2010
Donate to Me
More
I originally found the fix in the SuperCharger Thread when I found that my Flush-O-Matic script wasn't working properly on my Sony Z1.

See original posting here.
Quote:
Originally Posted by zeppelinrox

Hey I realized yesterday that Flush O Matic doens't work properly on newer kernels.
Well it works, but it doesn't wait for the screen to go off before flushing.

A little googlie told me that the newer kernels no longer have the /sys/power/wait_for_fb_sleep file.
Normally, FOM will try and read it's contents (but it's unreadable) and it just hangs until the device goes to sleep.
When it goes to sleep, that file can be read and the script gets "unhung" and flushes.
And when the file is missing, well FOM will just spit out errors (check the log) and dump cache without uh... waiting for the fan to be turned on...

BUTT (yeah, thats a big butt!) I fingered out another way for newer kernels... heh.
Check it via PC... with the screen on do this

Code:
adb shell
su
while [ "`cat /sys/class/graphics/fb0/dynamic_fps`" ]; do sleep 1; done; echo " OK Flush Time!"
Who's your daddy!? LOL

While the screen is on it should hang there until you turn off the screen.
When the screen goes off, it will pronounce what "time" it is...

I'll probably do sleep 10 instead of sleep 1 tho to minimize battery suckage.

This fix would be applicable to various scripts on xda that will get outdated due to the missing wait_for_fb_sleep/wake files on some device/kernel combinations.
Currently effected hardware, that I'm aware so far: some Sony, Moto and Nexus devices using kernel version 3.3 or above.

These scripts change things or do things depending on whether the screen turns off or turns on.
Examples are cpu governor scripts or other screen state scaling scripts.

As mentioned above, it had effected my FOM script which dumps caches at a user defined interval.
However, when the time is up, it will actually wait until the screen is off if the screen happens to be on at the time.

So if you have a misbehaving script due to the missing /sys/power/wait_for_fb_sleep/wake files, you should have 2 other files that you can use.

1. /sys/class/graphics/fb0/dynamic_fps
2. /sys/class/graphics/fb0/show_blank_event

File contents with screen off:
Code:
shell@C6906:/ $ cat /sys/class/graphics/fb0/dynamic_fps
shell@C6906:/ $ cat /sys/class/graphics/fb0/show_blank_event
panel_power_on = 0
shell@C6906:/ $
File contents with screen on:
Code:
shell@C6906:/ $ cat /sys/class/graphics/fb0/dynamic_fps
60
shell@C6906:/ $ cat /sys/class/graphics/fb0/show_blank_event
panel_power_on = 1
shell@C6906:/ $
So when the screen is off, dynamic_fps is empty but has a value (60 in my case) when the screen is on.

I preferred to take advantage of that file.

However some may like to use the contents of show_blank_event and check whether panel_power_on = 0 (off) or panel_power_on = 1 (on).

Of course, a script will have to check and decide whether to use the wait_for_fb_sleep file or use the new way.

So a fixed script will look something like:
Code:
if [ -f "/sys/power/wait_for_fb_sleep" ]; then
     echo "Android is now `cat /sys/power/wait_for_fb_sleep`!"
else while [ "`cat /sys/class/graphics/fb0/dynamic_fps`" ]; do sleep 10; done
     echo "Android is now sleeping!"
fi
So if that code is ran when the screen is on, when the screen is off, the output would be Android is now sleeping! and it won't matter if you have the wait_for_fb_sleep file

Alternately, to do something when the screen turns on...
Code:
if [ -f "/sys/power/wait_for_fb_wake" ]; then
     echo "Android is now `cat /sys/power/wait_for_fb_wake`!"
else while [ ! "`cat /sys/class/graphics/fb0/dynamic_fps`" ]; do sleep 10; done
     echo "Android is now awake!"
fi
Of course, when the screen comes on, the output will be Android is now awake!

I used sleep 10 so that it doesn't do any needless work.
Of course sleep 1 would give an instant reaction but isn't very battery or cpu friendly.
You can decide for yourself how long is a good sleep interval between checks.

Anyhow, hope that helped
Last edited by zeppelinrox; 17th June 2014 at 02:58 AM.
The Following 5 Users Say Thank You to zeppelinrox For This Useful Post: [ View ]
17th June 2014, 03:18 AM   |  #2  
wkobaint's Avatar
Senior Member
Thanks Meter: 31
 
229 posts
Join Date:Joined: Feb 2013
Nice! Will try on my VU

sent from my LG-P895 using Tapatalk bajakan
17th June 2014, 08:36 AM   |  #3  
Madaditya's Avatar
Recognized Themer
Flag No where
Thanks Meter: 998
 
947 posts
Join Date:Joined: Jul 2012
More
Thank you
I wanted this to implement a small idea of mine ,also scanned through the 11k+ lines from supercharger script but couldn't find screen off thingy
Yeah,finding a small line in FastEngineFlush.sh also was hard
But this post helped!

The reason why your are called a XDA Scripting Genius!
Really useful!
The Following User Says Thank You to Madaditya For This Useful Post: [ View ]
17th June 2014, 11:01 AM   |  #4  
zeppelinrox's Avatar
OP Senior Member
Flag IN THE FREAKIN' OP
Thanks Meter: 21,307
 
9,313 posts
Join Date:Joined: Dec 2010
Donate to Me
More
Quote:
Originally Posted by Madaditya

I wanted this to implement a small idea of mine ,also scanned through the 11k+ lines from supercharger script but couldn't find screen off thingy
Yeah,finding a small line in FastEngineFlush.sh also was hard
But this post helped!

The reason why your are called a XDA Scripting Genius!
Really useful!

Whats your idea?

And yeah, even the flush script is rather complex lol
17th June 2014, 11:23 AM   |  #5  
Madaditya's Avatar
Recognized Themer
Flag No where
Thanks Meter: 998
 
947 posts
Join Date:Joined: Jul 2012
More
Quote:
Originally Posted by zeppelinrox

Whats your idea?

And yeah, even the flush script is rather complex lol

LOL yeah.
Wanted to make a background script that turns your data connection off on screen off + one minute and enables data on screen on.
Something close to Stamina mode in Sony Devices.
Reason,i face considerable battery drain on Custom roms,and a xperia user always misses Stamina mode
Last edited by Madaditya; 17th June 2014 at 11:26 AM.
17th June 2014, 01:46 PM   |  #6  
zeppelinrox's Avatar
OP Senior Member
Flag IN THE FREAKIN' OP
Thanks Meter: 21,307
 
9,313 posts
Join Date:Joined: Dec 2010
Donate to Me
More
Quote:
Originally Posted by Madaditya

LOL yeah.
Wanted to make a background script that turns your data connection off on screen off + one minute and enables data on screen on.
Something close to Stamina mode in Sony Devices.
Reason,i face considerable battery drain on Custom roms,and a xperia user always misses Stamina mode

Nice idea!

Whats the command to disable data?
17th June 2014, 04:19 PM   |  #7  
Madaditya's Avatar
Recognized Themer
Flag No where
Thanks Meter: 998
 
947 posts
Join Date:Joined: Jul 2012
More
Quote:
Originally Posted by zeppelinrox

Nice idea!

Whats the command to disable data?

svc data enable/disble

for wifi:

svc wifi enable/disable
The Following User Says Thank You to Madaditya For This Useful Post: [ View ]
17th June 2014, 11:12 PM   |  #8  
zeppelinrox's Avatar
OP Senior Member
Flag IN THE FREAKIN' OP
Thanks Meter: 21,307
 
9,313 posts
Join Date:Joined: Dec 2010
Donate to Me
More
Quote:
Originally Posted by Madaditya

svc data enable/disble

for wifi:

svc wifi enable/disable

Oh nice.

You learned me something lol

The Following User Says Thank You to zeppelinrox For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Software and Hacking General [Developers Only] by ThreadRank