• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2025 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.wallpapers.ui.viewmodel
18 
19 import android.graphics.RectF
20 import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
21 import com.android.systemui.keyguard.shared.model.Edge
22 import com.android.systemui.keyguard.shared.model.KeyguardState
23 import com.android.systemui.keyguard.shared.model.TransitionState
24 import com.android.systemui.scene.shared.model.Scenes
25 import com.android.systemui.wallpapers.domain.interactor.WallpaperFocalAreaInteractor
26 import javax.inject.Inject
27 import kotlinx.coroutines.flow.combine
28 import kotlinx.coroutines.flow.filter
29 import kotlinx.coroutines.flow.filterNotNull
30 import kotlinx.coroutines.flow.map
31 
32 class WallpaperFocalAreaViewModel
33 @Inject
34 constructor(
35     private val wallpaperFocalAreaInteractor: WallpaperFocalAreaInteractor,
36     val keyguardTransitionInteractor: KeyguardTransitionInteractor,
37 ) {
38     val hasFocalArea = wallpaperFocalAreaInteractor.hasFocalArea
39 
40     val wallpaperFocalAreaBounds =
41         combine(
42                 wallpaperFocalAreaInteractor.wallpaperFocalAreaBounds,
43                 keyguardTransitionInteractor.startedKeyguardTransitionStep,
44                 // Emit transition state when FINISHED instead of STARTED to avoid race with
45                 // wakingup command, causing layout change command not be received.
46                 keyguardTransitionInteractor
47                     .transition(
48                         edge = Edge.create(to = Scenes.Lockscreen),
49                         edgeWithoutSceneContainer = Edge.create(to = KeyguardState.LOCKSCREEN),
50                     )
51                     .filter { it.transitionState == TransitionState.FINISHED },
52                 ::Triple,
53             )
54             .map { (bounds, startedStep, _) ->
55                 // Avoid sending wrong bounds when transitioning from LOCKSCREEN to GONE
56                 if (
57                     startedStep.to == KeyguardState.LOCKSCREEN &&
58                         startedStep.from != KeyguardState.LOCKSCREEN
59                 ) {
60                     bounds
61                 } else {
62                     null
63                 }
64             }
65             .filterNotNull()
66 
67     fun setFocalAreaBounds(bounds: RectF) {
68         wallpaperFocalAreaInteractor.setFocalAreaBounds(bounds)
69     }
70 }
71