一般来说,与Android按键窗口事件相关的基本是与frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
这个文件有关。
因此先打开与输入相关的日志,如下:
然后重新编译烧录后查看打印的日志可以看到如下信息:
WindowManager: interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
而 “keycode=26” 这个键值可以通过frameworks/native/include/android/keycodes.h这个文件中的122行中找到,如下: AKEYCODE_POWER = 26,
通过上面的分析可以清楚知道电源按键按下后需要达到设定的超时时间后才会发送电源按键长按标志的消息,那么这个消息又会通过对应的Handler对该消息进行处理。
通过查找可以找到,还是在该文件下。
这里我要说一下,在调用 “showGlobalActionsInternal“ 此方法之前还调用了一个显示对话框方法 “onGlobalActionsAvailableChanged” ,这个就是小的对话框,如下。
那么创建并显示对话框这动作应该也是通过Handler去获取对应的 MSG_SHOW_CLOBAL_ACTIONS 标识的消息去执行的。
获取执行创建并显示对话框的源码位置
根据前面的分析,需要通过 “MSG_SHOW_CLOBAL_ACTIONS” 这个关键词去查找,可以找到如下图:
下面是对该执行创建并显示对话框的源码进行分析:
堆栈日志:
补丁:
commit d545ddbd31eb876971725e6a2818b44a8fd15a53
Author: dengjiawen <141147155@qq.com>
Date: Sat Aug 10 14:03:48 2024 +0800
移除长按POWER健弹出的对话框中的[关机]和[紧急呼救]选项
diff --git a/frameworks/base/core/res/res/values/config.xml b/frameworks/base/core/res/res/values/config.xml
index c1e3026ee45..f7c5764e0b3 100644
--- a/frameworks/base/core/res/res/values/config.xml
+++ b/frameworks/base/core/res/res/values/config.xml
@@ -2251,7 +2251,7 @@
<dimen name="config_viewMaxFlingVelocity">8000dp</dimen>
<!-- Amount of time in ms the user needs to press the relevant key to bring up the
- global actions dialog -->
+ global actions dialog 长按按键时长-->
<integer name="config_globalActionsKeyTimeout">500</integer>
<!-- Amount of time in ms the user needs to press the relevant keys to trigger the
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index ff25439a5f9..17f085b21be 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -614,12 +614,15 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
for (int i = 0; i < defaultActions.length; i++) {
String actionKey = defaultActions[i];
+ Log.e(TAG, "global action key " + actionKey);
if (addedKeys.contains(actionKey)) {
// If we already have added this, don't add it again.
continue;
}
if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
- addIfShouldShowAction(tempActions, shutdownAction);
+ // addIfShouldShowAction(tempActions, shutdownAction);
+ Exception e = new Exception("djw :createActionItems stack log");
+ e.printStackTrace();
} else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
addIfShouldShowAction(tempActions, mAirplaneModeOn);
} else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
@@ -655,7 +658,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
addIfShouldShowAction(tempActions, new LogoutAction());
}
} else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
- addIfShouldShowAction(tempActions, new EmergencyDialerAction());
+ // addIfShouldShowAction(tempActions, new EmergencyDialerAction());
} else {
Log.e(TAG, "Invalid global action key " + actionKey);
}
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index 96d6ecbcc07..dd1ff736ff6 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -57,6 +57,8 @@ import com.android.systemui.tracing.ProtoTracer;
import java.util.ArrayList;
+import android.util.Slog;
+
/**
* This class takes the functions from IStatusBar that come in on
* binder pool threads and posts messages to get them onto the main
@@ -66,6 +68,9 @@ import java.util.ArrayList;
*/
public class CommandQueue extends IStatusBar.Stub implements CallbackController<Callbacks>,
DisplayManager.DisplayListener {
+
+ private static final String TAG = "CommandQueue";
+
private static final int INDEX_MASK = 0xffff;
private static final int MSG_SHIFT = 16;
private static final int MSG_MASK = 0xffff << MSG_SHIFT;
@@ -742,6 +747,7 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
@Override
public void showGlobalActionsMenu() {
synchronized (mLock) {
+ Slog.w(TAG, "djw 9: showGlobalActionsMenu removeMessages obtainMessage");
mHandler.removeMessages(MSG_SHOW_GLOBAL_ACTIONS);
mHandler.obtainMessage(MSG_SHOW_GLOBAL_ACTIONS).sendToTarget();
}
diff --git a/frameworks/base/services/core/java/com/android/server/policy/GlobalActions.java b/frameworks/base/services/core/java/com/android/server/policy/GlobalActions.java
index ecd1eabc857..3e2e146fc9b 100755
--- a/frameworks/base/services/core/java/com/android/server/policy/GlobalActions.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/GlobalActions.java
@@ -26,7 +26,7 @@ import android.os.SystemProperties;
class GlobalActions implements GlobalActionsProvider.GlobalActionsListener {
private static final String TAG = "GlobalActions";
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = true;
private final Context mContext;
private final GlobalActionsProvider mGlobalActionsProvider;
@@ -66,6 +66,7 @@ class GlobalActions implements GlobalActionsProvider.GlobalActionsListener {
mDeviceProvisioned = deviceProvisioned;
mShowing = true;
if (mGlobalActionsAvailable && !"box".equals(SystemProperties.get("ro.target.product","unkonw"))) {
+ Slog.d(TAG, "djw 7: showDialog mGlobalActionsProvider.showGlobalActions");
mHandler.postDelayed(mShowTimeout, 5000);
mGlobalActionsProvider.showGlobalActions();
} else {
diff --git a/frameworks/base/services/core/java/com/android/server/policy/GlobalActionsProvider.java b/frameworks/base/services/core/java/com/android/server/policy/GlobalActionsProvider.java
index d414314db2b..a7b0f04ba92 100644
--- a/frameworks/base/services/core/java/com/android/server/policy/GlobalActionsProvider.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/GlobalActionsProvider.java
@@ -21,7 +21,7 @@ public interface GlobalActionsProvider {
boolean isGlobalActionsDisabled();
/** Set the listener that will handle various global actions evetns. */
void setGlobalActionsListener(GlobalActionsListener listener);
- /** Show the global actions UI to the user. */
+ /** Show the global actions UI to the user. by djw -> mGlobalActionsProvider.showGlobalActions();*/
void showGlobalActions();
/** Listener to pass global actions events back to system. */
diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index d966f36becb..82c4015630b 100755
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -240,7 +240,7 @@ import java.util.List;
public class PhoneWindowManager implements WindowManagerPolicy {
static final String TAG = "WindowManager";
static final boolean localLOGV = false;
- static final boolean DEBUG_INPUT = false;
+ static final boolean DEBUG_INPUT = true; //首先打开关于输入的日志
static final boolean DEBUG_KEYGUARD = false;
static final boolean DEBUG_SPLASH_SCREEN = false;
static final boolean DEBUG_WAKEUP = false;
@@ -682,6 +682,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
};
+ /* 被注册成监听和观察 */
private class PolicyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
@@ -729,6 +730,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
finishPowerKeyPress();
break;
case MSG_POWER_LONG_PRESS:
+ Log.d(TAG, "djw 4: PolicyHandler powerLongPress");
powerLongPress();
break;
case MSG_POWER_VERY_LONG_PRESS:
@@ -1016,8 +1018,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
powerLongPress();
} else {
+ Log.d(TAG, "djw 3: mHandler.sendMessageDelayed(msg,ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout())");
Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
+ /* mHandler.obtainMessage(MSG_POWER_LONG_PRESS)->PolicyHandler这是一个处理者 */
msg.setAsynchronous(true);
+ /* getDeviceGlobalActionKeyTimeout->mGlobalActionsKeyTimeout->com.android.internal.R.integer.config_globalActionsKeyTimeout->config.xml */
mHandler.sendMessageDelayed(msg,
ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
@@ -1308,6 +1313,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
case LONG_PRESS_POWER_NOTHING:
break;
case LONG_PRESS_POWER_GLOBAL_ACTIONS:
+ Log.d(TAG, "djw 5: LONG_PRESS_POWER_GLOBAL_ACTIONS");
mPowerKeyHandled = true;
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
"Power - Long Press - Global Actions");
@@ -1530,6 +1536,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (mGlobalActions == null) {
mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
}
+ Log.d(TAG, "djw 6: LONG_PRESS_POWER_GLOBAL_ACTIONS");
final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
// since it took two seconds of long press to bring this up,
@@ -3737,7 +3744,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mKeyguardDelegate.isShowing()));
if (DEBUG_INPUT) {
- Log.d(TAG, "interceptKeyTq keycode=" + keyCode
+ Log.d(TAG, "djw 1: interceptKeyTq keycode=" + keyCode
+ " interactive=" + interactive + " keyguardActive=" + keyguardActive
+ " policyFlags=" + Integer.toHexString(policyFlags));
}
@@ -3978,6 +3985,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
result &= ~ACTION_PASS_TO_USER;
isWakeKey = false; // wake-up will be handled separately
if (down) {
+ Log.d(TAG, "djw 2: KEYCODE_POWER DOWN (down)");
interceptPowerKeyDown(event, interactive);
} else {
interceptPowerKeyUp(event, interactive, canceled);
diff --git a/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index 39e839dfc7e..3ed8845199c 100644
--- a/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -542,6 +542,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
public void showGlobalActions() {
if (mBar != null) {
try {
+ Slog.w(TAG, "djw 8: showGlobalActionsMenu");
mBar.showGlobalActionsMenu();
} catch (RemoteException ex) {}
}