Android shutdown pops up an in depth analysis of the selection menu

  • 2020-05-10 18:48:29
  • OfStack

In the Android system, a long press of the Power key will bring up a dialog box for you to select "airplane mode", "mute", "shutdown" and other functions. These features are great for phones, but not necessarily for set-top boxes.
This article briefly describes how to customize the shutdown interface.
My goal is to long press the Power key, which will shut down, and the "device will shut down" selection dialog box will pop up. If you can choose "yes" to shut down, and "no" to return to the system.
The code for the pop-up dialog box is:
frameworks\policies\base\phone\com\android\internal\policy\impl\PhoneWindowManager.java
The code to display the dialog box is as follows:

java Code: 
Runnable mPowerLongPress = new Runnable() { 
public void run() { 
mShouldTurnOffOnKeyUp = false; 
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); showGlobalActionsDialog(); 
} 
};

Calling the showGlobalActionsDialog method will display the dialog box above that shows "airplane mode," "mute," "shutdown," and the options.
Since my goal is to get rid of the show, just comment out the line of code and replace it with the shutdown code. So where is the shutdown code? This code is located at:
frameworks\policies\base\phone\ android\internal\ impl\ GlobalActions. java the createDialog method of this file has the following code:

java Code: 
mItems = Lists.newArrayList( 
//  Silent mode mSilentModeToggle, 
// mAirplaneModeOn In airplane mode , 
// last: power off new SinglePressAction( com.android.internal.R.drawable.ic_lock_power_off, R.string.global_action_power_off) { 
public void onPress() { 
// shutdown by making sure radio and power are handled accordingly. 
ShutdownThread.shutdown(mContext, true); 
} 
public boolean showDuringKeyguard() { 
return true; 
} 
public boolean showBeforeProvisioning() { 
return true 
} 
});

As you can see from the code, if you select the "shutdown" option in the dialog above, the shutdown method of ShutdownThread will be called to shutdown. The second parameter of the shutdown method identifies whether the query dialog box pops up.
We can modify the code of PhoneWindowManager.java, and the final code is as follows:

java Code: 
Runnable mPowerLongPress = new Runnable() { 
public void run() { 
mShouldTurnOffOnKeyUp = false; 
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); 
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); 
//showGlobalActionsDialog(); 
ShutdownThread.shutdown(mContext, false); 
}
};


Related articles: