• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.view.Display;
20 import android.view.KeyEvent;
21 
22 import java.util.function.Consumer;
23 
24 /**
25  * Power manager local system service interface.
26  *
27  * @hide Only for use within the system server.
28  */
29 public abstract class PowerManagerInternal {
30     /**
31      * Wakefulness: The device is asleep.  It can only be awoken by a call to wakeUp().
32      * The screen should be off or in the process of being turned off by the display controller.
33      * The device typically passes through the dozing state first.
34      */
35     public static final int WAKEFULNESS_ASLEEP = 0;
36 
37     /**
38      * Wakefulness: The device is fully awake.  It can be put to sleep by a call to goToSleep().
39      * When the user activity timeout expires, the device may start dreaming or go to sleep.
40      */
41     public static final int WAKEFULNESS_AWAKE = 1;
42 
43     /**
44      * Wakefulness: The device is dreaming.  It can be awoken by a call to wakeUp(),
45      * which ends the dream.  The device goes to sleep when goToSleep() is called, when
46      * the dream ends or when unplugged.
47      * User activity may brighten the screen but does not end the dream.
48      */
49     public static final int WAKEFULNESS_DREAMING = 2;
50 
51     /**
52      * Wakefulness: The device is dozing.  It is almost asleep but is allowing a special
53      * low-power "doze" dream to run which keeps the display on but lets the application
54      * processor be suspended.  It can be awoken by a call to wakeUp() which ends the dream.
55      * The device fully goes to sleep if the dream cannot be started or ends on its own.
56      */
57     public static final int WAKEFULNESS_DOZING = 3;
58 
wakefulnessToString(int wakefulness)59     public static String wakefulnessToString(int wakefulness) {
60         switch (wakefulness) {
61             case WAKEFULNESS_ASLEEP:
62                 return "Asleep";
63             case WAKEFULNESS_AWAKE:
64                 return "Awake";
65             case WAKEFULNESS_DREAMING:
66                 return "Dreaming";
67             case WAKEFULNESS_DOZING:
68                 return "Dozing";
69             default:
70                 return Integer.toString(wakefulness);
71         }
72     }
73 
74     /**
75      * Converts platform constants to proto enums.
76      */
wakefulnessToProtoEnum(int wakefulness)77     public static int wakefulnessToProtoEnum(int wakefulness) {
78         switch (wakefulness) {
79             case WAKEFULNESS_ASLEEP:
80                 return PowerManagerInternalProto.WAKEFULNESS_ASLEEP;
81             case WAKEFULNESS_AWAKE:
82                 return PowerManagerInternalProto.WAKEFULNESS_AWAKE;
83             case WAKEFULNESS_DREAMING:
84                 return PowerManagerInternalProto.WAKEFULNESS_DREAMING;
85             case WAKEFULNESS_DOZING:
86                 return PowerManagerInternalProto.WAKEFULNESS_DOZING;
87             default:
88                 return wakefulness;
89         }
90     }
91 
92     /**
93      * Returns true if the wakefulness state represents an interactive state
94      * as defined by {@link android.os.PowerManager#isInteractive}.
95      */
isInteractive(int wakefulness)96     public static boolean isInteractive(int wakefulness) {
97         return wakefulness == WAKEFULNESS_AWAKE || wakefulness == WAKEFULNESS_DREAMING;
98     }
99 
100     /**
101      * Used by the window manager to override the screen brightness based on the
102      * current foreground activity.
103      *
104      * This method must only be called by the window manager.
105      *
106      * @param brightness The overridden brightness, or Float.NaN to disable the override.
107      */
setScreenBrightnessOverrideFromWindowManager(float brightness)108     public abstract void setScreenBrightnessOverrideFromWindowManager(float brightness);
109 
110     /**
111      * Used by the window manager to override the user activity timeout based on the
112      * current foreground activity.  It can only be used to make the timeout shorter
113      * than usual, not longer.
114      *
115      * This method must only be called by the window manager.
116      *
117      * @param timeoutMillis The overridden timeout, or -1 to disable the override.
118      */
setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis)119     public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);
120 
121     /**
122      * Used by the window manager to tell the power manager that the user is no longer actively
123      * using the device.
124      */
setUserInactiveOverrideFromWindowManager()125     public abstract void setUserInactiveOverrideFromWindowManager();
126 
127     /**
128      * Used by device administration to set the maximum screen off timeout.
129      *
130      * This method must only be called by the device administration policy manager.
131      */
setMaximumScreenOffTimeoutFromDeviceAdmin(int userId, long timeMs)132     public abstract void setMaximumScreenOffTimeoutFromDeviceAdmin(int userId, long timeMs);
133 
134     /**
135      * Used by the dream manager to override certain properties while dozing.
136      *
137      * @param screenState The overridden screen state, or {@link Display#STATE_UNKNOWN}
138      * to disable the override.
139      * @param screenBrightness The overridden screen brightness, or
140      * {@link PowerManager#BRIGHTNESS_DEFAULT} to disable the override.
141      */
setDozeOverrideFromDreamManager( int screenState, int screenBrightness)142     public abstract void setDozeOverrideFromDreamManager(
143             int screenState, int screenBrightness);
144 
145     /**
146      * Used by sidekick manager to tell the power manager if it shouldn't change the display state
147      * when a draw wake lock is acquired. Some processes may grab such a wake lock to do some work
148      * in a powered-up state, but we shouldn't give up sidekick control over the display until this
149      * override is lifted.
150      */
setDrawWakeLockOverrideFromSidekick(boolean keepState)151     public abstract void setDrawWakeLockOverrideFromSidekick(boolean keepState);
152 
getLowPowerState(int serviceType)153     public abstract PowerSaveState getLowPowerState(int serviceType);
154 
registerLowPowerModeObserver(LowPowerModeListener listener)155     public abstract void registerLowPowerModeObserver(LowPowerModeListener listener);
156 
157     /**
158      * Same as {@link #registerLowPowerModeObserver} but can take a lambda.
159      */
registerLowPowerModeObserver(int serviceType, Consumer<PowerSaveState> listener)160     public void registerLowPowerModeObserver(int serviceType, Consumer<PowerSaveState> listener) {
161         registerLowPowerModeObserver(new LowPowerModeListener() {
162             @Override
163             public int getServiceType() {
164                 return serviceType;
165             }
166 
167             @Override
168             public void onLowPowerModeChanged(PowerSaveState state) {
169                 listener.accept(state);
170             }
171         });
172     }
173 
174     public interface LowPowerModeListener {
getServiceType()175         int getServiceType();
onLowPowerModeChanged(PowerSaveState state)176         void onLowPowerModeChanged(PowerSaveState state);
177     }
178 
setDeviceIdleMode(boolean enabled)179     public abstract boolean setDeviceIdleMode(boolean enabled);
180 
setLightDeviceIdleMode(boolean enabled)181     public abstract boolean setLightDeviceIdleMode(boolean enabled);
182 
setDeviceIdleWhitelist(int[] appids)183     public abstract void setDeviceIdleWhitelist(int[] appids);
184 
setDeviceIdleTempWhitelist(int[] appids)185     public abstract void setDeviceIdleTempWhitelist(int[] appids);
186 
startUidChanges()187     public abstract void startUidChanges();
188 
finishUidChanges()189     public abstract void finishUidChanges();
190 
updateUidProcState(int uid, int procState)191     public abstract void updateUidProcState(int uid, int procState);
192 
uidGone(int uid)193     public abstract void uidGone(int uid);
194 
uidActive(int uid)195     public abstract void uidActive(int uid);
196 
uidIdle(int uid)197     public abstract void uidIdle(int uid);
198 
199     /**
200      * Boost: It is sent when user interacting with the device, for example,
201      * touchscreen events are incoming.
202      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Boost.aidl
203      */
204     public static final int BOOST_INTERACTION = 0;
205 
206     /**
207      * Boost: It indicates that the framework is likely to provide a new display
208      * frame soon. This implies that the device should ensure that the display
209      * processing path is powered up and ready to receive that update.
210      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Boost.aidl
211      */
212     public static final int BOOST_DISPLAY_UPDATE_IMMINENT = 1;
213 
214     /**
215      * SetPowerBoost() indicates the device may need to boost some resources, as
216      * the load is likely to increase before the kernel governors can react.
217      * Depending on the boost, it may be appropriate to raise the frequencies of
218      * CPU, GPU, memory subsystem, or stop CPU from going into deep sleep state.
219      *
220      * @param boost Boost which is to be set with a timeout.
221      * @param durationMs The expected duration of the user's interaction, if
222      *        known, or 0 if the expected duration is unknown.
223      *        a negative value indicates canceling previous boost.
224      *        A given platform can choose to boost some time based on durationMs,
225      *        and may also pick an appropriate timeout for 0 case.
226      */
setPowerBoost(int boost, int durationMs)227     public abstract void setPowerBoost(int boost, int durationMs);
228 
229     /**
230      * Mode: It indicates that the device is to allow wake up when the screen
231      * is tapped twice.
232      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
233      */
234     public static final int MODE_DOUBLE_TAP_TO_WAKE = 0;
235 
236     /**
237      * Mode: It indicates Low power mode is activated or not. Low power mode
238      * is intended to save battery at the cost of performance.
239      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
240      */
241     public static final int MODE_LOW_POWER = 1;
242 
243     /**
244      * Mode: It indicates Sustained Performance mode is activated or not.
245      * Sustained performance mode is intended to provide a consistent level of
246      * performance for a prolonged amount of time.
247      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
248      */
249     public static final int MODE_SUSTAINED_PERFORMANCE = 2;
250 
251     /**
252      * Mode: It sets the device to a fixed performance level which can be sustained
253      * under normal indoor conditions for at least 10 minutes.
254      * Fixed performance mode puts both upper and lower bounds on performance such
255      * that any workload run while in a fixed performance mode should complete in
256      * a repeatable amount of time.
257      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
258      */
259     public static final int MODE_FIXED_PERFORMANCE = 3;
260 
261     /**
262      * Mode: It indicates VR Mode is activated or not. VR mode is intended to
263      * provide minimum guarantee for performance for the amount of time the device
264      * can sustain it.
265      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
266      */
267     public static final int MODE_VR = 4;
268 
269     /**
270      * Mode: It indicates that an application has been launched.
271      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
272      */
273     public static final int MODE_LAUNCH = 5;
274 
275     /**
276      * Mode: It indicates that the device is about to enter a period of expensive
277      * rendering.
278      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
279      */
280     public static final int MODE_EXPENSIVE_RENDERING = 6;
281 
282     /**
283      * Mode: It indicates that the device is about entering/leaving interactive
284      * state or on-interactive state.
285      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
286      */
287     public static final int MODE_INTERACTIVE = 7;
288 
289     /**
290      * Mode: It indicates the device is in device idle, externally known as doze.
291      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
292      */
293     public static final int MODE_DEVICE_IDLE = 8;
294 
295     /**
296      * Mode: It indicates that display is either off or still on but is optimized
297      * for low power.
298      * Defined in hardware/interfaces/power/aidl/android/hardware/power/Mode.aidl
299      */
300     public static final int MODE_DISPLAY_INACTIVE = 9;
301 
302     /**
303      * SetPowerMode() is called to enable/disable specific hint mode, which
304      * may result in adjustment of power/performance parameters of the
305      * cpufreq governor and other controls on device side.
306      *
307      * @param mode Mode which is to be enable/disable.
308      * @param enabled true to enable, false to disable the mode.
309      */
setPowerMode(int mode, boolean enabled)310     public abstract void setPowerMode(int mode, boolean enabled);
311 
312     /** Returns whether there hasn't been a user activity event for the given number of ms. */
wasDeviceIdleFor(long ms)313     public abstract boolean wasDeviceIdleFor(long ms);
314 
315     /** Returns information about the last wakeup event. */
getLastWakeup()316     public abstract PowerManager.WakeData getLastWakeup();
317 
318     /** Allows power button to intercept a power key button press. */
interceptPowerKeyDown(KeyEvent event)319     public abstract boolean interceptPowerKeyDown(KeyEvent event);
320 }
321