有时log中会出现keyguard 1S超时的log
08-05 22:09:48.397957 1109 1184 W WindowManager: Keyguard drawn timeout. Setting mKeyguardDrawComplete
//framework部分代码流程
DisplayPowerController中设置完设置完模式之后
PhoneWindowManager.screenTurningOn{
//上面有个一个1秒超时Handle,超时会强制绘制keyguard
mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
}
--->
KeyguardServiceDelegate.onScreenTurningOn(final DrawnListener drawnListener) {
mKeyguardService.onScreenTurningOn(new KeyguardShowDelegate(drawnListener));
}
--->
KeyguardServiceWrapper.onScreenTurningOn(IKeyguardDrawnCallback callback)
IKeyguardService.aidl void onScreenTurningOn(IKeyguardDrawnCallback callback);
//systemUI部分代码流程
KeyguardService.onScreenTurningOn(IKeyguardDrawnCallback callback)
-->
KeyguardViewMediator.onScreenTurningOn(IKeyguardDrawnCallback callback){
notifyScreenOn(callback);
}
-->
public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
notifyScreenOn(callback);
Trace.endSection();
}
--->
//如果系统卡顿,可能这么Handle处理都可能会有有延迟出现,导致绘制超时
通过H.NOTIFY_SCREEN_TURNING_ON处理
--->
Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Trace.endSection();
--->
这边会持有KeyguardViewMediator.this的锁,可能会导致回调延时
private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
synchronized (KeyguardViewMediator.this) {
if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
mKeyguardViewControllerLazy.get().onScreenTurningOn();
if (callback != null) {
if (mWakeAndUnlocking) {
mDrawnCallback = callback;
} else {
notifyDrawn(callback);
}
}
}
Trace.endSection();
}
///
private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Trace.beginSection("KeyguardViewMediator#notifyDrawn");
try {
callback.onDrawn();
} catch (RemoteException e) {
Slog.w(TAG, "Exception calling onDrawn():", e);
}
Trace.endSection();
}
onDraw这边回调的是PhoneWindowManager,如果1秒内没有调用则会出现keyguard绘制超时
437 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
438 @Override
439 public void onDrawn() {
440 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
441 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
442 }
443 };