"Suspend-to-Idle" (freeze power state) script

147 views
Skip to first unread message

ouija

unread,
Jul 28, 2019, 6:16:28 PM7/28/19
to Android-x86
Managed to resolve issue with sleep on my device, which apparently only supports "suspend to idle" (or freeze power state) on cherrytrail / baytrail devices.

Essentially the problem is that the backlight of the screen remains on when the device is asleep, unless you set the power state to freeze (ie: echo freeze > sys/power/state)

I've seen people using Tasker to achieve a similar concept of applying this state when the system becomes idle, but I'd rather not rely on an app to do this but instead have a script running behind the scenes, so I wrote one, which you can find online at: https://gist.github.com/ouija/a1e5389172bd79c75977ae9671b639fc

You can add this to the init.sh script under the do_bootcomplete() function, with a case switch defined for your particular device, for example something similar to this:

case "$(cat $DMIPATH/uevent)" in
*NS-P08W7100*)
# Run sleep freeze state script
sh /etc/sleep.sh > /dev/null 2>&1 &
;;
esac

Just copy the sleep.sh script to the /etc directory and update the device identifier to match your own.

This script basically checks when the device is asleep, and if so, it sets the power state to freeze.   It does this ever 30 seconds, so the device doesn't immediately go into "freeze" mode when you press the power button to put it to sleep, which I found more user-friendly in that the device is a little slower to "wake" from a freeze state then the default state, so having a 30 second buffer is nice to have,  when you accidentally put the device to sleep or need to quickly wake it after doing so! :)

Wanted to share in case anyone else is looking to achieve something similar and doesn't want to rely on a third-party app to do so.  Enjoy!

Chih-Wei Huang

unread,
Jul 29, 2019, 12:11:26 AM7/29/19
to Android-x86
Thank you for sharing this.

You may also try to set the property sleep.state=freeze

ouija <djo...@gmail.com> 於 2019年7月29日 週一 上午6:16寫道:
--
Chih-Wei
Android-x86 project
http://www.android-x86.org

ouija

unread,
Jul 29, 2019, 3:08:42 AM7/29/19
to Android-x86
I tried that earlier on this device and it didn't seem to work -- both with setting from /system/build.prop and from /etc/init.sh script via 'set_property' method and neither seem to have any effect on my device, which is why I opted to utilize this script instead.

ouija

unread,
Jul 29, 2019, 5:58:14 PM7/29/19
to Android-x86
Could you clarify how to set that property exactly?  I've tried everything, including setting as a kernel flag and nothing seems to work -- the power state is still defined as the default "freeze mem" and not "freeze".

My script does help, but it's not exactly perfect and sometimes has issues.

Chih-Wei Huang

unread,
Jul 29, 2019, 10:24:50 PM7/29/19
to Android-x86
ouija <djo...@gmail.com> 於 2019年7月30日 週二 上午5:58寫道:
>
> Could you clarify how to set that property exactly? I've tried everything, including setting as a kernel flag and nothing seems to work -- the power state is still defined as the default "freeze mem" and not "freeze".

The property won't affect kernel, of course.
It just changes the sleep state used by libsuspend.
Please check logcat to see if the property takes effect.
If it does, you should see log like
"autosuspend using sleep.state property freeze"

ouija

unread,
Jul 31, 2019, 12:02:50 AM7/31/19
to Android-x86
It doesn't seem to take when trying to set the property, not sure why.  But I've updated the script and it works really well, so I'm happy with this solution for now.
Reply all
Reply to author
Forward
0 new messages