KeyguardService
@startuml
top to bottom direction
rectangle "客户端" {
KeyguardServiceDelegate -up-> KeyguardServiceWrapper
}
rectangle "服务端" {
KeyguardService <..right.> KeyguardServiceWrapper : AIDL
KeyguardService -left-> KeyguardLifecyclesDispatcher
KeyguardService -down-> KeyguardViewMediator
KeyguardViewMediator --> KeyguardUpdateMonitor
KeyguardViewMediator --> KeyguardStateController
KeyguardViewMediator --> KeyguardViewControlle
}
@enduml
KeyguardService 是 Keyguard 的服务端,与之对应的是 KeyguardServiceDelegate 位于客户端,KeyguardServiceDelegate 持有 KeyguardServiceWrapper 的引用,KeyguardServiceWrapper 负责使用 AIDL 与 KeyguardService 通信
KeyguardService 持有 KeyguardViewMediator 和 KeyguardLifecyclesDispatcher 的引用,KeyguardLifecyclesDispatcher 用于分发 Keyguard 从 WindowManager 上获取的生命周期,而 KeyguardViewMediator 从名字上看就知道这里用了中介者(Mediator)模式,该类用于中介 Keyguard 相关的请求,很多来自 AIDL 的请求将会委托给 KeyguardViewMediator 处理。
KeyguardViewMediator
KeyguardViewMediator 下持有三个比较重要的引用,分别是 KeyguardUpdateMonitor、
KeyguardStateController、KeyguardViewControlle
KeyguardUpdateMonitor
@startuml
KeyguardService -down-> KeyguardViewMediator
KeyguardViewMediator --> KeyguardUpdateMonitor
BroadcastReceiver --> KeyguardUpdateMonitor
FingerprintManager ..> AuthenticationCallback
AuthenticationCallback --> KeyguardUpdateMonitor
StatusBarStateController ..> StateListener
StateListener --> KeyguardUpdateMonitor
TelephonyManager ..> ActiveDataSubscriptionIdListener
ActiveDataSubscriptionIdListener --> KeyguardUpdateMonitor
TaskStackChangeListeners ..> TaskStackChangeListener
TaskStackChangeListener --> KeyguardUpdateMonitor
KeyguardUpdateMonitor ..> KeyguardUpdateMonitorCallback
KeyguardUpdateMonitorCallback --> KeyguardBouncer
KeyguardUpdateMonitorCallback --> StatusBarKeyguardViewManager
KeyguardUpdateMonitorCallback --> KeyguardHostViewController
KeyguardUpdateMonitorCallback --> KeyguardPINView
KeyguardUpdateMonitorCallback --> KeyguardViewMediator
@enduml
KeyguardUpdateMonitor 用于监听 keyguard 可能感兴趣的更新,并提供注册回调的方法,其内部持有
KeyguardUpdateMonitorCallback 类型的 callback 数组,其他模块可以通过 com.android.keyguard.KeyguardUpdateMonitor#registerCallback 方法,向 KeyguardUpdateMonitor 注册回调,而 KeyguardUpdateMonitor 也在向其他模块注册回调,当 KeyguardUpdateMonitor 收到来自其他模块或者来自广播的回调时,它会将回调的信息进行整理与转换,然后在自己的 callback 数组里进行广播
向 KeyguardUpdateMonitor 注册回调的类有很多,在 Android 12 上打印 log 可以看到至少包含下面对象
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.policy.KeyguardStateControllerImpl$UpdateMonitorCallback@5e3a4c1
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.keyguard.KeyguardSliceProvider$2@555416f
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.classifier.FalsingCollectorImpl$2@6d617e5
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.sonymobile.keyguard.statistics.LockscreenStatisticsFingerprintAccuracyReporter@71a354b
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.doze.DozeLog$1@3d0dc47
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.BiometricUnlockController@8f59c74
04-29 22:31:10.583 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.accessibility.floatingmenu.AccessibilityFloatingMenuController$1@a0a0be0
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.KeyguardIndicationController$BaseKeyguardCallback@fd4f972
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.KeyguardIndicationController$4@e68fa40
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.sonymobile.keyguard.aod.FingerPrintFeedBackView$FingerprintFBCallBack@7dda55a
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.ScrimController$KeyguardVisibilityCallback@9f98ed2
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.notification.collection.coordinator.KeyguardCoordinator$6@380d706
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.KeyguardBouncer$1@2584c90
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager$3@e4ca989
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.StatusBar$5@b421d8e
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.wmshell.WMShell$2@95f5b5a
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.wmshell.WMShell$4@977d681
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.wmshell.WMShell$7@427d326
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.NotificationPanelViewController$1@a68d435
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.statusbar.phone.KeyguardBottomAreaView$10@1c33f70
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.EmergencyButtonController$1@e1652e9
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.LockIconViewController$3@5fa7b6e
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.KeyguardStatusViewController$2@256420f
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.AnimatableClockController$4@f40e934
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.AnimatableClockController$4@7e9535d
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.biometrics.AuthRippleController$keyguardUpdateMonitorCallback$1@b0147f
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.systemui.keyguard.KeyguardViewMediator$2@3b8279e
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.KeyguardHostViewController$1@3a7df7b
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.KeyguardPINView$1@8c81870
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.KeyguardMessageAreaController$1@b44b7e9
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.EmergencyButtonController$1@3817c6e
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.CarrierTextManager$2@9a65f9a
04-29 22:31:10.584 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.CarrierTextManager$2@3d5a25a
04-29 22:31:10.585 29196 29196 D KeyguardUpdateMonitor: onFingerprintAuthenticated: com.android.keyguard.CarrierTextManager$2@4ec50f9
从上面观察到 KeyguardViewMediator 也会向 KeyguardUpdateMonitor 注册回调,KeyguardViewMediator 常从 KeyguardUpdateMonitor 上得到消息后,更新自身储存的 keyguard 状态信息,然后再委托其他模块进行操作
KeyguardStateController
@startuml
KeyguardService -down-> KeyguardViewMediator
KeyguardViewMediator --> KeyguardUpdateMonitor
KeyguardStateController <|.. KeyguardStateControllerImpl
KeyguardUpdateMonitor -> KeyguardStateController
KeyguardUpdateMonitor ..> KeyguardUpdateMonitorCallback
KeyguardUpdateMonitorCallback --> KeyguardStateControllerImpl
KeyguardStateControllerImpl ..> KeyguardStateController$Callback
KeyguardStateController$Callback --> KeyguardStatusViewController
KeyguardStatusViewController -> KeyguardStateControllerImpl
@enduml
KeyguardStateController 用于储存 keyguard 的真实状态:是否锁定、堵塞、有密码、受信任等。KeyguardStateController 是一个接口,它的功能由 KeyguardStateControllerImpl 实现, KeyguardStateControllerImpl 会在构造函数中向 KeyguardUpdateMonitor 注册回调,以此来保障自身存储的数据的实时性。
KeyguardStateController 也有自己的回调 KeyguardStateController.Callback
有很多像 KeyguardStatusViewController 这样的类都持有 KeyguardStateController 的引用,他们可以通过 KeyguardStateController 主动获取、更新当前 Keyguard 的状态,也可以通过注册 callback 被动接收状态改变的通知
KeyguardViewControlle
KeyguardViewControlle 用于控制 Keyguard 视图,其实现类为 StatusBarKeyguardViewManager,该类用于管理 statusbar 中 Keyguard 的出现、消失等