Implementation code of android to realize short press power key shutdown

  • 2021-12-09 10:06:49
  • OfStack

Open the file:\ frameworks\ base\ policy\ src\ com\ android\ internal\ policy\ impl\ PhoneWindowManager.java
In the code: private static final int MSG_POWER_LONG_PRESS = 14; Add the following:


private static final int MSG_POWER_SHUT_DOWN=15;

At:


case MSG_POWER_LONG_PRESS:
  powerLongPress();
  break;

Add the following:


case MSG_POWER_SHUT_DOWN:
		mWindowManagerFuncs.shutdown(false);
		break;

Find case 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:


if(down){
					if(mPowerManager.isScreenOn()) {
						Message msg = mHandler.obtainMessage(MSG_POWER_SHUT_DOWN);
						msg.setAsynchronous(true);
						mHandler.sendMessageDelayed(msg,
						ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
					} else {
						Log.e("GO to Wakeup--------> TTTEEE","keyCode :"+keyCode);
						wakeUpFromPowerKey(event.getDownTime());
					}
				}   
				break;

Then android is compiled in the directory frameworks/base/policy. policy. jar push is restarted from system/framework


Related articles: