Android5.0 press the power key to shut down directly without the confirmation dialog box
If you press the power key to shut down Android5.0, the dialog box does not pop up, but after you click the Shutdown option, you should pop up a confirmation dialog box to prompt the user whether the shutdown mode is actually enabled.
First, open the flag of the dialog box at the frameworks layer.
Frameworks \ base \ policy \ src \ com \ android \ internal \ policy \ impl \ GlobalActions. java
@Override public void onPress() { final boolean quickbootEnabled = Settings.System.getInt( mContext.getContentResolver(), "enable_quickboot", 0) == 1; // go to quickboot mode if enabled if (quickbootEnabled) { startQuickBoot(); return; } // shutdown by making sure radio and power are handled accordingly. mWindowManagerFuncs.shutdown(true /* confirm */);//20150423 show the power-off dialog }
In the source code, the processing of the displayed string is logical. Therefore, if you do not modify the function, the restart dialog box is displayed. Modify as follows:
Frameworks \ base \ services \ core \ java \ com \ android \ server \ power \ ShutdownThread. java
static void shutdownInner(final Context context, boolean confirm) { // ensure that only one thread is trying to power down. // any additional calls are just returned synchronized (sIsStartedGuard) { if (sIsStarted) { Log.d(TAG, "Request to shutdown already running, returning."); return; } } boolean showRebootOption = false; String[] defaultActions = context.getResources().getStringArray( com.android.internal.R.array.config_globalActionsList); for (int i = 0; i < defaultActions.length; i++) { if (defaultActions[i].equals("reboot") && mReboot) {// if (defaultActions[i].equals("reboot")) {20150421 for power_off dialog showRebootOption = true; break; } } final int longPressBehavior = context.getResources().getInteger( com.android.internal.R.integer.config_longPressOnPowerBehavior); int resourceId = mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_confirm : (longPressBehavior == 2 ? com.android.internal.R.string.shutdown_confirm_question : com.android.internal.R.string.shutdown_confirm); if (showRebootOption && !mRebootSafeMode) { resourceId = com.android.internal.R.string.reboot_confirm; } Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" + longPressBehavior); if (confirm) { final CloseDialogReceiver closer = new CloseDialogReceiver(context); if (sConfirmDialog != null) { sConfirmDialog.dismiss(); } sConfirmDialog = new AlertDialog.Builder(context) .setTitle(mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_title : showRebootOption ? com.android.internal.R.string.reboot_title : com.android.internal.R.string.power_off) .setMessage(resourceId) .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { beginShutdownSequence(context); } }) .setNegativeButton(com.android.internal.R.string.no, null) .create(); closer.dialog = sConfirmDialog; sConfirmDialog.setOnDismissListener(closer); sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); sConfirmDialog.show(); } else { beginShutdownSequence(context); } }