blob: 03fa1d5923d5d71cf21f57c01950def6384c0238 [file] [log] [blame]
Jeff Brown4ccb8232014-01-16 22:16:42 -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.hardware.display;
18
Jeff Brownad9ef192014-04-08 17:26:30 -070019import android.hardware.SensorManager;
20import android.os.Handler;
21import android.os.PowerManager;
Jeff Brown4ccb8232014-01-16 22:16:42 -080022import android.view.DisplayInfo;
23
24/**
25 * Display manager local system service interface.
26 *
27 * @hide Only for use within the system server.
28 */
29public abstract class DisplayManagerInternal {
30 /**
Jeff Brownad9ef192014-04-08 17:26:30 -070031 * Called by the power manager to initialize power management facilities.
32 */
33 public abstract void initPowerManagement(DisplayPowerCallbacks callbacks,
34 Handler handler, SensorManager sensorManager);
35
36 /**
37 * Called by the power manager to request a new power state.
38 * <p>
39 * The display power controller makes a copy of the provided object and then
40 * begins adjusting the power state to match what was requested.
41 * </p>
42 *
43 * @param request The requested power state.
44 * @param waitForNegativeProximity If true, issues a request to wait for
45 * negative proximity before turning the screen back on, assuming the screen
46 * was turned off by the proximity sensor.
47 * @return True if display is ready, false if there are important changes that must
48 * be made asynchronously (such as turning the screen on), in which case the caller
49 * should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged()}
50 * then try the request again later until the state converges.
51 */
52 public abstract boolean requestPowerState(DisplayPowerRequest request,
53 boolean waitForNegativeProximity);
54
55 /**
56 * Returns true if the proximity sensor screen-off function is available.
57 */
58 public abstract boolean isProximitySensorAvailable();
59
60 /**
Jeff Brown4ccb8232014-01-16 22:16:42 -080061 * Called by the power manager to blank all displays.
62 */
63 public abstract void blankAllDisplaysFromPowerManager();
64
65 /**
66 * Called by the power manager to unblank all displays.
67 */
68 public abstract void unblankAllDisplaysFromPowerManager();
69
70 /**
71 * Returns information about the specified logical display.
72 *
73 * @param displayId The logical display id.
74 * @return The logical display info, or null if the display does not exist. The
75 * returned object must be treated as immutable.
76 */
77 public abstract DisplayInfo getDisplayInfo(int displayId);
78
79 /**
80 * Registers a display transaction listener to provide the client a chance to
81 * update its surfaces within the same transaction as any display layout updates.
82 *
83 * @param listener The listener to register.
84 */
85 public abstract void registerDisplayTransactionListener(DisplayTransactionListener listener);
86
87 /**
88 * Unregisters a display transaction listener to provide the client a chance to
89 * update its surfaces within the same transaction as any display layout updates.
90 *
91 * @param listener The listener to unregister.
92 */
93 public abstract void unregisterDisplayTransactionListener(DisplayTransactionListener listener);
94
95 /**
96 * Overrides the display information of a particular logical display.
97 * This is used by the window manager to control the size and characteristics
98 * of the default display. It is expected to apply the requested change
99 * to the display information synchronously so that applications will immediately
100 * observe the new state.
101 *
102 * NOTE: This method must be the only entry point by which the window manager
103 * influences the logical configuration of displays.
104 *
105 * @param displayId The logical display id.
106 * @param info The new data to be stored.
107 */
108 public abstract void setDisplayInfoOverrideFromWindowManager(
109 int displayId, DisplayInfo info);
110
111 /**
112 * Called by the window manager to perform traversals while holding a
113 * surface flinger transaction.
114 */
115 public abstract void performTraversalInTransactionFromWindowManager();
116
117 /**
118 * Tells the display manager whether there is interesting unique content on the
119 * specified logical display. This is used to control automatic mirroring.
120 * <p>
121 * If the display has unique content, then the display manager arranges for it
122 * to be presented on a physical display if appropriate. Otherwise, the display manager
123 * may choose to make the physical display mirror some other logical display.
124 * </p>
125 *
126 * @param displayId The logical display id to update.
127 * @param hasContent True if the logical display has content.
128 * @param inTraversal True if called from WindowManagerService during a window traversal
129 * prior to call to performTraversalInTransactionFromWindowManager.
130 */
131 public abstract void setDisplayHasContent(int displayId, boolean hasContent,
132 boolean inTraversal);
133
134 /**
Jeff Brownad9ef192014-04-08 17:26:30 -0700135 * Describes the requested power state of the display.
136 *
137 * This object is intended to describe the general characteristics of the
138 * power state, such as whether the screen should be on or off and the current
139 * brightness controls leaving the DisplayPowerController to manage the
140 * details of how the transitions between states should occur. The goal is for
141 * the PowerManagerService to focus on the global power state and not
142 * have to micro-manage screen off animations, auto-brightness and other effects.
143 */
144 public static final class DisplayPowerRequest {
145 public static final int SCREEN_STATE_OFF = 0;
146 public static final int SCREEN_STATE_DOZE = 1;
147 public static final int SCREEN_STATE_DIM = 2;
148 public static final int SCREEN_STATE_BRIGHT = 3;
149
150 // The requested minimum screen power state: off, doze, dim or bright.
151 public int screenState;
152
153 // If true, the proximity sensor overrides the screen state when an object is
154 // nearby, turning it off temporarily until the object is moved away.
155 public boolean useProximitySensor;
156
157 // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
158 // The display power controller may choose to clamp the brightness.
159 // When auto-brightness is enabled, this field should specify a nominal default
160 // value to use while waiting for the light sensor to report enough data.
161 public int screenBrightness;
162
163 // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
164 public float screenAutoBrightnessAdjustment;
165
166 // If true, enables automatic brightness control.
167 public boolean useAutoBrightness;
168
169 // If true, prevents the screen from completely turning on if it is currently off.
170 // The display does not enter a "ready" state if this flag is true and screen on is
171 // blocked. The window manager policy blocks screen on while it prepares the keyguard to
172 // prevent the user from seeing intermediate updates.
173 //
174 // Technically, we may not block the screen itself from turning on (because that introduces
175 // extra unnecessary latency) but we do prevent content on screen from becoming
176 // visible to the user.
177 public boolean blockScreenOn;
178
179 public DisplayPowerRequest() {
180 screenState = SCREEN_STATE_BRIGHT;
181 useProximitySensor = false;
182 screenBrightness = PowerManager.BRIGHTNESS_ON;
183 screenAutoBrightnessAdjustment = 0.0f;
184 useAutoBrightness = false;
185 blockScreenOn = false;
186 }
187
188 public DisplayPowerRequest(DisplayPowerRequest other) {
189 copyFrom(other);
190 }
191
192 // Returns true if we want the screen on in any mode, including doze.
193 public boolean wantScreenOnAny() {
194 return screenState != SCREEN_STATE_OFF;
195 }
196
197 // Returns true if we want the screen on in a normal mode, excluding doze.
198 // This is usually what we want to tell the rest of the system. For compatibility
199 // reasons, we pretend the screen is off when dozing.
200 public boolean wantScreenOnNormal() {
201 return screenState == SCREEN_STATE_DIM || screenState == SCREEN_STATE_BRIGHT;
202 }
203
204 public boolean wantLightSensorEnabled() {
205 // Specifically, we don't want the light sensor while dozing.
206 return useAutoBrightness && wantScreenOnNormal();
207 }
208
209 public void copyFrom(DisplayPowerRequest other) {
210 screenState = other.screenState;
211 useProximitySensor = other.useProximitySensor;
212 screenBrightness = other.screenBrightness;
213 screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
214 useAutoBrightness = other.useAutoBrightness;
215 blockScreenOn = other.blockScreenOn;
216 }
217
218 @Override
219 public boolean equals(Object o) {
220 return o instanceof DisplayPowerRequest
221 && equals((DisplayPowerRequest)o);
222 }
223
224 public boolean equals(DisplayPowerRequest other) {
225 return other != null
226 && screenState == other.screenState
227 && useProximitySensor == other.useProximitySensor
228 && screenBrightness == other.screenBrightness
229 && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
230 && useAutoBrightness == other.useAutoBrightness
231 && blockScreenOn == other.blockScreenOn;
232 }
233
234 @Override
235 public int hashCode() {
236 return 0; // don't care
237 }
238
239 @Override
240 public String toString() {
241 return "screenState=" + screenState
242 + ", useProximitySensor=" + useProximitySensor
243 + ", screenBrightness=" + screenBrightness
244 + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
245 + ", useAutoBrightness=" + useAutoBrightness
246 + ", blockScreenOn=" + blockScreenOn;
247 }
248 }
249
250 /**
251 * Asynchronous callbacks from the power controller to the power manager service.
252 */
253 public interface DisplayPowerCallbacks {
254 void onStateChanged();
255 void onProximityPositive();
256 void onProximityNegative();
257
258 void acquireSuspendBlocker();
259 void releaseSuspendBlocker();
260
261 void blankAllDisplays();
262 void unblankAllDisplays();
263 }
264
265 /**
Jeff Brown4ccb8232014-01-16 22:16:42 -0800266 * Called within a Surface transaction whenever the size or orientation of a
267 * display may have changed. Provides an opportunity for the client to
268 * update the position of its surfaces as part of the same transaction.
269 */
270 public interface DisplayTransactionListener {
271 void onDisplayTransaction();
272 }
273}