Quantcast
Channel: xda-developers - Android Software and Hacking General [Developers Only]
Viewing all articles
Browse latest Browse all 3614

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

$
0
0
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 (Post 51640363)
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... :p

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 ;)

Viewing all articles
Browse latest Browse all 3614

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>