Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,055 Members 47,175 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
zeppelinrox
Old
(Last edited by zeppelinrox; 17th June 2014 at 02:58 AM.)
#1  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21,210
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
Default [FIX] For MANY scripts broken due to missing wait_for_fb_sleep/wake files.

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 View Post
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
The Following 5 Users Say Thank You to zeppelinrox For This Useful Post: [ Click to Expand ]
 
wkobaint
Old
#2  
wkobaint's Avatar
Senior Member
Thanks Meter 31
Posts: 227
Join Date: Feb 2013
Nice! Will try on my VU

sent from my LG-P895 using Tapatalk bajakan
 
Madaditya
Old
#3  
Madaditya's Avatar
Recognized Themer
Thanks Meter 980
Posts: 940
Join Date: Jul 2012
Location: No where
Default 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!
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental



The Following User Says Thank You to Madaditya For This Useful Post: [ Click to Expand ]
 
zeppelinrox
Old
#4  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21,210
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
Quote:
Originally Posted by Madaditya View Post
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
 
Madaditya
Old
(Last edited by Madaditya; 17th June 2014 at 11:26 AM.)
#5  
Madaditya's Avatar
Recognized Themer
Thanks Meter 980
Posts: 940
Join Date: Jul 2012
Location: No where
Quote:
Originally Posted by zeppelinrox View Post
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
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental



 
zeppelinrox
Old
#6  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21,210
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
Quote:
Originally Posted by Madaditya View Post
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?
 
Madaditya
Old
#7  
Madaditya's Avatar
Recognized Themer
Thanks Meter 980
Posts: 940
Join Date: Jul 2012
Location: No where
Quote:
Originally Posted by zeppelinrox View Post
Nice idea!

Whats the command to disable data?
svc data enable/disble

for wifi:

svc wifi enable/disable
You...Me...are all Noobs

Xperia Pro | Xperia Iridescent | Lupus v16
Xperia Sola | White Pepper | Experimental



The Following User Says Thank You to Madaditya For This Useful Post: [ Click to Expand ]
 
zeppelinrox
Old
#8  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21,210
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
Quote:
Originally Posted by Madaditya View Post
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: [ Click to Expand ]
Thread Tools
Display Modes