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;
             }
 
相关推荐
菠萝地亚狂想曲25 分钟前
Zephyr_01, environment
android·java·javascript
sTone8737536 分钟前
跨端框架通信机制全解析:从 URL Schema 到 JSI 到 Platform Channel
android·前端
sTone8737537 分钟前
Java 注解完全指南:从 "这是什么" 到 "自己写一个"
android·前端
catoop1 小时前
Kotlin 协程在 Android 开发中的应用:定义、优势与对比
android·kotlin
撒旦物种1 小时前
Android WebView 获取内容高度
android·webview
空中海1 小时前
第七章:安卓性能优化
android·性能优化
空中海2 小时前
第四章:导航与路由
android
2501_916007474 小时前
iOS逆向工程:详细解析ptrace反调试机制的破解方法与实战步骤
android·macos·ios·小程序·uni-app·cocoa·iphone
空中海4 小时前
第三章:状态管理与 Jetpack 架构组件
android·架构
峥嵘life4 小时前
Android + Kiro AI软件开发实战教程
android·后端·学习