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 user has tapped or double tapped to wake the screen. */ 30 TAP(isTouch = true, PowerManager.WAKE_REASON_TAP), 31 32 /** The user performed some sort of gesture to wake the screen. */ 33 GESTURE(isTouch = true, PowerManager.WAKE_REASON_GESTURE), 34 35 /** Waking up because a wake key other than power was pressed. */ 36 KEY(isTouch = false, PowerManager.WAKE_REASON_WAKE_KEY), 37 38 /** Waking up because a wake motion was performed */ 39 MOTION(isTouch = false, PowerManager.WAKE_REASON_WAKE_MOTION), 40 41 /** Waking due to the lid being opened. */ 42 LID(isTouch = false, PowerManager.WAKE_REASON_LID), 43 44 /** Waking the device due to unfolding of a foldable device. */ 45 UNFOLD(isTouch = false, PowerManager.WAKE_REASON_UNFOLD_DEVICE), 46 47 /** Waking up due to a user performed lift gesture. */ 48 LIFT(isTouch = false, PowerManager.WAKE_REASON_LIFT), 49 50 /** Waking up due to a user interacting with a biometric. */ 51 BIOMETRIC(isTouch = false, PowerManager.WAKE_REASON_BIOMETRIC), 52 53 /** Something else happened to wake up or sleep the device. */ 54 OTHER(isTouch = false, PowerManager.WAKE_REASON_UNKNOWN), 55 56 /** Device goes to sleep due to folding of a foldable device. */ 57 FOLD(isTouch = false, PowerManager.GO_TO_SLEEP_REASON_DEVICE_FOLD); 58 59 companion object { fromPowerManagerWakeReasonnull60 fun fromPowerManagerWakeReason(reason: Int): WakeSleepReason { 61 return when (reason) { 62 PowerManager.WAKE_REASON_POWER_BUTTON -> POWER_BUTTON 63 PowerManager.WAKE_REASON_TAP -> TAP 64 PowerManager.WAKE_REASON_GESTURE -> GESTURE 65 PowerManager.WAKE_REASON_WAKE_KEY -> KEY 66 PowerManager.WAKE_REASON_WAKE_MOTION -> MOTION 67 PowerManager.WAKE_REASON_LID -> LID 68 PowerManager.WAKE_REASON_UNFOLD_DEVICE -> UNFOLD 69 PowerManager.WAKE_REASON_LIFT -> LIFT 70 PowerManager.WAKE_REASON_BIOMETRIC -> BIOMETRIC 71 else -> OTHER 72 } 73 } 74 fromPowerManagerSleepReasonnull75 fun fromPowerManagerSleepReason(reason: Int): WakeSleepReason { 76 return when (reason) { 77 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON -> POWER_BUTTON 78 PowerManager.GO_TO_SLEEP_REASON_DEVICE_FOLD -> FOLD 79 else -> OTHER 80 } 81 } 82 } 83 } 84