android源碼修改,實現長按電源鍵直接關機

來源:互聯網
上載者:User

標籤:

版本:android 4.4.2

源檔案路徑:frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java

修改下面的代碼:

private final Runnable mPowerLongPress = new Runnable() {        @Override        public void run() {            // The context isn‘t read            if (mLongPressOnPowerBehavior < 0) {                mLongPressOnPowerBehavior = mContext.getResources().getInteger(                        com.android.internal.R.integer.config_longPressOnPowerBehavior);            }            int resolvedBehavior = mLongPressOnPowerBehavior;            if (FactoryTest.isLongPressOnPowerOffEnabled()) {                resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;            }/*            switch (resolvedBehavior) {            case LONG_PRESS_POWER_NOTHING:                break;            case LONG_PRESS_POWER_GLOBAL_ACTIONS:                mPowerKeyHandled = true;                if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {                    performAuditoryFeedbackForAccessibilityIfNeed();                }                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);                showGlobalActionsDialog();                break;            case LONG_PRESS_POWER_SHUT_OFF:            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:                mPowerKeyHandled = true;                performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);                mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);                break;            }*/            //注釋掉上面的代碼後,增加下面的代碼            mPowerKeyHandled = true;            performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);            sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);            mWindowManagerFuncs.shutdown(false);//這裡false代表不顯示關機提示框,true未顯示關機提示框        }    };

 修改後,長按關機鍵會直接關機。

android源碼修改,實現長按電源鍵直接關機

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.