我这边主要是讲下android reboot走的流程以及所设计的代码,我这边直接从framework层开始。
framework会提供系统重启的接口:
代码路径:frameworks/base/core/java/android/os/Power.java
public static void reboot(String reason) throws IOException
{
rebootNative(reason);
}
而嵌套的rebootNative(reason);其实是个native接口,其实现是在frameworks/base/core/jni/android_os_Power.cpp
{ "rebootNative", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot },
static void android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason)
{
sync();
#ifdef HAVE_ANDROID_OS
if (reason == NULL) {
reboot(RB_AUTOBOOT);
} else {
const char *chars = env->GetStringUTFChars(reason, NULL);
__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_RESTART2, (char*) chars);
env->ReleaseStringUTFChars(reason, chars); // In case it fails.
}
jniThrowIOException(env, errno);
#endif
}
重点关注__reboot这个函数,其带4个参数,具体函数定义是在内核里kernel/sys.c