Android14 AOSP支持短按关机

修改frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java 

diff --git a/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 044da84e7..3cd9cf5f0 100644
--- a/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -697,6 +697,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
     private static final int MSG_LOG_KEYBOARD_SYSTEM_EVENT = 26;
     //----rk-code----
     private static final int MSG_SLEEP_SHOW_DREAM = 27;
+    //add by donggua
+    private static final int MSG_POWER_SHUT_DOWN = 28; //支持短按关机
 
     private int screenWidth;
     private int screenHeight;
@@ -822,6 +824,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                 case MSG_LOG_KEYBOARD_SYSTEM_EVENT:
                     handleKeyboardSystemEvent(KeyboardLogEvent.from(msg.arg1), (KeyEvent) msg.obj);
                     break;
+                case MSG_POWER_SHUT_DOWN://add by donggua,支持短按关机
+                    mWindowManagerFuncs.shutdown(false);
+                    break;
             }
         }
     }
@@ -4526,19 +4531,32 @@ public class PhoneWindowManager implements WindowManagerPolicy {
             }
 
             case KeyEvent.KEYCODE_POWER: {
-                logKeyboardSystemsEventOnActionUp(event, KeyboardLogEvent.TOGGLE_POWER);
-                EventLogTags.writeInterceptPower(
-                        KeyEvent.actionToString(event.getAction()),
-                        mPowerKeyHandled ? 1 : 0,
-                        mSingleKeyGestureDetector.getKeyPressCounter(KeyEvent.KEYCODE_POWER));
-                // Any activity on the power button stops the accessibility shortcut
-                result &= ~ACTION_PASS_TO_USER;
-                isWakeKey = false; // wake-up will be handled separately
-                if (down) {
-                    interceptPowerKeyDown(event, interactiveAndOn);
-                } else {
-                    interceptPowerKeyUp(event, canceled);
-                }
+                // logKeyboardSystemsEventOnActionUp(event, KeyboardLogEvent.TOGGLE_POWER);
+                // EventLogTags.writeInterceptPower(
+                //         KeyEvent.actionToString(event.getAction()),
+                //         mPowerKeyHandled ? 1 : 0,
+                //         mSingleKeyGestureDetector.getKeyPressCounter(KeyEvent.KEYCODE_POWER));
+                // // Any activity on the power button stops the accessibility shortcut
+                // result &= ~ACTION_PASS_TO_USER;
+                // isWakeKey = false; // wake-up will be handled separately
+                // if (down) {
+                //     interceptPowerKeyDown(event, interactiveAndOn);
+                // } else {
+                //     interceptPowerKeyUp(event, canceled);
+                // }
+                // add my donggua
+                // 支持短按电源事件关机
+                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;
             }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值