• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.systemui.keyguard.shared.model
17 
18 import com.android.systemui.keyguard.WakefulnessLifecycle
19 
20 /** Model device wakefulness states. */
21 data class WakefulnessModel(
22     val state: WakefulnessState,
23     val isWakingUpOrAwake: Boolean,
24     val lastWakeReason: WakeSleepReason,
25     val lastSleepReason: WakeSleepReason,
26 ) {
27     companion object {
isSleepingOrStartingToSleepnull28         fun isSleepingOrStartingToSleep(model: WakefulnessModel): Boolean {
29             return model.state == WakefulnessState.ASLEEP ||
30                 model.state == WakefulnessState.STARTING_TO_SLEEP
31         }
32 
isWakingOrStartingToWakenull33         fun isWakingOrStartingToWake(model: WakefulnessModel): Boolean {
34             return model.state == WakefulnessState.AWAKE ||
35                 model.state == WakefulnessState.STARTING_TO_WAKE
36         }
37 
fromWakefulnessLifecyclenull38         fun fromWakefulnessLifecycle(wakefulnessLifecycle: WakefulnessLifecycle): WakefulnessModel {
39             return WakefulnessModel(
40                 WakefulnessState.fromWakefulnessLifecycleInt(wakefulnessLifecycle.wakefulness),
41                 wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_WAKING ||
42                     wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_AWAKE,
43                 WakeSleepReason.fromPowerManagerWakeReason(wakefulnessLifecycle.lastWakeReason),
44                 WakeSleepReason.fromPowerManagerSleepReason(wakefulnessLifecycle.lastSleepReason),
45             )
46         }
47     }
48 }
49