安卓锁屏灭屏加载流程

时间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;
            }
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值