How to auto shut down Android during long sleep

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to auto shut down Android during long sleep

1,035件の閲覧回数
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?

ラベル(3)
0 件の賞賛
返信
2 返答(返信)

1,021件の閲覧回数
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 件の賞賛
返信

1,008件の閲覧回数
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 件の賞賛
返信