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 com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.dagger.qualifiers.Background
21 import com.android.systemui.keyguard.shared.model.KeyguardState
22 import com.android.systemui.shade.data.repository.ShadeRepository
23 import com.android.systemui.util.kotlin.Utils.Companion.sample
24 import javax.inject.Inject
25 import kotlinx.coroutines.CoroutineScope
26 import kotlinx.coroutines.flow.SharingStarted
27 import kotlinx.coroutines.flow.filter
28 import kotlinx.coroutines.flow.map
29 import kotlinx.coroutines.flow.stateIn
30 
31 /**
32  * Handles logic around the swipe to dismiss gesture, where the user swipes up on the dismissable
33  * lockscreen to unlock the device.
34  */
35 @SysUISingleton
36 class SwipeToDismissInteractor
37 @Inject
38 constructor(
39     @Background backgroundScope: CoroutineScope,
40     shadeRepository: ShadeRepository,
41     transitionInteractor: KeyguardTransitionInteractor,
42     keyguardInteractor: KeyguardInteractor,
43 ) {
44     /**
45      * Emits a [FlingInfo] whenever a swipe to dismiss gesture has started a fling animation on the
46      * lockscreen while it's dismissable.
47      *
48      * This value is collected by [FromLockscreenTransitionInteractor] to start a transition from
49      * LOCKSCREEN -> GONE, and by [KeyguardSurfaceBehindInteractor] to match the surface remote
50      * animation's velocity to the fling velocity, if applicable.
51      */
52     val dismissFling =
53         shadeRepository.currentFling
54             .sample(
55                 transitionInteractor.startedKeyguardState,
56                 keyguardInteractor.isKeyguardDismissible
57             )
58             .filter { (flingInfo, startedState, keyguardDismissable) ->
59                 flingInfo != null &&
60                     !flingInfo.expand &&
61                     startedState == KeyguardState.LOCKSCREEN &&
62                     keyguardDismissable
63             }
64             .map { (flingInfo, _) -> flingInfo }
65             .stateIn(backgroundScope, SharingStarted.Eagerly, null)
66 }
67