时间2022-01-10
相关的类
首先需要了解以下这几个类
KeyguardViewMeditor:整个锁屏的调度类,相当于锁屏的大脑,控制着整个锁屏。
KeyguardService:负责锁屏模块和PWM和PMS之间的沟通。
KeyguardUpdateMonitor:负责将锁屏的状态传递下去
StatusBarKeyguardViewManager:负责View的管理
KeyguardBouncer:专门负责Bouncer界面也就是安全锁界面的管理。
灭屏的情况之前的文章中有提及到,规定的有3种,本篇中我们以按下Power键灭屏为例分析。
流程
1、首先执行的是PWM中的finishedGoingToSleep()方法
@Override
public void finishedGoingToSleep(int why) {
EventLogTags.writeScreenToggled(0);
if (DEBUG_WAKEUP) {
Slog.i(TAG, "Finished going to sleep... (why="
+ WindowManagerPolicyConstants.offReasonToString(why) + ")");
}
MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
mGoingToSleep = false;
mRequestedOrGoingToSleep = false;
mDefaultDisplayPolicy.setAwake(false);
// We must get this work done here because the power manager will drop
// the wake lock and let the system suspend once this function returns.
synchronized (mLock) {
updateWakeGestureListenerLp();
updateLockScreenTimeout();
}
mDefaultDisplayRotation.updateOrientationListener();
if (mKeyguardDelegate != null) {
mKeyguardDelegate.onFinishedGoingToSleep(why,
mCameraGestureTriggeredDuringGoingToSleep);
//此处调用的是KeyguardServiceDelegate类中的
// onFinishedGoingToSleep方法,此类中直接调用的KeyguardService中的方法,
// 所以直接看KeyGuardSeervice.读者也可自行查看代码确定调用关系
}
if (mDisplayFoldController != null) {
mDisplayFoldController.finishedGoingToSleep();
}
mCameraGestureTriggeredDuringGoingToSleep = false;
}
2、keyguardService中的onFinishedGoingToSleep()方法
@Override // Binder interface
public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) {
checkPermission();
mKeyguardViewMediator.onFinishedGoingToSleep(reason, cameraGestureTriggered);
mKeyguardLifecyclesDispatcher.dispatch(
KeyguardLifecyclesDispatcher.FINISHED_GOING_TO_SLEEP);
}
3、KeyguardViewMediator.onFinishedGoingToSleep(),此方法中有对当前状态的判断
public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
synchronized (this) {
mDeviceInteractive = false;
mGoingToSleep = false;
mWakeAndUnlocking = false;
resetKeyguardDonePendingLocked();
mHideAnimationRun = false;
notifyFinishedGoingToSleep();
if (cameraGestureTriggered) {
Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
// Just to make sure, make sure the device is awake.
mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
PowerManager.WAKE_REASON_CAMERA_LAUNCH,
"com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
mPendingLock = false;
mPendingReset = false;
}
//锁屏界面按下的Power
if (mPendingReset) {
resetStateLocked();
mPendingReset = false;
}
//非锁屏界面按下的Power
if (mPendingLock) {
doKeyguardLocked(null);
mPendingLock = false;
}