Powering off Android Things

…衆ロ難τιáo~ 提交于 2019-11-28 08:54:33

Android (and by extension, Android Things) should have no problem with a sudden loss of power. The core operating system is housed in read-only partitions on the file system, so there is no risk of corrupting the OS from a failed in-flight write.

Also, reboot -p should still work if you wanted to use that in testing or development. Going even farther with it, you could connect a Gpio with an InputDriver that emits KEYCODE_POWER to add your own power button back to the system if you felt you needed it.

Blundell

I like Dave's Answer, just wanted to add two things:

You could shut down the Android Things device programatically a number of ways but each has a caveat attached to it, discussed here: Turn off device programmatically

To power off an AndroidThings device like you said you can do it via ADB:

 adb shell reboot -p

(-p is short for --poweroff)

... and programmatically

for powering off

Runtime.getRuntime().exec("reboot -p");

and rebooting

Runtime.getRuntime().exec("reboot");

Explanation: the reboot binary is shipped in Android Things image with the world-executable permission, i.e. rwxr-xr-x, which makes it possible to be executable from within any app process. In other words, an app process does not need to gain su in contrast to most stock Android phones/tablets, so is no extra permission needed in AndroidManifest.xml.

Caution: in case of security model changes in newer OS versions this approach may not work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!