publicvoidonStartedGoingToSleep(int why) { if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")"); synchronized (this) { mDeviceInteractive = false; mGoingToSleep = true; // 这位置的代码作用具体不知,但放在前面可以解决息屏后又立马使用指纹解锁时:出现1.2s内没反应的问题。 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. intcurrentUser= KeyguardUpdateMonitor.getCurrentUser(); finalbooleanlockImmediately= mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser) || !mLockPatternUtils.isSecure(currentUser); longtimeout= getLockTimeout(KeyguardUpdateMonitor.getCurrentUser()); mLockLater = false; // 省略部分代码...... //判断是否需要播放锁屏音 if (mPendingLock) { playSounds(true); } } // 使得KeyguardUpdateMonitor可以监听到GoingToSleep // KeyguardUpdateMonitor 是Keyguard更新监视器 mUpdateMonitor.dispatchStartedGoingToSleep(why); //通知开始息屏 notifyStartedGoingToSleep(); }
12-10 09:43:41.437 1468 1468 D updateFaceListeningState: java.lang.Throwable 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.updateFaceListeningState(KeyguardUpdateMonitor.java:2128) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.updateBiometricListeningState(KeyguardUpdateMonitor.java:2053) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.setKeyguardGoingAway(KeyguardUpdateMonitor.java:575) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.handleKeyguardGoingAway(KeyguardUpdateMonitor.java:1727) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.access$5000(KeyguardUpdateMonitor.java:143) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor$16.handleMessage(KeyguardUpdateMonitor.java:1872) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at android.os.Handler.dispatchMessage(Handler.java:106) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at android.os.Looper.loop(Looper.java:223) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at android.app.ActivityThread.main(ActivityThread.java:7945) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at java.lang.reflect.Method.invoke(Native Method) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 12-10 09:43:41.437 1468 1468 V KeyguardUpdateMonitor: at com.android.keyguard.KeyguardUpdateMonitor.updateFaceListeningState(KeyguardUpdateMonitor.java:2129)
电源键息屏堆栈:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
12-10 09:43:41.437 1468 1468 D updateFaceListeningState: java.lang.Throwable 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.updateFaceListeningState(KeyguardUpdateMonitor.java:2128) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.updateBiometricListeningState(KeyguardUpdateMonitor.java:2053) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.setKeyguardGoingAway(KeyguardUpdateMonitor.java:575) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.handleKeyguardGoingAway(KeyguardUpdateMonitor.java:1727) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor.access$5000(KeyguardUpdateMonitor.java:143) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.keyguard.KeyguardUpdateMonitor$16.handleMessage(KeyguardUpdateMonitor.java:1872) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at android.os.Handler.dispatchMessage(Handler.java:106) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at android.os.Looper.loop(Looper.java:223) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at android.app.ActivityThread.main(ActivityThread.java:7945) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at java.lang.reflect.Method.invoke(Native Method) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603) 12-10 09:43:41.437 1468 1468 D updateFaceListeningState: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 12-10 09:43:41.437 1468 1468 V KeyguardUpdateMonitor: at com.android.keyguard.KeyguardUpdateMonitor.updateFaceListeningState(KeyguardUpdateMonitor.java:2129)
12-10 16:33:49.998 1017 1017 D longzhiye : longzhiye:FaceService.java ServiceListenerImpl onAuthenticationSucceeded() 12-10 16:33:49.998 1017 1017 D longzhiye : java.lang.Throwable 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.face.FaceService$ServiceListenerImpl.onAuthenticationSucceeded(FaceService.java:918) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.AuthenticationClient.onAuthenticated(AuthenticationClient.java:235) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.face.FaceService$FaceAuthClient.onAuthenticated(FaceService.java:297) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.BiometricServiceBase.handleAuthenticated(BiometricServiceBase.java:729) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.face.FaceService.access$11801(FaceService.java:110) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.face.FaceService$1.lambda$onAuthenticated$2$FaceService$1(FaceService.java:1040) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.biometrics.face.-$$Lambda$FaceService$1$GcU4ZG1fdDLhKvSxuMwfPargEnI.run(Unknown Source:8) 12-10 16:33:49.998 1017 1017 D longzhiye : at android.os.Handler.handleCallback(Handler.java:938) 12-10 16:33:49.998 1017 1017 D longzhiye : at android.os.Handler.dispatchMessage(Handler.java:99) 12-10 16:33:49.998 1017 1017 D longzhiye : at android.os.Looper.loop(Looper.java:223) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.SystemServer.run(SystemServer.java:647) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.server.SystemServer.main(SystemServer.java:431) 12-10 16:33:49.998 1017 1017 D longzhiye : at java.lang.reflect.Method.invoke(Native Method) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603) 12-10 16:33:49.998 1017 1017 D longzhiye : at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)
根据前面的讲的 底层 Face HIDL 可以知道 IExtBiometricsFaceClientCallback 是回调人脸识别结果的。onAuthenticated()是当一张人脸被成功认证时被回调。 frameworks/base/services/core/java/com/android/server/biometrics/face/FaceService.java
// For face, the authentication lifecycle ends either when // 1) Authenticated == true // 2) Error occurred // 3) Authenticated == false // Fingerprint currently does not end when the third condition is met which is a bug, // but let's leave it as-is for now. return result || !authenticated; }
12-10 16:33:50.024 1414 1414 D longzhiye : java.lang.Throwable 12-10 16:33:50.024 1414 1414 D longzhiye : at com.android.keyguard.KeyguardUpdateMonitor$15.onAuthenticationSucceeded(KeyguardUpdateMonitor.java:1427) 12-10 16:33:50.024 1414 1414 D longzhiye : at android.hardware.face.FaceManager.sendAuthenticatedSucceeded(FaceManager.java:1212) 12-10 16:33:50.024 1414 1414 D longzhiye : at android.hardware.face.FaceManager.access$1300(FaceManager.java:63) 12-10 16:33:50.024 1414 1414 D longzhiye : at android.hardware.face.FaceManager$MyHandler.handleMessage(FaceManager.java:1120) 12-10 16:33:50.024 1414 1414 D longzhiye : at android.os.Handler.dispatchMessage(Handler.java:106) 12-10 16:33:50.024 1414 1414 D longzhiye : at android.os.Looper.loop(Looper.java:223) 12-10 16:33:50.024 1414 1414 D longzhiye : at android.app.ActivityThread.main(ActivityThread.java:7945) 12-10 16:33:50.024 1414 1414 D longzhiye : at java.lang.reflect.Method.invoke(Native Method) 12-10 16:33:50.024 1414 1414 D longzhiye : at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603) 12-10 16:33:50.024 1414 1414 D longzhiye : at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
protectedvoidonFaceAuthenticated(int userId) { Trace.beginSection("KeyGuardUpdateMonitor#onFaceAuthenticated"); mUserFaceAuthenticated.put(userId, true); // Update/refresh trust state only if user can skip bouncer if (getUserCanSkipBouncer(userId)) { mTrustManager.unlockedByBiometricForUser(userId, BiometricSourceType.FACE); } // Don't send cancel if authentication succeeds mFaceCancelSignal = null; for (inti=0; i < mCallbacks.size(); i++) { /*重点关注*/ KeyguardUpdateMonitorCallbackcb= mCallbacks.get(i).get(); if (cb != null) { /*重点关注*/ cb.onBiometricAuthenticated(userId, BiometricSourceType.FACE); } } mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_BIOMETRIC_AUTHENTICATION_CONTINUE), BIOMETRIC_CONTINUE_DELAY_MS); // Only authenticate face once when assistant is visible mAssistantVisible = false; Trace.endSection(); }
privatevoidhandleHide() { Trace.beginSection("KeyguardViewMediator#handleHide"); // It's possible that the device was unlocked in a dream state. It's time to wake up. if (mAodShowing) { PowerManagerpm= mContext.getSystemService(PowerManager.class); pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, "com.android.systemui:BOUNCER_DOZING"); } synchronized (KeyguardViewMediator.this) { if (DEBUG) Log.d(TAG, "handleHide"); if (mustNotUnlockCurrentUser()) { if (DEBUG) Log.d(TAG, "Split system user, quit unlocking."); return; } mHiding = true; if (mShowing && !mOccluded) { mKeyguardGoingAwayRunnable.run(); } else { /*重点关注*/ // 处理开始键盘保护退出动画 handleStartKeyguardExitAnimation( SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(), mHideAnimation.getDuration()); } } Trace.endSection(); }