SoFunction
Updated on 2025-03-11

Android implementation code to shut down short press power button

Open the file: \frameworks\base\policy\src\com\android\internal\policy\impl\
In code:private static final int MSG_POWER_LONG_PRESS = 14;Added below:

private static final int MSG_POWER_SHUT_DOWN=15;

exist:

case MSG_POWER_LONG_PRESS:
  powerLongPress();
  break;

Added below:

case MSG_POWER_SHUT_DOWN:
		(false);
		break;

turn upcase KeyEvent.KEYCODE_POWER:
Comment out

/*result &= ~ACTION_PASS_TO_USER;
 isWakeKey = false; // wake-up will be handled separately
 if (down) {
  interceptPowerKeyDown(event, interactive);
 } else {
  interceptPowerKeyUp(event, interactive, canceled);
 }
 break;*/

Add again:

if(down){
					if(()) {
						Message msg = (MSG_POWER_SHUT_DOWN);
						(true);
						(msg,
						(mContext).getDeviceGlobalActionKeyTimeout());
					} else {
						("GO to Wakeup--------> TTTEEE","keyCode :"+keyCode);
						wakeUpFromPowerKey(());
					}
				}   
				break;

Then, in the directory frameworks/base/policy, compile push to system/framework and restart

This is the article about the implementation code of Android short-press power button shutdown. For more related contents of Android short-press power button shutdown, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!