Android14 AOSP支持短按关机

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

diff 复制代码
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;
             }
 
相关推荐
修炼者6 小时前
Android Studio的技巧
android·android studio
雨白6 小时前
ARouter 入门指南:从基本跳转到对象传递
android
用户69371750013847 小时前
17.Kotlin 类:类的形态(四):枚举类 (Enum Class)
android·后端·kotlin
h***34637 小时前
MS SQL Server 实战 排查多列之间的值是否重复
android·前端·后端
用户69371750013847 小时前
16.Kotlin 类:类的形态(三):密封类 (Sealed Class)
android·后端·kotlin
摆烂积极分子9 小时前
安卓开发学习-安卓版本
android·学习
n***265611 小时前
MySQL JSON数据类型全解析(JSON datatype and functions)
android·mysql·json
t***821111 小时前
mysql的主从配置
android·mysql·adb
YF021113 小时前
Frida如何稳定连接PC端跟Android手机端
android·mac·xposed
O***P57114 小时前
【MySQL】MySQL内置函数--日期函数字符串函数数学函数其他相关函数
android·mysql·adb