Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 android.os; |
| 18 | |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 19 | import android.view.Display; |
| 20 | |
Makoto Onuki | aae8953 | 2017-11-08 14:32:03 -0800 | [diff] [blame] | 21 | import java.util.function.Consumer; |
| 22 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 23 | /** |
| 24 | * Power manager local system service interface. |
| 25 | * |
| 26 | * @hide Only for use within the system server. |
| 27 | */ |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 28 | public abstract class PowerManagerInternal { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 29 | /** |
Jeff Brown | fbe9670 | 2014-11-19 18:30:58 -0800 | [diff] [blame] | 30 | * Wakefulness: The device is asleep. It can only be awoken by a call to wakeUp(). |
| 31 | * The screen should be off or in the process of being turned off by the display controller. |
| 32 | * The device typically passes through the dozing state first. |
| 33 | */ |
| 34 | public static final int WAKEFULNESS_ASLEEP = 0; |
| 35 | |
| 36 | /** |
| 37 | * Wakefulness: The device is fully awake. It can be put to sleep by a call to goToSleep(). |
| 38 | * When the user activity timeout expires, the device may start dreaming or go to sleep. |
| 39 | */ |
| 40 | public static final int WAKEFULNESS_AWAKE = 1; |
| 41 | |
| 42 | /** |
| 43 | * Wakefulness: The device is dreaming. It can be awoken by a call to wakeUp(), |
| 44 | * which ends the dream. The device goes to sleep when goToSleep() is called, when |
| 45 | * the dream ends or when unplugged. |
| 46 | * User activity may brighten the screen but does not end the dream. |
| 47 | */ |
| 48 | public static final int WAKEFULNESS_DREAMING = 2; |
| 49 | |
| 50 | /** |
| 51 | * Wakefulness: The device is dozing. It is almost asleep but is allowing a special |
| 52 | * low-power "doze" dream to run which keeps the display on but lets the application |
| 53 | * processor be suspended. It can be awoken by a call to wakeUp() which ends the dream. |
| 54 | * The device fully goes to sleep if the dream cannot be started or ends on its own. |
| 55 | */ |
| 56 | public static final int WAKEFULNESS_DOZING = 3; |
| 57 | |
| 58 | public static String wakefulnessToString(int wakefulness) { |
| 59 | switch (wakefulness) { |
| 60 | case WAKEFULNESS_ASLEEP: |
| 61 | return "Asleep"; |
| 62 | case WAKEFULNESS_AWAKE: |
| 63 | return "Awake"; |
| 64 | case WAKEFULNESS_DREAMING: |
| 65 | return "Dreaming"; |
| 66 | case WAKEFULNESS_DOZING: |
| 67 | return "Dozing"; |
| 68 | default: |
| 69 | return Integer.toString(wakefulness); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
Yi Jin | 148d7f4 | 2017-11-28 14:23:56 -0800 | [diff] [blame] | 74 | * Converts platform constants to proto enums. |
| 75 | */ |
| 76 | public static int wakefulnessToProtoEnum(int wakefulness) { |
| 77 | switch (wakefulness) { |
| 78 | case WAKEFULNESS_ASLEEP: |
| 79 | return PowerManagerInternalProto.WAKEFULNESS_ASLEEP; |
| 80 | case WAKEFULNESS_AWAKE: |
| 81 | return PowerManagerInternalProto.WAKEFULNESS_AWAKE; |
| 82 | case WAKEFULNESS_DREAMING: |
| 83 | return PowerManagerInternalProto.WAKEFULNESS_DREAMING; |
| 84 | case WAKEFULNESS_DOZING: |
| 85 | return PowerManagerInternalProto.WAKEFULNESS_DOZING; |
| 86 | default: |
| 87 | return wakefulness; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
Jeff Brown | fbe9670 | 2014-11-19 18:30:58 -0800 | [diff] [blame] | 92 | * Returns true if the wakefulness state represents an interactive state |
| 93 | * as defined by {@link android.os.PowerManager#isInteractive}. |
| 94 | */ |
| 95 | public static boolean isInteractive(int wakefulness) { |
| 96 | return wakefulness == WAKEFULNESS_AWAKE || wakefulness == WAKEFULNESS_DREAMING; |
| 97 | } |
| 98 | |
| 99 | /** |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 100 | * Used by the window manager to override the screen brightness based on the |
| 101 | * current foreground activity. |
| 102 | * |
| 103 | * This method must only be called by the window manager. |
| 104 | * |
| 105 | * @param brightness The overridden brightness, or -1 to disable the override. |
| 106 | */ |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 107 | public abstract void setScreenBrightnessOverrideFromWindowManager(int brightness); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 108 | |
| 109 | /** |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 110 | * Used by the window manager to override the user activity timeout based on the |
| 111 | * current foreground activity. It can only be used to make the timeout shorter |
| 112 | * than usual, not longer. |
| 113 | * |
| 114 | * This method must only be called by the window manager. |
| 115 | * |
| 116 | * @param timeoutMillis The overridden timeout, or -1 to disable the override. |
| 117 | */ |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 118 | public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 119 | |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 120 | /** |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 121 | * Used by the window manager to tell the power manager that the user is no longer actively |
| 122 | * using the device. |
| 123 | */ |
| 124 | public abstract void setUserInactiveOverrideFromWindowManager(); |
| 125 | |
| 126 | /** |
Jeff Brown | 5ce1cb2 | 2014-11-06 19:05:33 -0800 | [diff] [blame] | 127 | * Used by device administration to set the maximum screen off timeout. |
| 128 | * |
| 129 | * This method must only be called by the device administration policy manager. |
| 130 | */ |
Pavel Grafov | 2893998 | 2017-10-03 15:11:52 +0100 | [diff] [blame] | 131 | public abstract void setMaximumScreenOffTimeoutFromDeviceAdmin(int userId, long timeMs); |
Jeff Brown | 5ce1cb2 | 2014-11-06 19:05:33 -0800 | [diff] [blame] | 132 | |
| 133 | /** |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 134 | * Used by the dream manager to override certain properties while dozing. |
| 135 | * |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 136 | * @param screenState The overridden screen state, or {@link Display#STATE_UNKNOWN} |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 137 | * to disable the override. |
| 138 | * @param screenBrightness The overridden screen brightness, or |
| 139 | * {@link PowerManager#BRIGHTNESS_DEFAULT} to disable the override. |
| 140 | */ |
| 141 | public abstract void setDozeOverrideFromDreamManager( |
| 142 | int screenState, int screenBrightness); |
| 143 | |
Ivan Podogov | 56bc6d0 | 2018-02-26 16:04:24 +0000 | [diff] [blame] | 144 | /** |
| 145 | * Used by sidekick manager to tell the power manager if it shouldn't change the display state |
| 146 | * when a draw wake lock is acquired. Some processes may grab such a wake lock to do some work |
| 147 | * in a powered-up state, but we shouldn't give up sidekick control over the display until this |
| 148 | * override is lifted. |
| 149 | */ |
| 150 | public abstract void setDrawWakeLockOverrideFromSidekick(boolean keepState); |
| 151 | |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 152 | public abstract PowerSaveState getLowPowerState(int serviceType); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 153 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 154 | public abstract void registerLowPowerModeObserver(LowPowerModeListener listener); |
| 155 | |
Makoto Onuki | aae8953 | 2017-11-08 14:32:03 -0800 | [diff] [blame] | 156 | /** |
| 157 | * Same as {@link #registerLowPowerModeObserver} but can take a lambda. |
| 158 | */ |
| 159 | public void registerLowPowerModeObserver(int serviceType, Consumer<PowerSaveState> listener) { |
| 160 | registerLowPowerModeObserver(new LowPowerModeListener() { |
| 161 | @Override |
| 162 | public int getServiceType() { |
| 163 | return serviceType; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void onLowPowerModeChanged(PowerSaveState state) { |
| 168 | listener.accept(state); |
| 169 | } |
| 170 | }); |
| 171 | } |
| 172 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 173 | public interface LowPowerModeListener { |
jackqdyulei | 455e90a | 2017-02-09 15:29:16 -0800 | [diff] [blame] | 174 | int getServiceType(); |
| 175 | void onLowPowerModeChanged(PowerSaveState state); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 176 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 177 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 178 | public abstract boolean setDeviceIdleMode(boolean enabled); |
| 179 | |
| 180 | public abstract boolean setLightDeviceIdleMode(boolean enabled); |
Dianne Hackborn | 8d66b3f | 2015-05-08 17:21:48 -0700 | [diff] [blame] | 181 | |
| 182 | public abstract void setDeviceIdleWhitelist(int[] appids); |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 183 | |
Amith Yamasani | af575b9 | 2015-05-29 15:35:26 -0700 | [diff] [blame] | 184 | public abstract void setDeviceIdleTempWhitelist(int[] appids); |
| 185 | |
Dianne Hackborn | d33c7cd | 2016-10-25 17:13:24 -0700 | [diff] [blame] | 186 | public abstract void startUidChanges(); |
| 187 | |
| 188 | public abstract void finishUidChanges(); |
| 189 | |
Dianne Hackborn | d23e0d6 | 2015-05-15 16:36:12 -0700 | [diff] [blame] | 190 | public abstract void updateUidProcState(int uid, int procState); |
| 191 | |
| 192 | public abstract void uidGone(int uid); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 193 | |
Dianne Hackborn | d33c7cd | 2016-10-25 17:13:24 -0700 | [diff] [blame] | 194 | public abstract void uidActive(int uid); |
| 195 | |
| 196 | public abstract void uidIdle(int uid); |
| 197 | |
Ruchi Kandoi | 0d43404 | 2016-10-03 09:12:02 -0700 | [diff] [blame] | 198 | /** |
| 199 | * The hintId sent through this method should be in-line with the |
| 200 | * PowerHint defined in android/hardware/power/<version 1.0 & up>/IPower.h |
| 201 | */ |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 202 | public abstract void powerHint(int hintId, int data); |
Alex Kershaw | 2418ea9 | 2018-10-19 17:17:49 +0100 | [diff] [blame] | 203 | |
| 204 | /** Returns whether there hasn't been a user activity event for the given number of ms. */ |
| 205 | public abstract boolean wasDeviceIdleFor(long ms); |
Santos Cordon | 623526b | 2019-04-09 17:02:38 +0100 | [diff] [blame] | 206 | |
| 207 | /** Returns information about the last wakeup event. */ |
| 208 | public abstract PowerManager.WakeData getLastWakeup(); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 209 | } |