android reboot
Posted smile3670
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 down
Vibrator 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 power
Log.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 compare
memset(&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的主要内容,如果未能解决你的问题,请参考以下文章