• 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.display.domain.interactor
18 
19 import android.view.Display
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.dagger.qualifiers.Background
22 import com.android.systemui.display.data.repository.DeviceStateRepository
23 import com.android.systemui.display.data.repository.DisplayRepository
24 import javax.inject.Inject
25 import kotlinx.coroutines.CoroutineDispatcher
26 import kotlinx.coroutines.flow.Flow
27 import kotlinx.coroutines.flow.combineTransform
28 import kotlinx.coroutines.flow.distinctUntilChanged
29 import kotlinx.coroutines.flow.flowOn
30 
31 /** Provides information about the status of Rear Display Mode. */
32 interface RearDisplayStateInteractor {
33 
34     /** A flow notifying the subscriber of Rear Display state changes */
35     val state: Flow<State>
36 
37     sealed class State {
38         /** Indicates that the rear display is disabled */
39         data object Disabled : State()
40 
41         /**
42          * Indicates that the device is in Rear Display Mode, and that the inner display is ready to
43          * show a system-provided affordance allowing the user to cancel out of the Rear Display
44          * Mode.
45          */
46         data class Enabled(val innerDisplay: Display) : State()
47     }
48 }
49 
50 @SysUISingleton
51 class RearDisplayStateInteractorImpl
52 @Inject
53 constructor(
54     displayRepository: DisplayRepository,
55     deviceStateRepository: DeviceStateRepository,
56     @Background backgroundCoroutineDispatcher: CoroutineDispatcher,
57 ) : RearDisplayStateInteractor {
58 
59     override val state: Flow<RearDisplayStateInteractor.State> =
60         deviceStateRepository.state
statenull61             .combineTransform(displayRepository.displays) { state, displays ->
62                 val innerDisplay = displays.find { it.flags and Display.FLAG_REAR != 0 }
63 
64                 if (state != DeviceStateRepository.DeviceState.REAR_DISPLAY_OUTER_DEFAULT) {
65                     emit(RearDisplayStateInteractor.State.Disabled)
66                 } else if (innerDisplay != null) {
67                     emit(RearDisplayStateInteractor.State.Enabled(innerDisplay))
68                 }
69             }
70             .distinctUntilChanged()
71             .flowOn(backgroundCoroutineDispatcher)
72 }
73