blob: 9661a08464dd91084e6feb8df24ff97c1fe53c64 [file] [log] [blame]
Jeff Brown6f357d32014-01-15 20:40:55 -08001/*
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
17package android.os;
18
Jeff Brown970d4132014-07-19 11:33:47 -070019import android.view.Display;
20
Makoto Onukiaae89532017-11-08 14:32:03 -080021import java.util.function.Consumer;
22
Jeff Brown6f357d32014-01-15 20:40:55 -080023/**
24 * Power manager local system service interface.
25 *
26 * @hide Only for use within the system server.
27 */
Jeff Brown4ccb8232014-01-16 22:16:42 -080028public abstract class PowerManagerInternal {
Jeff Brown6f357d32014-01-15 20:40:55 -080029 /**
Jeff Brownfbe96702014-11-19 18:30:58 -080030 * 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 Jin148d7f42017-11-28 14:23:56 -080074 * 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 Brownfbe96702014-11-19 18:30:58 -080092 * 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 Brown6f357d32014-01-15 20:40:55 -0800100 * 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 Brown4ccb8232014-01-16 22:16:42 -0800107 public abstract void setScreenBrightnessOverrideFromWindowManager(int brightness);
Jeff Brown6f357d32014-01-15 20:40:55 -0800108
109 /**
Jeff Brown6f357d32014-01-15 20:40:55 -0800110 * 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 Brown4ccb8232014-01-16 22:16:42 -0800118 public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);
Jeff Brown6f357d32014-01-15 20:40:55 -0800119
Jeff Brown970d4132014-07-19 11:33:47 -0700120 /**
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -0700121 * 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 Brown5ce1cb22014-11-06 19:05:33 -0800127 * 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 Grafov28939982017-10-03 15:11:52 +0100131 public abstract void setMaximumScreenOffTimeoutFromDeviceAdmin(int userId, long timeMs);
Jeff Brown5ce1cb22014-11-06 19:05:33 -0800132
133 /**
Jeff Brown970d4132014-07-19 11:33:47 -0700134 * Used by the dream manager to override certain properties while dozing.
135 *
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700136 * @param screenState The overridden screen state, or {@link Display#STATE_UNKNOWN}
Jeff Brown970d4132014-07-19 11:33:47 -0700137 * 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 Podogov56bc6d02018-02-26 16:04:24 +0000144 /**
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
jackqdyulei455e90a2017-02-09 15:29:16 -0800152 public abstract PowerSaveState getLowPowerState(int serviceType);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -0700153
Jeff Brown2c43c332014-06-12 22:38:59 -0700154 public abstract void registerLowPowerModeObserver(LowPowerModeListener listener);
155
Makoto Onukiaae89532017-11-08 14:32:03 -0800156 /**
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 Hackborncbefd8d2014-05-14 11:42:00 -0700173 public interface LowPowerModeListener {
jackqdyulei455e90a2017-02-09 15:29:16 -0800174 int getServiceType();
175 void onLowPowerModeChanged(PowerSaveState state);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -0700176 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700177
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700178 public abstract boolean setDeviceIdleMode(boolean enabled);
179
180 public abstract boolean setLightDeviceIdleMode(boolean enabled);
Dianne Hackborn8d66b3f2015-05-08 17:21:48 -0700181
182 public abstract void setDeviceIdleWhitelist(int[] appids);
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700183
Amith Yamasaniaf575b92015-05-29 15:35:26 -0700184 public abstract void setDeviceIdleTempWhitelist(int[] appids);
185
Dianne Hackbornd33c7cd2016-10-25 17:13:24 -0700186 public abstract void startUidChanges();
187
188 public abstract void finishUidChanges();
189
Dianne Hackbornd23e0d62015-05-15 16:36:12 -0700190 public abstract void updateUidProcState(int uid, int procState);
191
192 public abstract void uidGone(int uid);
Michael Wrighta4d22d72015-09-16 23:19:26 +0100193
Dianne Hackbornd33c7cd2016-10-25 17:13:24 -0700194 public abstract void uidActive(int uid);
195
196 public abstract void uidIdle(int uid);
197
Ruchi Kandoi0d434042016-10-03 09:12:02 -0700198 /**
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 Wrighta4d22d72015-09-16 23:19:26 +0100202 public abstract void powerHint(int hintId, int data);
Alex Kershaw2418ea92018-10-19 17:17:49 +0100203
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 Cordon623526b2019-04-09 17:02:38 +0100206
207 /** Returns information about the last wakeup event. */
208 public abstract PowerManager.WakeData getLastWakeup();
Jeff Brown6f357d32014-01-15 20:40:55 -0800209}