• 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 
17 package com.android.systemui.power.shared.model
18 
19 import android.os.PowerManager
20 
21 /** The reason we're waking up or going to sleep, such as pressing the power button. */
22 enum class WakeSleepReason(
23     val isTouch: Boolean,
24     @PowerManager.WakeReason val powerManagerWakeReason: Int,
25 ) {
26     /** The physical power button was pressed to wake up or sleep the device. */
27     POWER_BUTTON(isTouch = false, PowerManager.WAKE_REASON_POWER_BUTTON),
28 
29     /** The sleep button was pressed to sleep the device. */
30     SLEEP_BUTTON(isTouch = false, PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON),
31 
32     /** The user has tapped or double tapped to wake the screen. */
33     TAP(isTouch = true, PowerManager.WAKE_REASON_TAP),
34 
35     /** The user performed some sort of gesture to wake the screen. */
36     GESTURE(isTouch = true, PowerManager.WAKE_REASON_GESTURE),
37 
38     /** Waking up because a wake key other than power was pressed. */
39     KEY(isTouch = false, PowerManager.WAKE_REASON_WAKE_KEY),
40 
41     /** Waking up because a wake motion was performed */
42     MOTION(isTouch = false, PowerManager.WAKE_REASON_WAKE_MOTION),
43 
44     /** Waking due to the lid being opened. */
45     LID(isTouch = false, PowerManager.WAKE_REASON_LID),
46 
47     /** Waking the device due to unfolding of a foldable device. */
48     UNFOLD(isTouch = false, PowerManager.WAKE_REASON_UNFOLD_DEVICE),
49 
50     /** Waking up due to a user performed lift gesture. */
51     LIFT(isTouch = false, PowerManager.WAKE_REASON_LIFT),
52 
53     /** Waking up due to a user interacting with a biometric. */
54     BIOMETRIC(isTouch = false, PowerManager.WAKE_REASON_BIOMETRIC),
55 
56     /** Something else happened to wake up or sleep the device. */
57     OTHER(isTouch = false, PowerManager.WAKE_REASON_UNKNOWN),
58 
59     /** Device goes to sleep due to folding of a foldable device. */
60     FOLD(isTouch = false, PowerManager.GO_TO_SLEEP_REASON_DEVICE_FOLD),
61 
62     /** Device goes to sleep because it timed out. */
63     TIMEOUT(isTouch = false, PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
64 
65     companion object {
fromPowerManagerWakeReasonnull66         fun fromPowerManagerWakeReason(reason: Int): WakeSleepReason {
67             return when (reason) {
68                 PowerManager.WAKE_REASON_POWER_BUTTON -> POWER_BUTTON
69                 PowerManager.WAKE_REASON_TAP -> TAP
70                 PowerManager.WAKE_REASON_GESTURE -> GESTURE
71                 PowerManager.WAKE_REASON_WAKE_KEY -> KEY
72                 PowerManager.WAKE_REASON_WAKE_MOTION -> MOTION
73                 PowerManager.WAKE_REASON_LID -> LID
74                 PowerManager.WAKE_REASON_UNFOLD_DEVICE -> UNFOLD
75                 PowerManager.WAKE_REASON_LIFT -> LIFT
76                 PowerManager.WAKE_REASON_BIOMETRIC -> BIOMETRIC
77                 else -> OTHER
78             }
79         }
80 
fromPowerManagerSleepReasonnull81         fun fromPowerManagerSleepReason(reason: Int): WakeSleepReason {
82             return when (reason) {
83                 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON -> POWER_BUTTON
84                 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON -> SLEEP_BUTTON
85                 PowerManager.GO_TO_SLEEP_REASON_TIMEOUT -> TIMEOUT
86                 PowerManager.GO_TO_SLEEP_REASON_DEVICE_FOLD -> FOLD
87                 else -> OTHER
88             }
89         }
90     }
91 }
92