shutdown thread分析

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值