Android 6.0.1 修改按下 power button 三秒後才出現關機選單

power button按下時的code流程位於
\frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
在以下code中
==
        // If the power key has still not yet been handled, then detect short
        // press, long press, or multi press and decide what to do.
        mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
                || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
        if (!mPowerKeyHandled) {
            if (interactive) {
                // When interactive, we're already awake.
                // Wait for a long press or for the button to be released to decide what to do.
                if (hasLongPressOnPowerBehavior()) {
                    Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
                    msg.setAsynchronous(true);
                    mHandler.sendMessageDelayed(msg,
                            ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());  //mark trace
==         

會呼叫 sendMessageDelayed 在 getDeviceGlobalActionKeyTimeout 時間之後送出  MSG_POWER_LONG_PRESS message
mHandler.sendMessageDelayed(msg,
                            ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());  //mark trace                 
                           
而getDeviceGlobalActionKeyTimeout 相關code位於
\frameworks\base\core\java\android\view\ViewConfiguration.java
==
    public long getDeviceGlobalActionKeyTimeout() {
        return mGlobalActionsKeyTimeout;
    }
==
搜尋mGlobalActionsKeyTimeout,找到

mGlobalActionsKeyTimeout = GLOBAL_ACTIONS_KEY_TIMEOUT;

往上找 GLOBAL_ACTIONS_KEY_TIMEOUT,找到定義處
--
    /**
     * Defines the duration in milliseconds a user needs to hold down the
     * appropriate button to bring up the global actions dialog (power off,
     * lock screen, etc).
     */
    private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;  
--
這只是預設值 500 ms,往後找 mGlobalActionsKeyTimeout 還會有

        mGlobalActionsKeyTimeout = res.getInteger(
                com.android.internal.R.integer.config_globalActionsKeyTimeout);

在 frameworks\base\core\res\res\values\config.xml 檔案內,搜尋 config_globalActionsKeyTimeout
找到
    <!-- Amount of time in ms the user needs to press the relevant key to bring up the global actions dialog -->
    <integer name="config_globalActionsKeyTimeout">3000</integer>
所以就是修改  config.xml 檔案


    <!-- Amount of time in ms the user needs to press the relevant key to bring up the global actions dialog -->
    <integer name="config_globalActionsKeyTimeout">500</integer>
改成
  <integer name="config_globalActionsKeyTimeout">3000</integer>

  
                               
build method:
  mmm ./frameworks/base/core/res
  mmm ./frameworks/base/services
 
  make snod
  用 fastboot 去更新 system.img,就可以生效了
  fastboot flash system system.img
              
這樣就可以讓 power button 按下三秒後才出現 關機選單了  
arrow
arrow

    CuteParrot 發表在 痞客邦 留言(0) 人氣()