1 /*
<lambda>null2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.keyguard.data.repository
18 
19 import android.graphics.Point
20 import com.android.keyguard.KeyguardUpdateMonitor
21 import com.android.keyguard.KeyguardUpdateMonitorCallback
22 import com.android.systemui.biometrics.AuthController
23 import com.android.systemui.biometrics.data.repository.FacePropertyRepository
24 import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
25 import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
26 import com.android.systemui.dagger.SysUISingleton
27 import com.android.systemui.dagger.qualifiers.Application
28 import com.android.systemui.dagger.qualifiers.Main
29 import com.android.systemui.doze.DozeMachine
30 import com.android.systemui.doze.DozeTransitionCallback
31 import com.android.systemui.doze.DozeTransitionListener
32 import com.android.systemui.dreams.DreamOverlayCallbackController
33 import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
34 import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
35 import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
36 import com.android.systemui.keyguard.shared.model.DismissAction
37 import com.android.systemui.keyguard.shared.model.DozeStateModel
38 import com.android.systemui.keyguard.shared.model.DozeTransitionModel
39 import com.android.systemui.keyguard.shared.model.KeyguardDone
40 import com.android.systemui.keyguard.shared.model.StatusBarState
41 import com.android.systemui.plugins.statusbar.StatusBarStateController
42 import com.android.systemui.settings.UserTracker
43 import com.android.systemui.statusbar.policy.KeyguardStateController
44 import com.android.systemui.util.time.SystemClock
45 import javax.inject.Inject
46 import kotlinx.coroutines.CoroutineDispatcher
47 import kotlinx.coroutines.CoroutineScope
48 import kotlinx.coroutines.ExperimentalCoroutinesApi
49 import kotlinx.coroutines.channels.awaitClose
50 import kotlinx.coroutines.flow.Flow
51 import kotlinx.coroutines.flow.MutableSharedFlow
52 import kotlinx.coroutines.flow.MutableStateFlow
53 import kotlinx.coroutines.flow.SharingStarted
54 import kotlinx.coroutines.flow.StateFlow
55 import kotlinx.coroutines.flow.asSharedFlow
56 import kotlinx.coroutines.flow.asStateFlow
57 import kotlinx.coroutines.flow.distinctUntilChanged
58 import kotlinx.coroutines.flow.filter
59 import kotlinx.coroutines.flow.flowOn
60 import kotlinx.coroutines.flow.mapLatest
61 import kotlinx.coroutines.flow.onStart
62 import kotlinx.coroutines.flow.stateIn
63 
64 /** Defines interface for classes that encapsulate application state for the keyguard. */
65 interface KeyguardRepository {
66     /**
67      * Observable for whether the bottom area UI should animate the transition out of doze state.
68      *
69      * To learn more about doze state, please see [isDozing].
70      */
71     val animateBottomAreaDozingTransitions: StateFlow<Boolean>
72 
73     /**
74      * Observable for the current amount of alpha that should be used for rendering the bottom area.
75      * UI.
76      */
77     val bottomAreaAlpha: StateFlow<Float>
78 
79     val keyguardAlpha: StateFlow<Float>
80 
81     /**
82      * Observable for whether the keyguard is showing.
83      *
84      * Note: this is also `true` when the lock-screen is occluded with an `Activity` "above" it in
85      * the z-order (which is not really above the system UI window, but rather - the lock-screen
86      * becomes invisible to reveal the "occluding activity").
87      */
88     val isKeyguardShowing: Flow<Boolean>
89 
90     /** Is an activity showing over the keyguard? */
91     @Deprecated("Use KeyguardTransitionInteractor + KeyguardState.OCCLUDED")
92     val isKeyguardOccluded: Flow<Boolean>
93 
94     /**
95      * Whether the device is locked or unlocked right now. This is true when keyguard has been
96      * dismissed or can be dismissed by a swipe
97      */
98     val isKeyguardDismissible: StateFlow<Boolean>
99 
100     /**
101      * Observable for the signal that keyguard is about to go away.
102      *
103      * TODO(b/278086361): Remove once KEYGUARD_WM_STATE_REFACTOR flag is removed.
104      */
105     @Deprecated(
106         "Use KeyguardTransitionInteractor flows instead. The closest match for 'going " +
107             "away' is isInTransitionToState(GONE), but consider using more specific flows " +
108             "whenever possible."
109     )
110     val isKeyguardGoingAway: Flow<Boolean>
111 
112     /**
113      * Whether the keyguard is enabled, per [KeyguardService]. If the keyguard is not enabled, the
114      * lockscreen cannot be shown and the device will go from AOD/DOZING directly to GONE.
115      *
116      * Keyguard can be disabled by selecting Security: "None" in settings, or by apps that hold
117      * permission to do so (such as Phone).
118      *
119      * If the keyguard is disabled while we're locked, we will transition to GONE unless we're in
120      * lockdown mode. If the keyguard is re-enabled, we'll transition back to LOCKSCREEN if we were
121      * locked when it was disabled.
122      */
123     val isKeyguardEnabled: StateFlow<Boolean>
124 
125     /** Is the always-on display available to be used? */
126     val isAodAvailable: StateFlow<Boolean>
127 
128     fun setAodAvailable(value: Boolean)
129 
130     /**
131      * Observable for whether we are in doze state.
132      *
133      * Doze state is the same as "Always on Display" or "AOD". It is the state that the device can
134      * enter to conserve battery when the device is locked and inactive.
135      *
136      * Note that it is possible for the system to be transitioning into doze while this flow still
137      * returns `false`. In order to account for that, observers should also use the
138      * [linearDozeAmount] flow to check if it's greater than `0`
139      */
140     val isDozing: StateFlow<Boolean>
141 
142     /** Keyguard can be clipped at the top as the shade is dragged */
143     val topClippingBounds: MutableStateFlow<Int?>
144 
145     /**
146      * Observable for whether the device is dreaming.
147      *
148      * Dozing/AOD is a specific type of dream, but it is also possible for other non-systemui dreams
149      * to be active, such as screensavers.
150      */
151     val isDreaming: MutableStateFlow<Boolean>
152 
153     /** Observable for whether the device is dreaming with an overlay, see [DreamOverlayService] */
154     val isDreamingWithOverlay: Flow<Boolean>
155 
156     /** Observable for device dreaming state and the active dream is hosted in lockscreen */
157     val isActiveDreamLockscreenHosted: StateFlow<Boolean>
158 
159     /**
160      * Observable for the amount of doze we are currently in.
161      *
162      * While in doze state, this amount can change - driving a cycle of animations designed to avoid
163      * pixel burn-in, etc.
164      *
165      * Also note that the value here may be greater than `0` while [isDozing] is still `false`, this
166      * happens during an animation/transition into doze mode. An observer would be wise to account
167      * for both flows if needed.
168      */
169     val linearDozeAmount: Flow<Float>
170 
171     /** Doze state information, as it transitions */
172     val dozeTransitionModel: Flow<DozeTransitionModel>
173 
174     val lastDozeTapToWakePosition: StateFlow<Point?>
175 
176     /** Last point that [KeyguardRootView] was tapped */
177     val lastRootViewTapPosition: MutableStateFlow<Point?>
178 
179     /** Is the ambient indication area visible? */
180     val ambientIndicationVisible: MutableStateFlow<Boolean>
181 
182     /** Observable for the [StatusBarState] */
183     val statusBarState: StateFlow<StatusBarState>
184 
185     /** Observable for biometric unlock state which includes the mode and unlock source */
186     val biometricUnlockState: StateFlow<BiometricUnlockModel>
187 
188     fun setBiometricUnlockState(
189         unlockMode: BiometricUnlockMode,
190         unlockSource: BiometricUnlockSource?,
191     )
192 
193     /** Approximate location on the screen of the fingerprint sensor. */
194     val fingerprintSensorLocation: Flow<Point?>
195 
196     /** Approximate location on the screen of the face unlock sensor/front facing camera. */
197     val faceSensorLocation: Flow<Point?>
198 
199     /** Whether quick settings or quick-quick settings is visible. */
200     val isQuickSettingsVisible: Flow<Boolean>
201 
202     /** Receive an event for doze time tick */
203     val dozeTimeTick: Flow<Long>
204 
205     /** Observable for DismissAction */
206     val dismissAction: StateFlow<DismissAction>
207 
208     /** Observable updated when keyguardDone should be called either now or soon. */
209     val keyguardDone: Flow<KeyguardDone>
210 
211     /**
212      * Emits after the keyguard is done animating away.
213      *
214      * TODO(b/278086361): Remove once KEYGUARD_WM_STATE_REFACTOR flag is removed.
215      */
216     @Deprecated(
217         "Use KeyguardTransitionInteractor flows instead. The closest match for " +
218             "'keyguardDoneAnimationsFinished' is when the GONE transition is finished."
219     )
220     val keyguardDoneAnimationsFinished: Flow<Unit>
221 
222     /**
223      * Receive whether clock should be centered on lockscreen.
224      *
225      * @deprecated When scene container flag is on use clockShouldBeCentered from domain level.
226      */
227     val clockShouldBeCentered: Flow<Boolean>
228 
229     /**
230      * Whether the primary authentication is required for the given user due to lockdown or
231      * encryption after reboot.
232      */
233     val isEncryptedOrLockdown: Flow<Boolean>
234 
235     /**
236      * Returns `true` if the keyguard is showing; `false` otherwise.
237      *
238      * Note: this is also `true` when the lock-screen is occluded with an `Activity` "above" it in
239      * the z-order (which is not really above the system UI window, but rather - the lock-screen
240      * becomes invisible to reveal the "occluding activity").
241      */
242     fun isKeyguardShowing(): Boolean
243 
244     /** Sets whether the bottom area UI should animate the transition out of doze state. */
245     fun setAnimateDozingTransitions(animate: Boolean)
246 
247     /** Sets the current amount of alpha that should be used for rendering the bottom area. */
248     @Deprecated("Deprecated as part of b/278057014") fun setBottomAreaAlpha(alpha: Float)
249 
250     /** Sets the current amount of alpha that should be used for rendering the keyguard. */
251     fun setKeyguardAlpha(alpha: Float)
252 
253     /** Whether the device is actively dreaming */
254     fun setDreaming(isDreaming: Boolean)
255 
256     /**
257      * Returns whether the keyguard bottom area should be constrained to the top of the lock icon
258      */
259     fun isUdfpsSupported(): Boolean
260 
261     /** Sets whether quick settings or quick-quick settings is visible. */
262     fun setQuickSettingsVisible(isVisible: Boolean)
263 
264     fun setLastDozeTapToWakePosition(position: Point)
265 
266     fun setIsDozing(isDozing: Boolean)
267 
268     fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean)
269 
270     fun dozeTimeTick()
271 
272     fun setDismissAction(dismissAction: DismissAction)
273 
274     suspend fun setKeyguardDone(keyguardDoneType: KeyguardDone)
275 
276     fun setClockShouldBeCentered(shouldBeCentered: Boolean)
277 
278     /**
279      * Updates signal that the keyguard done animations are finished
280      *
281      * TODO(b/278086361): Remove once KEYGUARD_WM_STATE_REFACTOR flag is removed.
282      */
283     @Deprecated(
284         "Use KeyguardTransitionInteractor flows instead. The closest match for " +
285             "'keyguardDoneAnimationsFinished' is when the GONE transition is finished."
286     )
287     fun keyguardDoneAnimationsFinished()
288 
289     /** Sets whether the keyguard is enabled (see [isKeyguardEnabled]). */
290     fun setKeyguardEnabled(enabled: Boolean)
291 }
292 
293 /** Encapsulates application state for the keyguard. */
294 @SysUISingleton
295 class KeyguardRepositoryImpl
296 @Inject
297 constructor(
298     statusBarStateController: StatusBarStateController,
299     private val keyguardStateController: KeyguardStateController,
300     private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
301     private val dozeTransitionListener: DozeTransitionListener,
302     private val authController: AuthController,
303     private val dreamOverlayCallbackController: DreamOverlayCallbackController,
304     @Main private val mainDispatcher: CoroutineDispatcher,
305     @Application private val scope: CoroutineScope,
306     private val systemClock: SystemClock,
307     facePropertyRepository: FacePropertyRepository,
308     private val userTracker: UserTracker,
309 ) : KeyguardRepository {
310     private val _dismissAction: MutableStateFlow<DismissAction> =
311         MutableStateFlow(DismissAction.None)
312     override val dismissAction = _dismissAction.asStateFlow()
313 
setDismissActionnull314     override fun setDismissAction(dismissAction: DismissAction) {
315         _dismissAction.value = dismissAction
316     }
317 
318     private val _keyguardDone: MutableSharedFlow<KeyguardDone> = MutableSharedFlow()
319     override val keyguardDone = _keyguardDone.asSharedFlow()
320 
setKeyguardDonenull321     override suspend fun setKeyguardDone(keyguardDoneType: KeyguardDone) {
322         _keyguardDone.emit(keyguardDoneType)
323     }
324 
325     override val keyguardDoneAnimationsFinished: MutableSharedFlow<Unit> = MutableSharedFlow()
326 
keyguardDoneAnimationsFinishednull327     override fun keyguardDoneAnimationsFinished() {
328         keyguardDoneAnimationsFinished.tryEmit(Unit)
329     }
330 
331     private val _animateBottomAreaDozingTransitions = MutableStateFlow(false)
332     override val animateBottomAreaDozingTransitions =
333         _animateBottomAreaDozingTransitions.asStateFlow()
334 
335     private val _bottomAreaAlpha = MutableStateFlow(1f)
336     override val bottomAreaAlpha = _bottomAreaAlpha.asStateFlow()
337 
338     private val _keyguardAlpha = MutableStateFlow(1f)
339     override val keyguardAlpha = _keyguardAlpha.asStateFlow()
340 
341     private val _clockShouldBeCentered = MutableStateFlow(true)
342     override val clockShouldBeCentered: Flow<Boolean> = _clockShouldBeCentered.asStateFlow()
343 
344     override val topClippingBounds = MutableStateFlow<Int?>(null)
345 
346     override val isKeyguardShowing: Flow<Boolean> =
<lambda>null347         conflatedCallbackFlow {
348                 val callback =
349                     object : KeyguardStateController.Callback {
350                         override fun onKeyguardShowingChanged() {
351                             trySendWithFailureLogging(
352                                 keyguardStateController.isShowing,
353                                 TAG,
354                                 "updated isKeyguardShowing"
355                             )
356                         }
357                     }
358 
359                 keyguardStateController.addCallback(callback)
360                 // Adding the callback does not send an initial update.
361                 trySendWithFailureLogging(
362                     keyguardStateController.isShowing,
363                     TAG,
364                     "initial isKeyguardShowing"
365                 )
366 
367                 awaitClose { keyguardStateController.removeCallback(callback) }
368             }
369             .distinctUntilChanged()
370 
371     private val _isAodAvailable = MutableStateFlow(false)
372     override val isAodAvailable: StateFlow<Boolean> = _isAodAvailable.asStateFlow()
373 
setAodAvailablenull374     override fun setAodAvailable(value: Boolean) {
375         _isAodAvailable.value = value
376     }
377 
378     override val isKeyguardOccluded: Flow<Boolean> =
<lambda>null379         conflatedCallbackFlow {
380                 val callback =
381                     object : KeyguardStateController.Callback {
382                         override fun onKeyguardShowingChanged() {
383                             trySendWithFailureLogging(
384                                 keyguardStateController.isOccluded,
385                                 TAG,
386                                 "updated isKeyguardOccluded"
387                             )
388                         }
389                     }
390 
391                 keyguardStateController.addCallback(callback)
392                 // Adding the callback does not send an initial update.
393                 trySendWithFailureLogging(
394                     keyguardStateController.isOccluded,
395                     TAG,
396                     "initial isKeyguardOccluded"
397                 )
398 
399                 awaitClose { keyguardStateController.removeCallback(callback) }
400             }
401             .distinctUntilChanged()
402 
403     override val isKeyguardDismissible: StateFlow<Boolean> =
<lambda>null404         conflatedCallbackFlow {
405                 val callback =
406                     object : KeyguardStateController.Callback {
407                         override fun onUnlockedChanged() {
408                             trySendWithFailureLogging(
409                                 keyguardStateController.isUnlocked,
410                                 TAG,
411                                 "updated isKeyguardDismissible due to onUnlockedChanged"
412                             )
413                         }
414 
415                         override fun onKeyguardShowingChanged() {
416                             trySendWithFailureLogging(
417                                 keyguardStateController.isUnlocked,
418                                 TAG,
419                                 "updated isKeyguardDismissible due to onKeyguardShowingChanged"
420                             )
421                         }
422                     }
423 
424                 keyguardStateController.addCallback(callback)
425                 // Adding the callback does not send an initial update.
426                 trySendWithFailureLogging(
427                     keyguardStateController.isUnlocked,
428                     TAG,
429                     "initial isKeyguardUnlocked"
430                 )
431 
432                 awaitClose { keyguardStateController.removeCallback(callback) }
433             }
434             .distinctUntilChanged()
435             .stateIn(
436                 scope,
437                 SharingStarted.Eagerly,
438                 initialValue = false,
439             )
440 
<lambda>null441     override val isKeyguardGoingAway: Flow<Boolean> = conflatedCallbackFlow {
442         val callback =
443             object : KeyguardStateController.Callback {
444                 override fun onKeyguardGoingAwayChanged() {
445                     trySendWithFailureLogging(
446                         keyguardStateController.isKeyguardGoingAway,
447                         TAG,
448                         "updated isKeyguardGoingAway"
449                     )
450                 }
451             }
452 
453         keyguardStateController.addCallback(callback)
454         // Adding the callback does not send an initial update.
455         trySendWithFailureLogging(
456             keyguardStateController.isKeyguardGoingAway,
457             TAG,
458             "initial isKeyguardGoingAway"
459         )
460 
461         awaitClose { keyguardStateController.removeCallback(callback) }
462     }
463 
464     private val _isKeyguardEnabled = MutableStateFlow(true)
465     override val isKeyguardEnabled: StateFlow<Boolean> = _isKeyguardEnabled.asStateFlow()
466 
467     private val _isDozing = MutableStateFlow(statusBarStateController.isDozing)
468     override val isDozing: StateFlow<Boolean> = _isDozing.asStateFlow()
469 
setIsDozingnull470     override fun setIsDozing(isDozing: Boolean) {
471         _isDozing.value = isDozing
472     }
473 
474     private val _dozeTimeTick = MutableStateFlow<Long>(0)
475     override val dozeTimeTick = _dozeTimeTick.asStateFlow()
476 
dozeTimeTicknull477     override fun dozeTimeTick() {
478         _dozeTimeTick.value = systemClock.uptimeMillis()
479     }
480 
481     private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null)
482     override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow()
483 
setLastDozeTapToWakePositionnull484     override fun setLastDozeTapToWakePosition(position: Point) {
485         _lastDozeTapToWakePosition.value = position
486     }
487 
488     override val lastRootViewTapPosition: MutableStateFlow<Point?> = MutableStateFlow(null)
489 
490     override val ambientIndicationVisible: MutableStateFlow<Boolean> = MutableStateFlow(false)
491 
492     override val isDreamingWithOverlay: Flow<Boolean> =
<lambda>null493         conflatedCallbackFlow {
494                 val callback =
495                     object : DreamOverlayCallbackController.Callback {
496                         override fun onStartDream() {
497                             trySendWithFailureLogging(true, TAG, "updated isDreamingWithOverlay")
498                         }
499 
500                         override fun onWakeUp() {
501                             trySendWithFailureLogging(false, TAG, "updated isDreamingWithOverlay")
502                         }
503                     }
504                 dreamOverlayCallbackController.addCallback(callback)
505                 trySendWithFailureLogging(
506                     dreamOverlayCallbackController.isDreaming,
507                     TAG,
508                     "initial isDreamingWithOverlay",
509                 )
510 
511                 awaitClose { dreamOverlayCallbackController.removeCallback(callback) }
512             }
513             .distinctUntilChanged()
514 
515     override val isDreaming: MutableStateFlow<Boolean> = MutableStateFlow(false)
516 
<lambda>null517     override val linearDozeAmount: Flow<Float> = conflatedCallbackFlow {
518         val callback =
519             object : StatusBarStateController.StateListener {
520                 override fun onDozeAmountChanged(linear: Float, eased: Float) {
521                     trySendWithFailureLogging(linear, TAG, "updated dozeAmount")
522                 }
523             }
524 
525         statusBarStateController.addCallback(callback)
526         trySendWithFailureLogging(statusBarStateController.dozeAmount, TAG, "initial dozeAmount")
527 
528         awaitClose { statusBarStateController.removeCallback(callback) }
529     }
530 
<lambda>null531     override val dozeTransitionModel: Flow<DozeTransitionModel> = conflatedCallbackFlow {
532         val callback =
533             object : DozeTransitionCallback {
534                 override fun onDozeTransition(
535                     oldState: DozeMachine.State,
536                     newState: DozeMachine.State
537                 ) {
538                     trySendWithFailureLogging(
539                         DozeTransitionModel(
540                             from = dozeMachineStateToModel(oldState),
541                             to = dozeMachineStateToModel(newState),
542                         ),
543                         TAG,
544                         "doze transition model"
545                     )
546                 }
547             }
548 
549         dozeTransitionListener.addCallback(callback)
550         trySendWithFailureLogging(
551             DozeTransitionModel(
552                 from = dozeMachineStateToModel(dozeTransitionListener.oldState),
553                 to = dozeMachineStateToModel(dozeTransitionListener.newState),
554             ),
555             TAG,
556             "initial doze transition model"
557         )
558 
559         awaitClose { dozeTransitionListener.removeCallback(callback) }
560     }
561 
562     @OptIn(ExperimentalCoroutinesApi::class)
563     override val isEncryptedOrLockdown: Flow<Boolean> =
<lambda>null564         conflatedCallbackFlow {
565                 val callback =
566                     object : KeyguardUpdateMonitorCallback() {
567                         override fun onStrongAuthStateChanged(userId: Int) {
568                             trySendWithFailureLogging(userId, TAG, "strong auth state change")
569                         }
570                     }
571                 keyguardUpdateMonitor.registerCallback(callback)
572                 awaitClose { keyguardUpdateMonitor.removeCallback(callback) }
573             }
userIdnull574             .filter { userId -> userId == userTracker.userId }
<lambda>null575             .onStart { emit(userTracker.userId) }
userIdnull576             .mapLatest { userId -> keyguardUpdateMonitor.isEncryptedOrLockdown(userId) }
577             // KeyguardUpdateMonitor#registerCallback needs to be called on the main thread.
578             .flowOn(mainDispatcher)
579 
isKeyguardShowingnull580     override fun isKeyguardShowing(): Boolean {
581         return keyguardStateController.isShowing
582     }
583 
584     // TODO(b/297345631): Expose this at the interactor level instead so that it can be powered by
585     // [SceneInteractor] when scenes are ready.
586     override val statusBarState: StateFlow<StatusBarState> =
<lambda>null587         conflatedCallbackFlow {
588                 val callback =
589                     object : StatusBarStateController.StateListener {
590                         override fun onStateChanged(state: Int) {
591                             trySendWithFailureLogging(
592                                 statusBarStateIntToObject(state),
593                                 TAG,
594                                 "state"
595                             )
596                         }
597                     }
598 
599                 statusBarStateController.addCallback(callback)
600                 awaitClose { statusBarStateController.removeCallback(callback) }
601             }
602             .stateIn(
603                 scope,
604                 SharingStarted.Eagerly,
605                 statusBarStateIntToObject(statusBarStateController.state)
606             )
607 
608     private val _biometricUnlockState: MutableStateFlow<BiometricUnlockModel> =
609         MutableStateFlow(BiometricUnlockModel(BiometricUnlockMode.NONE, null))
610     override val biometricUnlockState: StateFlow<BiometricUnlockModel> =
611         _biometricUnlockState.asStateFlow()
612 
setBiometricUnlockStatenull613     override fun setBiometricUnlockState(
614         unlockMode: BiometricUnlockMode,
615         unlockSource: BiometricUnlockSource?,
616     ) {
617         _biometricUnlockState.value = BiometricUnlockModel(unlockMode, unlockSource)
618     }
619 
<lambda>null620     override val fingerprintSensorLocation: Flow<Point?> = conflatedCallbackFlow {
621         fun sendFpLocation() {
622             trySendWithFailureLogging(
623                 authController.fingerprintSensorLocation,
624                 TAG,
625                 "AuthController.Callback#onFingerprintLocationChanged"
626             )
627         }
628 
629         val callback =
630             object : AuthController.Callback {
631                 override fun onFingerprintLocationChanged() {
632                     sendFpLocation()
633                 }
634             }
635 
636         authController.addCallback(callback)
637         sendFpLocation()
638 
639         awaitClose { authController.removeCallback(callback) }
640     }
641 
642     override val faceSensorLocation: Flow<Point?> = facePropertyRepository.sensorLocation
643 
644     private val _isQuickSettingsVisible = MutableStateFlow(false)
645     override val isQuickSettingsVisible: Flow<Boolean> = _isQuickSettingsVisible.asStateFlow()
646 
647     private val _isActiveDreamLockscreenHosted = MutableStateFlow(false)
648     override val isActiveDreamLockscreenHosted = _isActiveDreamLockscreenHosted.asStateFlow()
649 
setAnimateDozingTransitionsnull650     override fun setAnimateDozingTransitions(animate: Boolean) {
651         _animateBottomAreaDozingTransitions.value = animate
652     }
653 
setBottomAreaAlphanull654     override fun setBottomAreaAlpha(alpha: Float) {
655         _bottomAreaAlpha.value = alpha
656     }
657 
setKeyguardAlphanull658     override fun setKeyguardAlpha(alpha: Float) {
659         _keyguardAlpha.value = alpha
660     }
661 
setDreamingnull662     override fun setDreaming(isDreaming: Boolean) {
663         this.isDreaming.value = isDreaming
664     }
665 
isUdfpsSupportednull666     override fun isUdfpsSupported(): Boolean = keyguardUpdateMonitor.isUdfpsSupported
667 
668     override fun setQuickSettingsVisible(isVisible: Boolean) {
669         _isQuickSettingsVisible.value = isVisible
670     }
671 
setIsActiveDreamLockscreenHostednull672     override fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean) {
673         _isActiveDreamLockscreenHosted.value = isLockscreenHosted
674     }
675 
setClockShouldBeCenterednull676     override fun setClockShouldBeCentered(shouldBeCentered: Boolean) {
677         _clockShouldBeCentered.value = shouldBeCentered
678     }
679 
setKeyguardEnablednull680     override fun setKeyguardEnabled(enabled: Boolean) {
681         _isKeyguardEnabled.value = enabled
682     }
683 
statusBarStateIntToObjectnull684     private fun statusBarStateIntToObject(value: Int): StatusBarState {
685         return when (value) {
686             0 -> StatusBarState.SHADE
687             1 -> StatusBarState.KEYGUARD
688             2 -> StatusBarState.SHADE_LOCKED
689             else -> throw IllegalArgumentException("Invalid StatusBarState value: $value")
690         }
691     }
692 
dozeMachineStateToModelnull693     private fun dozeMachineStateToModel(state: DozeMachine.State): DozeStateModel {
694         return when (state) {
695             DozeMachine.State.UNINITIALIZED -> DozeStateModel.UNINITIALIZED
696             DozeMachine.State.INITIALIZED -> DozeStateModel.INITIALIZED
697             DozeMachine.State.DOZE -> DozeStateModel.DOZE
698             DozeMachine.State.DOZE_SUSPEND_TRIGGERS -> DozeStateModel.DOZE_SUSPEND_TRIGGERS
699             DozeMachine.State.DOZE_AOD -> DozeStateModel.DOZE_AOD
700             DozeMachine.State.DOZE_REQUEST_PULSE -> DozeStateModel.DOZE_REQUEST_PULSE
701             DozeMachine.State.DOZE_PULSING -> DozeStateModel.DOZE_PULSING
702             DozeMachine.State.DOZE_PULSING_BRIGHT -> DozeStateModel.DOZE_PULSING_BRIGHT
703             DozeMachine.State.DOZE_PULSE_DONE -> DozeStateModel.DOZE_PULSE_DONE
704             DozeMachine.State.FINISH -> DozeStateModel.FINISH
705             DozeMachine.State.DOZE_AOD_PAUSED -> DozeStateModel.DOZE_AOD_PAUSED
706             DozeMachine.State.DOZE_AOD_PAUSING -> DozeStateModel.DOZE_AOD_PAUSING
707             DozeMachine.State.DOZE_AOD_DOCKED -> DozeStateModel.DOZE_AOD_DOCKED
708             else -> throw IllegalArgumentException("Invalid DozeMachine.State: state")
709         }
710     }
711 
712     companion object {
713         private const val TAG = "KeyguardRepositoryImpl"
714     }
715 }
716