本文主要是介绍android reboot,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考:
http://blog.csdn.net/airk000/article/details/9177077
http://blog.csdn.net/zhenwenxian/article/details/6766803
http://www.tuicool.com/articles/jYFZFf
http://blog.csdn.net/zzobin/article/details/7195060
http://blog.csdn.net/androiddeveloper_lee/article/details/9086447
framework
./base/core/java/com/android/internal/app/ShutdownThread.java
/*** Do not call this directly. Use {@link #reboot(Context, String, boolean)}* or {@link #shutdown(Context, boolean)} instead.** @param reboot true to reboot or false to shutdown* @param reason reason for reboot*/public static void rebootOrShutdown(boolean reboot, String reason) {if (reboot) {Log.i(TAG, "Rebooting, reason: " + reason);try {Power.reboot(reason);} catch (Exception e) {Log.e(TAG, "Reboot failed, will attempt shutdown instead", e);}} else if (SHUTDOWN_VIBRATE_MS > 0) {// vibrate before shutting downVibrator vibrator = new Vibrator();try {vibrator.vibrate(SHUTDOWN_VIBRATE_MS);} catch (Exception e) {// Failure to vibrate shouldn't interrupt shutdown. Just log it.Log.w(TAG, "Failed to vibrate during shutdown.", e);}// vibrator is asynchronous so we need to wait to avoid shutting down too soon.try {Thread.sleep(SHUTDOWN_VIBRATE_MS);} catch (InterruptedException unused) {}}// Shutdown powerLog.i(TAG, "Performing low-level shutdown...");Power.shutdown();}./base/core/jni/android_os_Power.cpp 不一样
static void android_os_Power_shutdown(JNIEnv *env, jobject clazz)
{android_reboot(ANDROID_RB_POWEROFF, 0, 0);
}extern int go_recovery(void);static void android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason)
{if (reason == NULL) {android_reboot(ANDROID_RB_RESTART, 0, 0);} else {const char *chars = env->GetStringUTFChars(reason, NULL);//android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars);go_recovery();android_reboot(ANDROID_RB_RESTART, 0, 0);env->ReleaseStringUTFChars(reason, chars); // In case it fails.}jniThrowIOException(env, errno);
}ANDOID_ROOT\system\core\libcutils\android_reboot.c
int android_reboot(int cmd, int flags, char *arg)
{int ret;if (!(flags & ANDROID_RB_FLAG_NO_SYNC))sync();if (!(flags & ANDROID_RB_FLAG_NO_REMOUNT_RO))remount_ro();switch (cmd) {case ANDROID_RB_RESTART:ret = reboot(RB_AUTOBOOT);break;case ANDROID_RB_POWEROFF:ret = reboot(RB_POWER_OFF);break;case ANDROID_RB_RESTART2:ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,LINUX_REBOOT_CMD_RESTART2, arg);break;default:ret = -1;}return ret;
}android4.0/frameworks/base/core/jni/misc_rw.cpp
/* force the next boot to recovery */
int go_recovery(void){LOGE("go_recovery =================\n");struct bootloader_message boot, temp;memset(&boot, 0, sizeof(boot));strcpy(boot.command, "boot-recovery");if (set_bootloader_message_block(&boot, MISC_DEVICE) )return -1;//read for comparememset(&temp, 0, sizeof(temp));if (get_bootloader_message_block(&temp, MISC_DEVICE))return -1;if( memcmp(&boot, &temp, sizeof(boot)) )return -1;LOGE("go_recovery ++++++++++++++++++++++\n");return 0;}
这篇关于android reboot的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!