写在前面:
关于这个话题我们需要了解屏幕唤醒的一些基本流程,物理按键的Keycode,CPU使用率,Low Memeory,还需要关注ANR(由于广播是按顺序发送的,ANR会导致唤醒屏幕的广播阻塞引起屏幕无法正常点亮),再结合现场其他的一些情况进行综合分析。
结合案例分析:
案例描述:打开应用市场更新软件,操作Power键无法正常唤醒屏幕
分析过程:
下面的这行log,当有按键产生的时候就会打印出来,可以直接以keycode= 来做为关键字搜索:
请注意这个 policyFlags = #2000001 ,若这个值是包含下面两个值,则是由于底层驱动配置亮屏的,需要检查一下对应实体按键的配置文件:
public final static int FLAG_WAKE = 0x00000001;
public final static int FLAG_WAKE_DROPPED = 0x00000002;
首先我们可以通过案例描述可以看到当前手机系统资源比较紧张,不过还是要进一步去确认。那么我们可以通过沟通来准确定位现场时间点,但是一般情况下用户是不能提供准确的时间点,那么此时我们通过log信息来定位现场复现的时间点,那么keycode的按键log来进行定位(Tag:WindowManager,Key:keycode=26),如下:
02-13 18:32:06.203: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=true policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作①
02-13 18:32:06.207: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:32:06.297: I/WindowManager(707): Lock screen displayed!①
......
02-13 18:32:07.109: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=9 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:32:07.123: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:44:19.788: D/PowerManagerDisplayState(707): setScreenOn: on=false修改状态
02-13 18:44:26.345: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作②
02-13 18:44:26.408: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:44:28.619: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:44:28.924: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:44:29.034: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:44:31.418: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=true policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作③
02-13 18:44:31.448: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:44:32.098: I/WindowManager(707): Lock screen displayed!②
02-13 18:44:31.763: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为灭屏按键操作
02-13 18:44:33.163: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false02-13 18:44:33.666: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:44:33.715: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=2 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:44:34.023: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:44:34.093: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:44:37.393: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=true policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作④
02-13 18:44:37.413: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
......
02-13 18:44:38.097: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=5 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:44:38.134: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:44:39.063: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:44:39.565: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=true mHomePressed=false canceled=false metaState:0
......
02-13 18:44:39.617: I/WindowManager(707): Lock screen displayed!//③
02-13 18:44:40.183: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:10.730: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:11.043: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:11.571: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:45:12.303: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作⑤
02-13 18:45:12.306: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:45:14.163: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:14.665: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
......
02-13 18:45:14.816: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=4 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:45:14.823: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:15.633: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:16.135: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=true mHomePressed=false canceled=false metaState:0
......
02-13 18:45:16.488: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=8 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:45:16.515: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:45:17.404: I/WindowManager(707): Lock screen displayed!④
02-13 18:46:47.593: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:48:41.257: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作⑥
02-13 18:48:41.404: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为灭屏按键操作
02-13 18:48:41.405: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:48:41.435: I/WindowManager(707): Lock screen displayed!⑤
02-13 18:49:44.441: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:49:46.089: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作⑦
02-13 18:49:46.096: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:49:46.108: I/WindowManager(707): Lock screen displayed!⑥
02-13 18:51:12.283: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:12.533: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:13.041: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:51:15.861: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0//此为灭屏按键操作
02-13 18:51:15.422: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
02-13 18:51:15.883: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:16.844: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:17.349: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:51:17.373: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:18.790: D/PowerManagerDisplayState(707): setScreenOn: on=false//修改状态
02-13 18:51:18.236: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:18.733: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:18.789: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:51:16.844: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:17.349: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:51:17.373: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:18.236: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:18.733: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:18.789: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:51:19.626: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=false keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false//此为唤醒按键操作⑨
02-13 18:51:19.781: D/PowerManagerDisplayState(707): setScreenOn: on=true//修改状态
......
02-13 18:51:20.469: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=9 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:51:20.514: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:21.363: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:22.091: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=true mHomePressed=false canceled=false metaState:0
......
02-13 18:51:22.440: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=5 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:51:22.943: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=true policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:51:22.972: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=6 keyguardOn=true mHomePressed=false canceled=false metaState:0
02-13 18:51:23.645: I/WindowManager(707): Lock screen displayed!⑦
02-13 18:51:26.773: I/WindowManager(707): Lock screen displayed!⑧
02-13 18:56:42.000: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
......
02-13 18:56:42.248: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=6 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:56:42.303: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =false mVolumeUpKeyTriggered =false
02-13 18:56:57.267: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =true canceled = false isWakeKey=true mVolumeDownKeyTriggered =true mVolumeUpKeyTriggered =false
02-13 18:56:57.705: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=1 keyguardOn=false mHomePressed=false canceled=false metaState:0
......
02-13 18:56:58.817: D/WindowManager(707): interceptKeyTi keyCode=26 down=true repeatCount=23 keyguardOn=false mHomePressed=false canceled=false metaState:0
02-13 18:56:58.843: D/WindowManager(707): interceptKeyTq keycode=26 screenIsOn=true keyguardActive=false policyFlags = #2000001 down =false canceled = false isWakeKey=true mVolumeDownKeyTriggered =true mVolumeUpKeyTriggered =false
。。。。。。
从上面log我们看到用户进行Power按键唤醒屏幕的操作,其中包括几次长按,我们从上面的按键log中找出唤醒屏幕的操作时间点,然后来进行一一确认,这些唤醒操作是否能够成功唤醒屏幕。
那么通过对按键log的分析我们发现请求点亮的操作有9个,而实际成功唤醒的操作有8个,一个没有正常唤醒,也就是说有一次点亮屏幕失败,那么我们先重点关注此次唤醒失败的情况。在log中查找原因,首先我们查看哪一次唤醒的广播没有处理成功,然后我们发现有一次广播没有正常发出,如下:
02-13 18:51:25.360: W/BroadcastQueue(707): Failure sending broadcast Intent { act=android.intent.action.SCREEN_ON flg=0x50000010 }
02-13 18:51:25.360: W/BroadcastQueue(707): android.os.RemoteException: app thread has died
02-13 18:51:25.360: W/BroadcastQueue(707): at com.android.server.am.BroadcastQueue.performReceiveLocked(BroadcastQueue.java:441)
02-13 18:51:25.360: W/BroadcastQueue(707): at com.android.server.am.BroadcastQueue.deliverToRegisteredReceiverLocked(BroadcastQueue.java:528)
02-13 18:51:25.360: W/BroadcastQueue(707): at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:745)
02-13 18:51:25.360: W/BroadcastQueue(707): at com.android.server.am.ActivityManagerService.finishReceiver(ActivityManagerService.java:14821)
02-13 18:51:25.360: W/BroadcastQueue(707): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:384)
02-13 18:51:25.360: W/BroadcastQueue(707): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2272)
02-13 18:51:25.360: W/BroadcastQueue(707): at android.os.Binder.execTransact(Binder.java:404)
02-13 18:51:25.360: W/BroadcastQueue(707): at dalvik.system.NativeStart.run(Native Method)