关机流程

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。


=============== PhoneWindowManager.java (frameworks\base\policy\src\com\android\internal\policy\impl)=======
-->mPowerLongPress()
--> case LONG_PRESS_POWER_GLOBAL_ACTIONS:
mPowerKeyHandled = true;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
--> mVibrator.vibrate(pattern[0]); //弹出框马达震动
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
showGlobalActionsDialog(); //弹出关机选项对话框
-->mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
================ GlobalActions.java (frameworks\base\policy\src\com\android\internal\policy\impl)===========
--> showDialog();
-->createDialog();
-->ShutdownThread.shutdown(mContext, true); //监听关机选项是否按下。
================ ShutdownThread.java (frameworks\base\core\java\com\android\internal\app) ==================
-->shutdown(final Context context, boolean confirm) //开始关机流程
-->beginShutdownSequence(context);
-->startBootAnimation(); // 开始关机动画
-->checkShutdownFlow(); // 检测是假关机还是真关机
--> if ("1".equals(SystemProperties.get("sys.ipo.battlow")))
mShutdownFlow = NORMAL_SHUTDOWN_FLOW; //如果电池电量小于等于4%,在batteryserver.java中定义: if(mBatteryLevel<= 4) if (FeatureOption.MTK_IPO_SUPPORT == true) {
SystemProperties.set("sys.ipo.battlow","1");
-->sInstance.start(); // 开始关机进程
-->run();
-->running();
--> if (mShutdownFlow == IPO_SHUTDOWN_FLOW) //如果是假关机
vibrator.vibrate(SHUTDOWN_VIBRATE_MS); //假关机关机震动。
--> rebootOrShutdown(mReboot, mRebootReason); //如果是真关机
--> Power.reboot(reason); //重启,没有关机震动。
--> vibrator.vibrate(SHUTDOWN_VIBRATE_MS); //如果是真关机,有关机震动.
Power.shutdown(); //关机
========================== Power.java (frameworks\base\core\java\android\os) =============================
public static native void shutdown();
reboot(String reason) throws IOException
-->rebootNative(reason);
========================== JNI android_os_Power.cpp (frameworks\base\core\jni)=============================
{ "shutdown", "()V", (void*)android_os_Power_shutdown }, // shutdown JNINativeMethod 接口
{ "rebootNative", "(Ljava/lang/String;)V", (void*)android_os_Power_reboot }, // reboot JNINativeMethod 接口
android_os_Power_shutdown(JNIEnv *env, jobject clazz);
-->android_reboot(ANDROID_RB_POWEROFF, 0, 0);
android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason)
android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars);
========================= C++ /system/core/libcuilte/android_reboot.c ===============================

android_reboot(int cmd, int flags, char *arg)
-->case ANDROID_RB_RESTART: // 重启,不带重启原因
ret = reboot(RB_AUTOBOOT);
-->case ANDROID_RB_POWEROFF: // 关机
ret = reboot(RB_POWER_OFF);
-->case ANDROID_RB_RESTART2: //重启,带开机原因
ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,LINUX_REBOOT_CMD_RESTART2, arg);
======================== bionic\libc\unistd\reboot.c =================================================
reboot(int mode)
--> __reboot( LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, NULL );
======================== bionic\libc\arch-arm\syscalls\__reboot.S ===================================
#include
#include

ENTRY(__reboot)
.save {r4, r7}
stmfd sp!, {r4, r7}
ldr r7, =__NR_reboot
swi #0
ldmfd sp!, {r4, r7}
movs r0, r0
bxpl lr
b __set_syscall_errno
END(__reboot)

========================= kernel/kernel/sys.c ============================
SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
-->kernel_restart(NULL);
-->kernel_restart_prepare(cmd);
-->blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
system_state = SYSTEM_RESTART;
usermodehelper_disable();
device_shutdown();
syscore_shutdown();
-->machine_restart(cmd);
-->kernel_power_off();
-->kernel_shutdown_prepare(SYSTEM_POWER_OFF);
-->blocking_notifier_call_chain(&reboot_notifier_list,(state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
system_state = state;
usermodehelper_disable();
device_shutdown();

device_shutdown函数实现如下:
/**
* device_shutdown - call ->shutdown() on each device to shutdown.
*/
void device_shutdown(void)
{
struct device *dev, *devn;

list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
kobj.entry) {
if (dev->bus && dev->bus->shutdown) {
dev_dbg(dev, "shutdown\n");
dev->bus->shutdown(dev);
} else if (dev->driver && dev->driver->shutdown) {
dev_dbg(dev, "shutdown\n");
dev->driver->shutdown(dev);
}
}
kobject_put(sysfs_dev_char_kobj);
kobject_put(sysfs_dev_block_kobj);
kobject_put(dev_kobj);
async_synchronize_full();
}

list_for_each_entry_safe_reverse是个有关for循环的宏,目的是访问dev的链表,然后在循环体中调用dev->bus->shutdown(dev);

================ kernel/arch/arm/kernel/process.c ====================
machine_restart(char *cmd)
-->machine_shutdown();
-->arm_pm_restart(reboot_mode, cmd);
-->arm_machine_restart(char mode, const char *cmd)
-->arch_reset();
void (*arm_pm_restart)(char str, const char *cmd) = arm_machine_restart;

void arch_reset(char mode, const char *cmd)
{

#ifndef CONFIG_MT6577_FPGA
char reboot = 0;
printk("arch_reset: cmd = %s\n",

cmd ? : "NULL");

if (cmd && !strcmp(cmd, "charger")) {
/* do nothing */
} else if (cmd && !strcmp(cmd, "recovery")) {
rtc_mark_recovery();
} else {
reboot = 1;
}

wdt_arch_reset(reboot);
#endif
}

相关文档
最新文档