转载请标注原文地址:http://blog.csdn.net/uranus_wm/article/details/10542715
这里说的reboot是指software restart,常用场景有两种:
1.android应用层出现关键进程挂起,如system进程挂起引起的reboot
2.直接通过tty控制台输入reboot
以android4.0.4版本,samsung-exynos-4412+s5p8767(PMU)为例:
Android部分:
文件位置:/frameworks/base/core/java/com/android/internal/app/ShutdownThread.java
文件中有一个单例模式class ShutdownThread,包含reboot和shutdown两个静态方法。
public final class ShutdownThread extends Thread {
/**
* Request a clean shutdown, waiting for subsystems to clean up their
* state etc. Must be called from a Looper thread in which its UI
* is shown.
*
* @param context Context used to display the shutdown progress dialog.
* @param reason code to pass to the kernel (e.g. "recovery"), or null.
* @param confirm true if user confirmation is needed before shutting down.
*/
public static void reboot(final Context context, String reason, boolean confirm) {
mReboot = true;
mRebootReason = reason;
shutdown(context, confirm);
}
}
通过调用内部方法rebootOrShutdown会再调用到静态类Power.java的reboot方法
文件位置:/frameworks/base/core/java/android/os/power.java
/**
* Reboot the device.
* @param reason code to pass to the kernel (e.g. "recovery"), or null.
*
* @throws IOException if reboot fails for some reason (eg, lack of
* permission)
*/
public static void reboot(String reason) throws IOException
{
rebootNative(reason);
}
private static native void rebootNative(String reason) throws IOException ;
通过jni调用,一层层跟踪发现最终调用到
文件位置: /bionic/libc/unistd/reboot.c
int reboot (int mode)
{
return __reboot( LINUX_R