• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2024 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.domain.interactor
18 
19 import android.util.Log
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.dagger.qualifiers.Application
22 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
23 import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository
24 import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
25 import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
26 import com.android.systemui.keyguard.shared.model.KeyguardState.OFF
27 import com.android.systemui.scene.shared.flag.SceneContainerFlag
28 import com.android.systemui.statusbar.policy.domain.interactor.DeviceProvisioningInteractor
29 import javax.inject.Inject
30 import kotlinx.coroutines.CoroutineScope
31 import kotlinx.coroutines.flow.Flow
32 import kotlinx.coroutines.flow.first
33 import kotlinx.coroutines.flow.map
34 import com.android.app.tracing.coroutines.launchTraced as launch
35 
36 /** Handles initialization of the KeyguardTransitionRepository on boot. */
37 @SysUISingleton
38 class KeyguardTransitionBootInteractor
39 @Inject
40 constructor(
41     @Application val scope: CoroutineScope,
42     val deviceEntryInteractor: DeviceEntryInteractor,
43     val deviceProvisioningInteractor: DeviceProvisioningInteractor,
44     val keyguardTransitionInteractor: KeyguardTransitionInteractor,
45     val internalTransitionInteractor: InternalKeyguardTransitionInteractor,
46     val repository: KeyguardTransitionRepository,
47 ) {
48 
49     /**
50      * Whether the lockscreen should be showing when the device starts up for the first time. If not
51      * then we'll seed the repository with a transition from OFF -> GONE.
52      */
53     private val showLockscreenOnBoot: Flow<Boolean> by lazy {
54         deviceProvisioningInteractor.isDeviceProvisioned.map { provisioned ->
55             (provisioned || deviceEntryInteractor.isAuthenticationRequired()) &&
56                 deviceEntryInteractor.isLockscreenEnabled()
57         }
58     }
59 
60     fun start() {
61         scope.launch {
62             if (internalTransitionInteractor.currentTransitionInfoInternal().from != OFF) {
63                 Log.e(
64                     "KeyguardTransitionInteractor",
65                     "showLockscreenOnBoot emitted, but we've already " +
66                         "transitioned to a state other than OFF. We'll respect that " +
67                         "transition, but this should not happen.",
68                 )
69             } else {
70                 if (SceneContainerFlag.isEnabled) {
71                     // TODO(b/360372242): Some part of the transition implemented for flag off is
72                     //  missing here. There are two things achieved with this:
73                     //  1. Keyguard is hidden when the setup wizard is shown. This part is already
74                     //     implemented in scene container by disabling visibility instead of going
75                     //     to Gone. See [SceneContainerStartable.hydrateVisibility]. We might want
76                     //     to unify this logic here.
77                     //  2. When the auth method is set to NONE device boots into Gone (Launcher).
78                     //     For this we would just need to call changeScene(Scene.Gone).
79                     //     Unfortunately STL doesn't seem to be initialized at this point, therefore
80                     //     it needs a different solution.
81                     repository.emitInitialStepsFromOff(LOCKSCREEN)
82                 } else {
83                     repository.emitInitialStepsFromOff(
84                         if (showLockscreenOnBoot.first()) LOCKSCREEN else GONE
85                     )
86                 }
87             }
88         }
89     }
90 }
91