码迷,mamicode.com
首页 > 移动开发 > 详细

AndroidFramework工作日志---ATV9遥控器红外模式下,机顶盒在假待机阶段会响应遥控器语音键

时间:2019-06-07 19:05:32      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:server   event   switch   ret   debug   services   als   global   遥控器   

【问题描述】

测试部反馈,红外模式下,按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: 0
05-28 04:03:47.865  3115  3179 D WindowManager: interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
05-28 04:03:48.065  3115  3179 D WindowManager: interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
05-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=2000000
console:/ # 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 system
1.按power键进入假待机:
[  312.423757@1] input: irdec, power_state: 1, power_key_state: 0
01-01 03:06:40.199 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
01-01 03:06:40.199 D/WindowManager( 3123): boolean isWakeKey =false
01-01 03:06:40.401 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
01-01 03:06:40.402 D/WindowManager( 3123): boolean isWakeKey =false
01-01 03:06:40.402 D/WindowManager( 3123): powerPress: eventTime=312377 interactive=true count=1 beganFromNonInteractive=false mShortPressOnPowerBehavior=1
2.按BACK键:唤醒了
01-01 03:06:43.025 D/WindowManager( 3123): interceptKeyTq keycode=4 interactive=false keyguardActive=false policyFlags=2000000
01-01 03:06:43.025 D/WindowManager( 3123): boolean isWakeKey =true
01-01 03:06:43.026 D/WindowManager( 3123): line:6422,whz, is wakekey and going to wake up
01-01 03:06:43.229 D/WindowManager( 3123): interceptKeyTq keycode=4 interactive=true keyguardActive=false policyFlags=22000000
01-01 03:06:43.229 D/WindowManager( 3123): boolean isWakeKey =true
3.再次按Power键进入假待机:
[  318.426929@1] input: irdec, power_state: 1, power_key_state: 0
01-01 03:06:46.202 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
01-01 03:06:46.202 D/WindowManager( 3123): boolean isWakeKey =false
01-01 03:06:46.405 D/WindowManager( 3123): interceptKeyTq keycode=26 interactive=true keyguardActive=false policyFlags=22000000
01-01 03:06:46.406 D/WindowManager( 3123): boolean isWakeKey =false
01-01 03:06:46.406 D/WindowManager( 3123): powerPress: eventTime=318380 interactive=true count=1 beganFromNonInteractive=false mShortPressOnPowerBehavior=1

4.按语音键:也唤醒了,并且走的是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=2000000
01-01 03:06:49.168 D/WindowManager( 3123): boolean isWakeKey =true
01-01 03:06:49.168 D/WindowManager( 3123): line:6105,whz,voice key is global key & wakekey and going to wake up
01-01 03:06:49.249 D/WindowManager( 3123): interceptKeyTq keycode=225 interactive=true keyguardActive=false policyFlags=22000000
01-01 03:06:49.250 D/WindowManager( 3123): boolean isWakeKey =true

AndroidFramework工作日志---ATV9遥控器红外模式下,机顶盒在假待机阶段会响应遥控器语音键

标签:server   event   switch   ret   debug   services   als   global   遥控器   

原文地址:https://www.cnblogs.com/houser0323/p/10988823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!