注意点:对于锁屏来说,灭屏时,锁屏就会进行加载,并且加载完成,之后在亮屏时进行显示。
亮屏时,KeyguardService先后会调用以下方法:onStartedWakeUp(),onScreenTurningOn(),onScreenTurnedOn(),锁屏亮屏显示布局的主要操作就在onScreenTurningOn()。
1、首先onScreenTurningOn在PWM中被调起,开始进行亮屏流程。
// 在 DisplayManager 的 DisplayPowerController 线程上调用。
@Override
public void screenTurningOn(final ScreenonListener screenOnListener) {
if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn", 0 );
updateScreenOffSleepToken(false);
mDefaultDisplayPolicy.screenTurnedOn(screenOnListener);
synchronized (mLock) {
if (mKeyguardDelegate != null && mKeyguardDelegate.hasKeyguard()) {//一般走此处
mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
//移除掉消息队列中的绘制超时消息 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT,
getKeyguardDrawnTimeout());
//获取绘制时长后,发送绘制超时消息,完成绘制 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
} else {
if (DEBUG_WAKEUP) Slog.d(TAG,
"null mKeyguardDelegate: setting mKeyguardDrawComplete.");
mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
}
}
}
2、调用KeyguardServiceDelegate.onScreenTurningOn()方法
public void onScreenTurningOn(final DrawnListener drawnListener) {
if (mKeyguardService != null) {
if (DEBUG) Log.v(TAG, "onScreenTurnedOn(showListener = " + drawnListener + ")");
mKeyguardService.onScreenTurningOn(new KeyguardShowDelegate(drawnListener));
} else {
// try again when we establish a connection
Slog.w(TAG, "onScreenTurningOn(): no keyguard service!");
// This shouldn't happen, but if it does, show the scrim immediately and
// invoke the listener's callback after the service actually connects.
mDrawnListenerWhenConnect = drawnListener;
}
mKeyguardState.screenState = SCREEN_STATE_TURNING_ON;
}
3、此处调用了KeyguardService中的onScreenTurningOn方法
public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Trace.beginSection("KeyguardService.mBinder#onScreenTurningOn");
checkPermission();
mKeyguardViewMediator.onScreenTurningOn(callback);
mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNING_ON);
Trace.endSection();
}
4、调用KeyguardViewMediator中的onScreenTurningOn
public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
notifyScreenOn(callback);
Trace.endSection();
}
private void notifyScreenOn(IKeyguardDrawnCallback callback) {
if (DEBUG) Log.d(TAG, "notifyScreenOn");
Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
mHandler.sendMessage(msg);
}
5、此处,向消息队列中发送了NOTIFY_SCREEN_TURNING_ON消息。接收到消息后的执行逻辑如下
case NOTIFY_SCREEN_TURNING_ON:
Trace.beginSection(
"KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Trace.endSection();
break;
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();
}
6、此处执行了notifyDrawn(callback);
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();
}
7、这个callback.onDrow()回调到KeyguardServiceDelegate中
private final class KeyguardShowDelegate extends IKeyguardDrawnCallback.Stub {
private DrawnListener mDrawnListener;
KeyguardShowDelegate(DrawnListener drawnListener) {
mDrawnListener = drawnListener;
}
@Override
public void onDrawn() throws RemoteException {
if (DEBUG) Log.v(TAG, "**** SHOWN CALLED ****");
if (mDrawnListener != null) {
mDrawnListener.onDrawn();
}
}
};
8、此处执行mDrawnListener.onDrawn();这里实际上是调用到PWM中
final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
@Override
public void onDrawn() {
if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
}
};
从而发送锁屏绘制完成的消息。



