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;
             }
 
相关推荐
帅次3 小时前
Android 高级工程师面试:Java 基础知识 近1年高频追问 22 题
android·java·面试
私人珍藏库4 小时前
[Android] zip解压缩管理-全格式压缩包一键解压+打包
android·app·生活·工具·多功能
雨白5 小时前
C语言:动态内存分配
android
Android-Flutter5 小时前
android compose 自定义Painter绘制图形 使用
android·kotlin·compose
我是一颗柠檬5 小时前
【Java项目技术亮点】覆盖索引与索引下推优化
android·java·开发语言
vigor5127 小时前
MySQL通过Mango实现分库分表
android·数据库·mysql
阿pin10 小时前
Android随笔-Zygote中fork究竟是什么?
android·zygote·fork
Go-higher10 小时前
DriverTest 驾考知识卡片学习助手 —— 一款基于 Jetpack Compose 的现代 Android 学习APP
android·学习
安卓修改大师10 小时前
安卓修改大师APK控件修改实战教程
android