1 /*
2  * Copyright (C) 2022 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 
18 package com.android.systemui.power.data.repository
19 
20 import android.os.PowerManager
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.power.shared.model.ScreenPowerState
23 import com.android.systemui.power.shared.model.WakeSleepReason
24 import com.android.systemui.power.shared.model.WakefulnessModel
25 import com.android.systemui.power.shared.model.WakefulnessState
26 import dagger.Binds
27 import dagger.Module
28 import javax.inject.Inject
29 import kotlinx.coroutines.flow.Flow
30 import kotlinx.coroutines.flow.MutableStateFlow
31 import kotlinx.coroutines.flow.asStateFlow
32 
33 @SysUISingleton
34 class FakePowerRepository @Inject constructor() : PowerRepository {
35     private val _isInteractive = MutableStateFlow(true)
36     override val isInteractive: Flow<Boolean> = _isInteractive.asStateFlow()
37 
38     private val _wakefulness = MutableStateFlow(WakefulnessModel())
39     override val wakefulness = _wakefulness.asStateFlow()
40 
41     private val _screenPowerState = MutableStateFlow(ScreenPowerState.SCREEN_OFF)
42     override val screenPowerState = _screenPowerState.asStateFlow()
43 
44     var lastWakeWhy: String? = null
45     var lastWakeReason: Int? = null
46 
47     var userTouchRegistered = false
48 
setInteractivenull49     fun setInteractive(value: Boolean) {
50         _isInteractive.value = value
51     }
52 
wakeUpnull53     override fun wakeUp(why: String, @PowerManager.WakeReason wakeReason: Int) {
54         lastWakeWhy = why
55         lastWakeReason = wakeReason
56     }
57 
userTouchnull58     override fun userTouch(noChangeLights: Boolean) {
59         userTouchRegistered = true
60     }
61 
updateWakefulnessnull62     override fun updateWakefulness(
63         rawState: WakefulnessState,
64         lastWakeReason: WakeSleepReason,
65         lastSleepReason: WakeSleepReason,
66         powerButtonLaunchGestureTriggered: Boolean
67     ) {
68         _wakefulness.value =
69             WakefulnessModel(
70                 rawState,
71                 lastWakeReason,
72                 lastSleepReason,
73                 powerButtonLaunchGestureTriggered,
74             )
75     }
76 
setScreenPowerStatenull77     override fun setScreenPowerState(state: ScreenPowerState) {
78         _screenPowerState.value = state
79     }
80 }
81 
82 @Module
83 interface FakePowerRepositoryModule {
bindFakenull84     @Binds fun bindFake(fake: FakePowerRepository): PowerRepository
85 }
86