测试部反馈,红外模式下,按power键进入假待机,按红外语音键会唤醒。
背景交代:红外语言键是我们自定义的按键,键值225。在红外模式下按会弹提示框“没连蓝牙,请连蓝牙使用语音键
不是问题,这是Android框架源码中的功能设定,鉴于我们不修改ATV9的框架,所以该问题非故障处理。测试方法异常。
android9按键打印没开,需要修改框架代码打开日志打印。
路径:Android9.0-SDK/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
打开打印:
static final String TAG = "WindowManager"; static final boolean DEBUG_INPUT = true;//在这里,默认是false的,我们将它改为true,打开打印。
打印主要看下面两个函数。
@Override public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { if (DEBUG_INPUT) { Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed + " canceled=" + canceled); }@Override public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { if (DEBUG_INPUT) { Log.d(TAG, "interceptKeyTq keycode=" + keyCode + " interactive=" + interactive + " keyguardActive=" + keyguardActive + " policyFlags=" + Integer.toHexString(policyFlags)); }
加了打印之后待机按键--->>语音按键,实验:
console:/ # [ 227.863558@1] input: irdec, power_state: 1, power_key_state: 005-28 04:03:47.865 3115 3179 D WindowManager: interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=2200000005-28 04:03:48.065 3115 3179 D WindowManager: interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=2200000005-28 04:03:48.065 3115 3179 D WindowManager: powerPress: eventTime=227819 interactive=true count=1 beganFromNonInteractive=false mShortPressOnPowerBehavior=1======05-28 04:03:50.046 3115 3179 D WindowManager: interceptKeyTq keycode=225 interactive=false keyguardActive=false policyFlags=2000000console:/ # 05-28 04:03:50.121 3115 3179 D WindowManager: interceptKeyTq keycode=225 interactive=true keyguardActive=false policyFlags=22000000
以上结果表明,框架层的phonewindowmanager是可以收到按键的,说明底层到框架没问题
所以目前的方向:查找按键从框架去了哪?
Q1.global key:是不是走了设置?
A:假待机状态,setting是不在的,遂排除。
Q2.框架其他部分处理了该按键,引起唤醒?
A:分析
frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
@Override public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {====== boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 || event.isWakeKey();====== if (isValidGlobalKey(keyCode) && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { if (isWakeKey) { wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); }}
以及 frameworks\base\core\java\android\view\KeyEvent.java
/** @hide */ public static final boolean isWakeKey(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_WAKEUP: case KeyEvent.KEYCODE_PAIRING: case KeyEvent.KEYCODE_STEM_1: case KeyEvent.KEYCODE_STEM_2: case KeyEvent.KEYCODE_STEM_3: return true; } return false; }
在代码中可确认,是由于框架中原生代码就是设定paring按键是可唤醒键,问题基本澄清,现在将phonewindowmanager加打印验证。
if (isValidGlobalKey(keyCode) && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { if (isWakeKey) { Log.d(TAG, "line:6105,whz,voice key is global key & wakekey and going to wake up" ); wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); } if (isWakeKey) { Log.d(TAG, "line:6422,whz, is wakekey and going to wake up" ); wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); }
加打印后的验证日志:
console:/sdcard # logcat -c && logcat -v time -s WindowManager--------- beginning of main--------- beginning of system1.按power键进入假待机:[ 312.423757@1] input: irdec, power_state: 1, power_key_state: 001-01 03:06:40.199 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=2200000001-01 03:06:40.199 D/WindowManager( 3123): boolean isWakeKey =false01-01 03:06:40.401 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=2200000001-01 03:06:40.402 D/WindowManager( 3123): boolean isWakeKey =false01-01 03:06:40.402 D/WindowManager( 3123): powerPress: eventTime=312377 interactive=true count=1 beganFromNonInteractive=false mShortPressOnPowerBehavior=12.按BACK键:唤醒了01-01 03:06:43.025 D/WindowManager( 3123): interceptKeyTq keycode=4 interactive=false keyguardActive=false policyFlags=200000001-01 03:06:43.025 D/WindowManager( 3123): boolean isWakeKey =true01-01 03:06:43.026 D/WindowManager( 3123): line:6422,whz, is wakekey and going to wake up01-01 03:06:43.229 D/WindowManager( 3123): interceptKeyTq keycode=4 interactive=true keyguardActive=false policyFlags=2200000001-01 03:06:43.229 D/WindowManager( 3123): boolean isWakeKey =true3.再次按Power键进入假待机:[ 318.426929@1] input: irdec, power_state: 1, power_key_state: 001-01 03:06:46.202 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=2200000001-01 03:06:46.202 D/WindowManager( 3123): boolean isWakeKey =false01-01 03:06:46.405 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=2200000001-01 03:06:46.406 D/WindowManager( 3123): boolean isWakeKey =false01-01 03:06:46.406 D/WindowManager( 3123): powerPress: eventTime=318380 interactive=true count=1 beganFromNonInteractive=false mShortPressOnPowerBehavior=14.按语音键:也唤醒了,并且走的是globalkey&&iswakekey if (isValidGlobalKey(keyCode) && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { if (isWakeKey) {======01-01 03:06:49.168 D/WindowManager( 3123): interceptKeyTq keycode=225 interactive=false keyguardActive=false policyFlags=200000001-01 03:06:49.168 D/WindowManager( 3123): boolean isWakeKey =true01-01 03:06:49.168 D/WindowManager( 3123): line:6105,whz,voice key is global key & wakekey and going to wake up01-01 03:06:49.249 D/WindowManager( 3123): interceptKeyTq keycode=225 interactive=true keyguardActive=false policyFlags=2200000001-01 03:06:49.250 D/WindowManager( 3123): boolean isWakeKey =true