Android shutdown thread
- namespace is "package com.android.internal.app"
- design pattern is singleton
- 提供了公有静态成员函数
public static void shutdown(final Context context, boolean confirm)
confirm 输入变量决定是否弹出关机确认对话框。
该函数只能被一个线程调用。一旦执行,其他调用将被忽略。
该函数的常规调用是
public class PhoneWindowManager implements WindowManagerPolicy { private final Runnable mPowerLongPress = new Runnable() { public void run() { // The context isn't read if (mLongPressOnPowerBehavior < 0) { mLongPressOnPowerBehavior = mContext.getResources().getInteger( com.android.internal.R.integer.config_longPressOnPowerBehavior); } switch (mLongPressOnPowerBehavior) { case LONG_PRESS_POWER_NOTHING: break; case LONG_PRESS_POWER_GLOBAL_ACTIONS: mPowerKeyHandled = true; performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); showGlobalActionsDialog(); break; case LONG_PRESS_POWER_SHUT_OFF: mPowerKeyHandled = true; performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); ShutdownThread.shutdown(mContext, true); break; } } }; }
- shutdown()将调用私有静态成员函数
private static void beginShutdownSequence(Context context)
禁止设备进入 sleep 模式
禁止设备 LCD 进入关闭状态。
启动关机线程
- 线程处理函数广播 Intent.ACTION_SHUTDOWN 消息。
并设定超时时间。当time out 后,直接继续强制关机流程。
// maximum time we wait for the shutdown broadcast before going on. private static final int MAX_BROADCAST_TIME = 10*1000;
- 强制关机流程将依次关闭
- ActivityManager
- Bluetooth
- Phone 1 radio
- Phone 2 radio
- 循环等待time out 来关闭 Bluetooth, Phone1 radio, Phone2 radio
- MountService
- 最后进行扫尾工作
public static void rebootOrShutdown(boolean reboot, String reason) {
- 选择是否 reboot
- 选择是否 vibrate