How to auto shut down Android during long sleep

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to auto shut down Android during long sleep

582 Views
dennis3
Contributor V

This is less of an imx8 issue and more of a generic Android/Linux issue, but were using the imx8m so I'll ask here and see if someone perhaps has dealt with this issue.

Our device is battery powered.  We are using Android.  After the screen timeout for inactivity occurs, the kernel will go into a sleep state.  Battery load during this time is pretty minimal but it is enough to drain the battery over a couple days.  It would be desirable if the user does not wake the device after an hour or so, to go ahead and shut down.

I haven't found any luck finding hooks in Android to do this.  The PowerManagerService has some callbacks to set the wakefulness state, but it seems those are only called if the device actually wakes up from sleep.  At the Linux level though, the device does come out of sleep periodically due to the RTC interrupt.  I see the battery health is checked and then the device immediately goes back to sleep and no powermanager service hooks are called.

Can anyone suggest where I might put a hook to detect this state so that I might a check the time since the device was awake and just shut down if it's been longer than the desired timeout?

0 Kudos
2 Replies

568 Views
Zhiming_Liu
NXP TechSupport
NXP TechSupport

Maybe you can request ACTION_REQUEST_SHUTDOWN after screen timeout for inactivity occurs:

https://developer.tomtom.com/bridge/documentation/develop/suspend-shutdown-hooks

0 Kudos

555 Views
dennis3
Contributor V

Thanks @Zhiming_Liu 

It looks like that may be a solution if we create a system app or modify an Android library.

https://stackoverflow.com/questions/55486249/why-cant-i-find-action-request-shutdown-in-the-android-...

As near as I can tell however, the Android layer of the OS never comes out of sleep unless the system is supposed to wake all the way back up.  (Example the power button pressed).  Instead, the system suspend library is in a state of executing a loop that always puts the device right back to sleep on any wake event unless there is some wakelock managed by android.

So I've done a temporary workaround to modify the suspend library directly to have a timer and shutdown if our timeout passes.  But it seems there might be some more standard way to do this.

0 Kudos