blob: 6b6f540e40a074b03c9e673bed576bbd446b9388 [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
Jeff Brown6f357d32014-01-15 20:40:55 -080021/**
22 * Power manager local system service interface.
23 *
24 * @hide Only for use within the system server.
25 */
Jeff Brown4ccb8232014-01-16 22:16:42 -080026public abstract class PowerManagerInternal {
Jeff Brown6f357d32014-01-15 20:40:55 -080027 /**
Jeff Brownfbe96702014-11-19 18:30:58 -080028 * Wakefulness: The device is asleep. It can only be awoken by a call to wakeUp().
29 * The screen should be off or in the process of being turned off by the display controller.
30 * The device typically passes through the dozing state first.
31 */
32 public static final int WAKEFULNESS_ASLEEP = 0;
33
34 /**
35 * Wakefulness: The device is fully awake. It can be put to sleep by a call to goToSleep().
36 * When the user activity timeout expires, the device may start dreaming or go to sleep.
37 */
38 public static final int WAKEFULNESS_AWAKE = 1;
39
40 /**
41 * Wakefulness: The device is dreaming. It can be awoken by a call to wakeUp(),
42 * which ends the dream. The device goes to sleep when goToSleep() is called, when
43 * the dream ends or when unplugged.
44 * User activity may brighten the screen but does not end the dream.
45 */
46 public static final int WAKEFULNESS_DREAMING = 2;
47
48 /**
49 * Wakefulness: The device is dozing. It is almost asleep but is allowing a special
50 * low-power "doze" dream to run which keeps the display on but lets the application
51 * processor be suspended. It can be awoken by a call to wakeUp() which ends the dream.
52 * The device fully goes to sleep if the dream cannot be started or ends on its own.
53 */
54 public static final int WAKEFULNESS_DOZING = 3;
55
56 public static String wakefulnessToString(int wakefulness) {
57 switch (wakefulness) {
58 case WAKEFULNESS_ASLEEP:
59 return "Asleep";
60 case WAKEFULNESS_AWAKE:
61 return "Awake";
62 case WAKEFULNESS_DREAMING:
63 return "Dreaming";
64 case WAKEFULNESS_DOZING:
65 return "Dozing";
66 default:
67 return Integer.toString(wakefulness);
68 }
69 }
70
71 /**
72 * Returns true if the wakefulness state represents an interactive state
73 * as defined by {@link android.os.PowerManager#isInteractive}.
74 */
75 public static boolean isInteractive(int wakefulness) {
76 return wakefulness == WAKEFULNESS_AWAKE || wakefulness == WAKEFULNESS_DREAMING;
77 }
78
79 /**
Jeff Brown6f357d32014-01-15 20:40:55 -080080 * Used by the window manager to override the screen brightness based on the
81 * current foreground activity.
82 *
83 * This method must only be called by the window manager.
84 *
85 * @param brightness The overridden brightness, or -1 to disable the override.
86 */
Jeff Brown4ccb8232014-01-16 22:16:42 -080087 public abstract void setScreenBrightnessOverrideFromWindowManager(int brightness);
Jeff Brown6f357d32014-01-15 20:40:55 -080088
89 /**
90 * Used by the window manager to override the button brightness based on the
91 * current foreground activity.
92 *
93 * This method must only be called by the window manager.
94 *
95 * @param brightness The overridden brightness, or -1 to disable the override.
96 */
Jeff Brown4ccb8232014-01-16 22:16:42 -080097 public abstract void setButtonBrightnessOverrideFromWindowManager(int brightness);
Jeff Brown6f357d32014-01-15 20:40:55 -080098
99 /**
100 * Used by the window manager to override the user activity timeout based on the
101 * current foreground activity. It can only be used to make the timeout shorter
102 * than usual, not longer.
103 *
104 * This method must only be called by the window manager.
105 *
106 * @param timeoutMillis The overridden timeout, or -1 to disable the override.
107 */
Jeff Brown4ccb8232014-01-16 22:16:42 -0800108 public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);
Jeff Brown6f357d32014-01-15 20:40:55 -0800109
Jeff Brown970d4132014-07-19 11:33:47 -0700110 /**
111 * Used by the dream manager to override certain properties while dozing.
112 *
113 * @param screenState The overridden screen state, or {@link Display.STATE_UNKNOWN}
114 * to disable the override.
115 * @param screenBrightness The overridden screen brightness, or
116 * {@link PowerManager#BRIGHTNESS_DEFAULT} to disable the override.
117 */
118 public abstract void setDozeOverrideFromDreamManager(
119 int screenState, int screenBrightness);
120
Dianne Hackborncbefd8d2014-05-14 11:42:00 -0700121 public abstract boolean getLowPowerModeEnabled();
122
Jeff Brown2c43c332014-06-12 22:38:59 -0700123 public abstract void registerLowPowerModeObserver(LowPowerModeListener listener);
124
Dianne Hackborncbefd8d2014-05-14 11:42:00 -0700125 public interface LowPowerModeListener {
126 public void onLowPowerModeChanged(boolean enabled);
127 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800128}