安卓指纹解锁流程

首先IKeyguardService这个binder接口中有许多的回调,其中,在息屏时会使用如下回调

 /**
     * Called when the device has started going to sleep.
     *
     * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
     * or {@link #OFF_BECAUSE_OF_TIMEOUT}.
     */
    void onStartedGoingToSleep(int reason);

    /**
     * Called when the device has finished going to sleep.
     *
     * @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
     *            or {@link #OFF_BECAUSE_OF_TIMEOUT}.
     * @param cameraGestureTriggered whether the camera gesture was triggered between
     *                               {@link #onStartedGoingToSleep} and this method; if it's been
     *                               triggered, we shouldn't lock the device.
     */
    void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered);
    /**
     * Called when the screen starts turning off.
     */
    void onScreenTurningOff();

    /**
     * Called when the screen has turned off.
     */
    void onScreenTurnedOff();

亮屏时拉起如下回调

/**
     * Called when the device has started waking up.
     */
    void onStartedWakingUp();

    /**
     * Called when the device has finished waking up.
     */
    void onFinishedWakingUp();

    /**
     * Called when the device screen is turning on.
     */
    void onScreenTurningOn(IKeyguardDrawnCallback callback);

    /**
     * Called when the screen has actually turned on.
     */
    void onScreenTurnedOn();

且需要明确的一点时,锁屏的这几个周期的拉起是POWER拉起的,并非是锁屏自主拉起的,如果说,锁屏的周期走的不正确,从而引发了相关问题,此时,需要先分析Power是否出错。

如果亮屏后,短时间内没有唤醒系统,那么灭屏最后的周期会走

void onDreamingStarted();

然后再去唤醒系统的时候 首先会走

void onDreamingStopped();

然后才会继续执行剩下的周期。

指纹监听

1、首先phonewindowmanager中开始执行startedGoingToSleep()

    @Override
    public void startedGoingToSleep(int why) {
   
        if (DEBUG_WAKEUP) {
   
            Slog.i(TAG, "Started going to sleep... (why="
                    + WindowManagerPolicyConstants.offReasonToString(why) + ")");
        }

        mGoingToSleep = true;
        mRequestedOrGoingToSleep = true;

        if (mKeyguardDelegate != null) {
   
            mKeyguardDelegate.onStartedGoingToSleep(why);
        }
    }

2、此处调用KeyguardServiceDelegate中的onStartedGoingToSleep,调用时的参数,代表着灭屏原因,在WindowManagerPolicy的父类WindowManagerPolicyConstants中定义了下列三个原因

    /** Screen turned off because of a device admin */管理员
    int OFF_BECAUSE_OF_ADMIN = 1;
    /** Screen turned off because of power button */按下power键
    int OFF_BECAUSE_OF_USER = 2;
    /** Screen turned off because of timeout */超时
    int OFF_BECAUSE_OF_TIMEOUT = 3;

KeyguardServiceDelegate中的onStartedGoingToSleep方法是

public void onStartedGoingToSleep(int why) {
   
        if (mKeyguardService != null) {
   
            mKeyguardService.onStartedGoingToSleep(why);
        }
        mKeyguardState.offReason = why;
        mKeyguardState.interactiveState = INTERACTIVE_STATE_GOING_TO_SLEEP;
    }

3、这里调用了KeyguardService中的onStartedGoingToSleep

@Override // Binder interface
        public void onStartedGoingToSleep(int reason) {
   
            checkPermission();
            mKeyguardViewMediator.onStartedGoingToSleep(reason);
            mKeyguardLifecyclesDispatcher.dispatch(
                    KeyguardLifecyclesDispatcher.STARTED_GOING_TO_SLEEP);
        }

4,此处又调用了KeyguardViewMediator中的onStartedGoingToSleep

 public void onStartedGoingToSleep(int why) {
   
        if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
        synchronized (this) {
   
            mDeviceInteractive = false;
            mGoingToSleep = true;

            // Reset keyguard going away state so we can start listening for fingerprint. We
            // explicitly DO NOT want to call
            // mKeyguardViewControllerLazy.get().setKeyguardGoingAwayState(false)
            // here, since that will mess with the device lock state.
            mUpdateMonitor.dispatchKeyguardGoingAway(false);

            // Lock immediately based on setting if secure (user has a pin/pattern/password).
            // This also "locks" the device when not secure to provide easy access to the
            // camera while preventing unwanted input.
            int currentUser = KeyguardUpdateMonitor.getCurrentUser();
            final boolean lockImmediately =
                    mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
                            || !mLockPatternUtils.isSecure(currentUser);
            long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
            mLockLater = false;
            if (mExitSecureCallback != null) {
   
                if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
                try {
   
                    mExitSecureCallback.onKeyguardExitResult(false);
                } catch (RemoteException e) {
   
                    Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
                }
                mExitSecureCallback = null;
                if (!mExternallyEnabled) {
   
                    hideLocked();
                }
            } else if (mShowing) {
   
                mPendingReset = true;
            } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
                    || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
   
                doKeyguardLaterLocked(timeout);
                mLockLater = true;
            } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
   
                mPendingLock = true;
            }

            if (mPendingLock) {
   
                playSounds(true);
            }
        }
        mUpdateMonitor.dispatchStartedGoingToSleep(why);
        notifyStartedGoingToSleep();
    }

其中关于灭屏的相关流程暂不讨论,后续文章中会进一步分析。
5、又调用了KeyguardUpdataMonitor中的dispatchStartedGoingToSleep方法

public void dispatchStartedGoingToSleep(int why) {
   
        mHandler.sendMessage(mHandler.obtainMessage(MSG_STARTED_GOING_TO_SLEEP, why, 0));
    }
protected void handleStartedGoingToSleep(int arg1) {
   
        Assert.isMainThread();
        mLockIconPressed = false;
        clearBiometricRecognized();
        for (int i = 0; i < mCallbacks.size(); i++) {
   
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
   
                cb.onStartedGoingToSleep(arg1);
            }
        }
        mGoingToSleep = true;
        updateBiometricListeningState();
    }
    private void updateBiometricListeningState() {
   
        updateFingerprintListeningState();
        updateFaceListeningState();
    }
    

6、这里更新了2个监听器的状态,一个是指纹监听器,一个是人脸监听器,我们先看更新指纹监听器的方法

private void updateFingerprintListeningState() {
   
        // If this message exists, we should not authenticate again until this message is
        // consumed by the handler
        if (mHandler.hasMessages(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE)) {
   
            return;
        }
        mHandler.removeCallbacks(mRetryFingerprintAuthentication);
        boolean shouldListenForFingerprint = shouldListenForFingerpri
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值