1 /*
2  * Copyright (C) 2023 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 com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.keyguard.domain.interactor.InWindowLauncherUnlockAnimationInteractor
21 import com.android.systemui.shared.system.smartspace.ILauncherUnlockAnimationController
22 import com.android.systemui.shared.system.smartspace.SmartspaceState
23 import javax.inject.Inject
24 import kotlinx.coroutines.flow.MutableStateFlow
25 
26 /**
27  * State related to System UI's handling of the in-window Launcher unlock animations. This includes
28  * the staggered icon entry animation that plays during unlock, as well as the smartspace shared
29  * element animation, if supported.
30  *
31  * While the animations themselves occur fully in the Launcher window, System UI is responsible for
32  * preparing/starting the animations, as well as synchronizing the smartspace state so that the two
33  * smartspaces appear visually identical for the shared element animation.
34  */
35 @SysUISingleton
36 class InWindowLauncherUnlockAnimationRepository @Inject constructor() {
37 
38     /**
39      * Whether we have called [ILauncherUnlockAnimationController.playUnlockAnimation] during this
40      * unlock sequence. This value is set back to false once
41      * [InWindowLauncherUnlockAnimationInteractor.shouldStartInWindowAnimation] reverts to false,
42      * which happens when we're no longer in transition to GONE or if the remote animation ends or
43      * is cancelled.
44      */
45     val startedUnlockAnimation = MutableStateFlow(false)
46 
47     /**
48      * The unlock amount we've explicitly passed to
49      * [ILauncherUnlockAnimationController.setUnlockAmount]. This is used whenever System UI is
50      * directly controlling the amount of the unlock animation, such as during a manual swipe to
51      * unlock gesture.
52      *
53      * This value is *not* updated if we called
54      * [ILauncherUnlockAnimationController.playUnlockAnimation] to ask Launcher to animate all the
55      * way unlocked, since that animator is running in the Launcher window.
56      */
57     val manualUnlockAmount: MutableStateFlow<Float?> = MutableStateFlow(null)
58 
59     /**
60      * The class name of the Launcher activity that provided us with a
61      * [ILauncherUnlockAnimationController], if applicable. We can use this to check if that
62      * launcher is underneath the lockscreen before playing in-window animations.
63      *
64      * If null, we have not been provided with a launcher unlock animation controller.
65      */
66     val launcherActivityClass: MutableStateFlow<String?> = MutableStateFlow(null)
67 
68     /**
69      * Information about the Launcher's smartspace, which is passed to us via
70      * [ILauncherUnlockAnimationController].
71      */
72     val launcherSmartspaceState: MutableStateFlow<SmartspaceState?> = MutableStateFlow(null)
73 
setStartedUnlockAnimationnull74     fun setStartedUnlockAnimation(started: Boolean) {
75         startedUnlockAnimation.value = started
76     }
77 
setManualUnlockAmountnull78     fun setManualUnlockAmount(amount: Float?) {
79         manualUnlockAmount.value = amount
80     }
81 
setLauncherActivityClassnull82     fun setLauncherActivityClass(className: String) {
83         launcherActivityClass.value = className
84     }
85 
setLauncherSmartspaceStatenull86     fun setLauncherSmartspaceState(state: SmartspaceState?) {
87         launcherSmartspaceState.value = state
88     }
89 }
90