blob: 078958ad881a55b935b7c559021ab542ce65ad7a [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;
Andrii Kulianfb1bf692017-01-17 11:17:34 -080022import android.util.IntArray;
23import android.util.SparseArray;
Jeff Brown970d4132014-07-19 11:33:47 -070024import android.view.Display;
Jeff Brown4ccb8232014-01-16 22:16:42 -080025import android.view.DisplayInfo;
26
27/**
28 * Display manager local system service interface.
29 *
30 * @hide Only for use within the system server.
31 */
32public abstract class DisplayManagerInternal {
33 /**
Jeff Brownad9ef192014-04-08 17:26:30 -070034 * Called by the power manager to initialize power management facilities.
35 */
36 public abstract void initPowerManagement(DisplayPowerCallbacks callbacks,
37 Handler handler, SensorManager sensorManager);
38
39 /**
40 * Called by the power manager to request a new power state.
41 * <p>
42 * The display power controller makes a copy of the provided object and then
43 * begins adjusting the power state to match what was requested.
44 * </p>
45 *
46 * @param request The requested power state.
47 * @param waitForNegativeProximity If true, issues a request to wait for
48 * negative proximity before turning the screen back on, assuming the screen
49 * was turned off by the proximity sensor.
50 * @return True if display is ready, false if there are important changes that must
51 * be made asynchronously (such as turning the screen on), in which case the caller
52 * should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged()}
53 * then try the request again later until the state converges.
54 */
55 public abstract boolean requestPowerState(DisplayPowerRequest request,
56 boolean waitForNegativeProximity);
57
58 /**
59 * Returns true if the proximity sensor screen-off function is available.
60 */
61 public abstract boolean isProximitySensorAvailable();
62
63 /**
Jeff Brown4ccb8232014-01-16 22:16:42 -080064 * Returns information about the specified logical display.
65 *
66 * @param displayId The logical display id.
67 * @return The logical display info, or null if the display does not exist. The
68 * returned object must be treated as immutable.
69 */
70 public abstract DisplayInfo getDisplayInfo(int displayId);
71
72 /**
73 * Registers a display transaction listener to provide the client a chance to
74 * update its surfaces within the same transaction as any display layout updates.
75 *
76 * @param listener The listener to register.
77 */
78 public abstract void registerDisplayTransactionListener(DisplayTransactionListener listener);
79
80 /**
81 * Unregisters a display transaction listener to provide the client a chance to
82 * update its surfaces within the same transaction as any display layout updates.
83 *
84 * @param listener The listener to unregister.
85 */
86 public abstract void unregisterDisplayTransactionListener(DisplayTransactionListener listener);
87
88 /**
89 * Overrides the display information of a particular logical display.
90 * This is used by the window manager to control the size and characteristics
91 * of the default display. It is expected to apply the requested change
92 * to the display information synchronously so that applications will immediately
93 * observe the new state.
94 *
95 * NOTE: This method must be the only entry point by which the window manager
96 * influences the logical configuration of displays.
97 *
98 * @param displayId The logical display id.
99 * @param info The new data to be stored.
100 */
101 public abstract void setDisplayInfoOverrideFromWindowManager(
102 int displayId, DisplayInfo info);
103
104 /**
Andrii Kuliancd097992017-03-23 18:31:59 -0700105 * Get current display info without override from WindowManager.
106 * Current implementation of LogicalDisplay#getDisplayInfoLocked() always returns display info
107 * with overrides from WM if set. This method can be used for getting real display size without
108 * overrides to determine if real changes to display metrics happened.
109 * @param displayId Id of the target display.
110 * @param outInfo {@link DisplayInfo} to fill.
111 */
112 public abstract void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo);
113
114 /**
Jeff Brown4ccb8232014-01-16 22:16:42 -0800115 * Called by the window manager to perform traversals while holding a
116 * surface flinger transaction.
117 */
118 public abstract void performTraversalInTransactionFromWindowManager();
119
120 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700121 * Tells the display manager about properties of the display that depend on the windows on it.
122 * This includes whether there is interesting unique content on the specified logical display,
123 * and whether the one of the windows has a preferred refresh rate.
Jeff Brown4ccb8232014-01-16 22:16:42 -0800124 * <p>
125 * If the display has unique content, then the display manager arranges for it
126 * to be presented on a physical display if appropriate. Otherwise, the display manager
127 * may choose to make the physical display mirror some other logical display.
128 * </p>
129 *
Michael Wright3f145a22014-07-22 19:46:03 -0700130 * <p>
131 * If one of the windows on the display has a preferred refresh rate that's supported by the
132 * display, then the display manager will request its use.
133 * </p>
134 *
Jeff Brown4ccb8232014-01-16 22:16:42 -0800135 * @param displayId The logical display id to update.
Michael Wright3f145a22014-07-22 19:46:03 -0700136 * @param hasContent True if the logical display has content. This is used to control automatic
137 * mirroring.
138 * @param requestedRefreshRate The preferred refresh rate for the top-most visible window that
139 * has a preference.
P.Y. Laligand5c7773d2015-05-04 13:30:58 -0700140 * @param requestedModeId The preferred mode id for the top-most visible window that has a
141 * preference.
Jeff Brown4ccb8232014-01-16 22:16:42 -0800142 * @param inTraversal True if called from WindowManagerService during a window traversal
143 * prior to call to performTraversalInTransactionFromWindowManager.
144 */
Michael Wright3f145a22014-07-22 19:46:03 -0700145 public abstract void setDisplayProperties(int displayId, boolean hasContent,
P.Y. Laligand5c7773d2015-05-04 13:30:58 -0700146 float requestedRefreshRate, int requestedModeId, boolean inTraversal);
Jeff Brown4ccb8232014-01-16 22:16:42 -0800147
148 /**
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800149 * Applies an offset to the contents of a display, for example to avoid burn-in.
150 * <p>
151 * TODO: Technically this should be associated with a physical rather than logical
152 * display but this is good enough for now.
153 * </p>
154 *
155 * @param displayId The logical display id to update.
156 * @param x The X offset by which to shift the contents of the display.
157 * @param y The Y offset by which to shift the contents of the display.
158 */
159 public abstract void setDisplayOffsets(int displayId, int x, int y);
160
161 /**
Andrii Kulianfb1bf692017-01-17 11:17:34 -0800162 * Provide a list of UIDs that are present on the display and are allowed to access it.
163 *
164 * @param displayAccessUIDs Mapping displayId -> int array of UIDs.
165 */
166 public abstract void setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs);
167
168 /**
169 * Check if specified UID's content is present on display and should be granted access to it.
170 *
171 * @param uid UID to be checked.
172 * @param displayId id of the display where presence of the content is checked.
173 * */
174 public abstract boolean isUidPresentOnDisplay(int uid, int displayId);
175
176 /**
Kenny Guycfe7b702017-11-14 21:04:58 +0000177 * Persist brightness slider events.
178 */
179 public abstract void persistBrightnessSliderEvents();
180
181 /**
Adrian Roose1d68cd2018-01-17 12:54:50 +0100182 * Notifies the display manager that resource overlays have changed.
183 */
184 public abstract void onOverlayChanged();
185
186 /**
Jeff Brownad9ef192014-04-08 17:26:30 -0700187 * Describes the requested power state of the display.
188 *
189 * This object is intended to describe the general characteristics of the
190 * power state, such as whether the screen should be on or off and the current
191 * brightness controls leaving the DisplayPowerController to manage the
192 * details of how the transitions between states should occur. The goal is for
193 * the PowerManagerService to focus on the global power state and not
194 * have to micro-manage screen off animations, auto-brightness and other effects.
195 */
196 public static final class DisplayPowerRequest {
Jeff Brown970d4132014-07-19 11:33:47 -0700197 // Policy: Turn screen off as if the user pressed the power button
198 // including playing a screen off animation if applicable.
199 public static final int POLICY_OFF = 0;
200 // Policy: Enable dozing and always-on display functionality.
201 public static final int POLICY_DOZE = 1;
202 // Policy: Make the screen dim when the user activity timeout is
203 // about to expire.
204 public static final int POLICY_DIM = 2;
205 // Policy: Make the screen bright as usual.
206 public static final int POLICY_BRIGHT = 3;
Santos Cordon3107d292016-09-20 15:50:35 -0700207 // Policy: Keep the screen and display optimized for VR mode.
208 public static final int POLICY_VR = 4;
Jeff Brownad9ef192014-04-08 17:26:30 -0700209
Jeff Brown970d4132014-07-19 11:33:47 -0700210 // The basic overall policy to apply: off, doze, dim or bright.
211 public int policy;
Jeff Brownad9ef192014-04-08 17:26:30 -0700212
213 // If true, the proximity sensor overrides the screen state when an object is
214 // nearby, turning it off temporarily until the object is moved away.
215 public boolean useProximitySensor;
216
217 // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
218 // The display power controller may choose to clamp the brightness.
219 // When auto-brightness is enabled, this field should specify a nominal default
220 // value to use while waiting for the light sensor to report enough data.
221 public int screenBrightness;
222
223 // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
224 public float screenAutoBrightnessAdjustment;
225
Jeff Browna576b4d2015-04-23 19:58:06 -0700226 // Set to true if screenBrightness and screenAutoBrightnessAdjustment were both
227 // set by the user as opposed to being programmatically controlled by apps.
228 public boolean brightnessSetByUser;
229
Michael Wright144aac92017-12-21 18:37:41 +0000230 // Set to true if screenBrightness or screenAutoBrightnessAdjustment are being set
231 // temporarily. This is typically set while the user has their finger on the brightness
232 // control, before they've selected the final brightness value.
233 public boolean brightnessIsTemporary;
234
Jeff Brownad9ef192014-04-08 17:26:30 -0700235 // If true, enables automatic brightness control.
236 public boolean useAutoBrightness;
237
Jeff Browne333e672014-10-28 13:48:55 -0700238 // If true, scales the brightness to half of desired.
Ruchi Kandoif974cc82014-05-01 11:25:10 -0700239 public boolean lowPowerMode;
240
jackqdyulei92681e82017-02-28 11:26:28 -0800241 // The factor to adjust the screen brightness in low power mode in the range
242 // 0 (screen off) to 1 (no change)
243 public float screenLowPowerBrightnessFactor;
244
Jeff Browne333e672014-10-28 13:48:55 -0700245 // If true, applies a brightness boost.
246 public boolean boostScreenBrightness;
247
Jeff Brownad9ef192014-04-08 17:26:30 -0700248 // If true, prevents the screen from completely turning on if it is currently off.
249 // The display does not enter a "ready" state if this flag is true and screen on is
250 // blocked. The window manager policy blocks screen on while it prepares the keyguard to
251 // prevent the user from seeing intermediate updates.
252 //
253 // Technically, we may not block the screen itself from turning on (because that introduces
254 // extra unnecessary latency) but we do prevent content on screen from becoming
255 // visible to the user.
256 public boolean blockScreenOn;
257
Jeff Brown970d4132014-07-19 11:33:47 -0700258 // Overrides the policy for adjusting screen brightness and state while dozing.
259 public int dozeScreenBrightness;
260 public int dozeScreenState;
261
Jeff Brownad9ef192014-04-08 17:26:30 -0700262 public DisplayPowerRequest() {
Jeff Brown970d4132014-07-19 11:33:47 -0700263 policy = POLICY_BRIGHT;
Jeff Brownad9ef192014-04-08 17:26:30 -0700264 useProximitySensor = false;
265 screenBrightness = PowerManager.BRIGHTNESS_ON;
266 screenAutoBrightnessAdjustment = 0.0f;
jackqdyulei92681e82017-02-28 11:26:28 -0800267 screenLowPowerBrightnessFactor = 0.5f;
Jeff Brownad9ef192014-04-08 17:26:30 -0700268 useAutoBrightness = false;
269 blockScreenOn = false;
Jeff Brown970d4132014-07-19 11:33:47 -0700270 dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
271 dozeScreenState = Display.STATE_UNKNOWN;
Jeff Brownad9ef192014-04-08 17:26:30 -0700272 }
273
274 public DisplayPowerRequest(DisplayPowerRequest other) {
275 copyFrom(other);
276 }
277
Jeff Brown970d4132014-07-19 11:33:47 -0700278 public boolean isBrightOrDim() {
279 return policy == POLICY_BRIGHT || policy == POLICY_DIM;
Jeff Brownad9ef192014-04-08 17:26:30 -0700280 }
281
Santos Cordon3107d292016-09-20 15:50:35 -0700282 public boolean isVr() {
283 return policy == POLICY_VR;
284 }
285
Jeff Brownad9ef192014-04-08 17:26:30 -0700286 public void copyFrom(DisplayPowerRequest other) {
Jeff Brown970d4132014-07-19 11:33:47 -0700287 policy = other.policy;
Jeff Brownad9ef192014-04-08 17:26:30 -0700288 useProximitySensor = other.useProximitySensor;
289 screenBrightness = other.screenBrightness;
290 screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
jackqdyulei92681e82017-02-28 11:26:28 -0800291 screenLowPowerBrightnessFactor = other.screenLowPowerBrightnessFactor;
Jeff Browna576b4d2015-04-23 19:58:06 -0700292 brightnessSetByUser = other.brightnessSetByUser;
Michael Wright144aac92017-12-21 18:37:41 +0000293 brightnessIsTemporary = other.brightnessIsTemporary;
Jeff Brownad9ef192014-04-08 17:26:30 -0700294 useAutoBrightness = other.useAutoBrightness;
295 blockScreenOn = other.blockScreenOn;
Ruchi Kandoif974cc82014-05-01 11:25:10 -0700296 lowPowerMode = other.lowPowerMode;
Jeff Browne333e672014-10-28 13:48:55 -0700297 boostScreenBrightness = other.boostScreenBrightness;
Jeff Brown970d4132014-07-19 11:33:47 -0700298 dozeScreenBrightness = other.dozeScreenBrightness;
299 dozeScreenState = other.dozeScreenState;
Jeff Brownad9ef192014-04-08 17:26:30 -0700300 }
301
302 @Override
303 public boolean equals(Object o) {
304 return o instanceof DisplayPowerRequest
305 && equals((DisplayPowerRequest)o);
306 }
307
308 public boolean equals(DisplayPowerRequest other) {
309 return other != null
Jeff Brown970d4132014-07-19 11:33:47 -0700310 && policy == other.policy
Jeff Brownad9ef192014-04-08 17:26:30 -0700311 && useProximitySensor == other.useProximitySensor
312 && screenBrightness == other.screenBrightness
313 && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
jackqdyulei92681e82017-02-28 11:26:28 -0800314 && screenLowPowerBrightnessFactor
315 == other.screenLowPowerBrightnessFactor
Jeff Browna576b4d2015-04-23 19:58:06 -0700316 && brightnessSetByUser == other.brightnessSetByUser
Michael Wright144aac92017-12-21 18:37:41 +0000317 && brightnessIsTemporary == other.brightnessIsTemporary
Jeff Brownad9ef192014-04-08 17:26:30 -0700318 && useAutoBrightness == other.useAutoBrightness
Ruchi Kandoif974cc82014-05-01 11:25:10 -0700319 && blockScreenOn == other.blockScreenOn
Jeff Brown970d4132014-07-19 11:33:47 -0700320 && lowPowerMode == other.lowPowerMode
Jeff Browne333e672014-10-28 13:48:55 -0700321 && boostScreenBrightness == other.boostScreenBrightness
Jeff Brown970d4132014-07-19 11:33:47 -0700322 && dozeScreenBrightness == other.dozeScreenBrightness
Justin Klaassen5483cea2017-02-02 09:02:35 -0800323 && dozeScreenState == other.dozeScreenState;
Jeff Brownad9ef192014-04-08 17:26:30 -0700324 }
325
326 @Override
327 public int hashCode() {
328 return 0; // don't care
329 }
330
331 @Override
332 public String toString() {
Jeff Brown970d4132014-07-19 11:33:47 -0700333 return "policy=" + policyToString(policy)
Jeff Brownad9ef192014-04-08 17:26:30 -0700334 + ", useProximitySensor=" + useProximitySensor
335 + ", screenBrightness=" + screenBrightness
336 + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
jackqdyulei92681e82017-02-28 11:26:28 -0800337 + ", screenLowPowerBrightnessFactor=" + screenLowPowerBrightnessFactor
Jeff Browna576b4d2015-04-23 19:58:06 -0700338 + ", brightnessSetByUser=" + brightnessSetByUser
Michael Wright144aac92017-12-21 18:37:41 +0000339 + ", brightnessIsTemporary=" + brightnessIsTemporary
Jeff Brownad9ef192014-04-08 17:26:30 -0700340 + ", useAutoBrightness=" + useAutoBrightness
Ruchi Kandoif974cc82014-05-01 11:25:10 -0700341 + ", blockScreenOn=" + blockScreenOn
Jeff Brown970d4132014-07-19 11:33:47 -0700342 + ", lowPowerMode=" + lowPowerMode
Jeff Browne333e672014-10-28 13:48:55 -0700343 + ", boostScreenBrightness=" + boostScreenBrightness
Jeff Brown970d4132014-07-19 11:33:47 -0700344 + ", dozeScreenBrightness=" + dozeScreenBrightness
Justin Klaassen5483cea2017-02-02 09:02:35 -0800345 + ", dozeScreenState=" + Display.stateToString(dozeScreenState);
Jeff Brown970d4132014-07-19 11:33:47 -0700346 }
347
348 public static String policyToString(int policy) {
349 switch (policy) {
350 case POLICY_OFF:
351 return "OFF";
352 case POLICY_DOZE:
353 return "DOZE";
354 case POLICY_DIM:
355 return "DIM";
356 case POLICY_BRIGHT:
357 return "BRIGHT";
Santos Cordon3107d292016-09-20 15:50:35 -0700358 case POLICY_VR:
359 return "VR";
Jeff Brown970d4132014-07-19 11:33:47 -0700360 default:
361 return Integer.toString(policy);
362 }
Jeff Brownad9ef192014-04-08 17:26:30 -0700363 }
364 }
365
366 /**
367 * Asynchronous callbacks from the power controller to the power manager service.
368 */
369 public interface DisplayPowerCallbacks {
370 void onStateChanged();
371 void onProximityPositive();
372 void onProximityNegative();
Jeff Brown037c33e2014-04-09 00:31:55 -0700373 void onDisplayStateChange(int state); // one of the Display state constants
Jeff Brownad9ef192014-04-08 17:26:30 -0700374
375 void acquireSuspendBlocker();
376 void releaseSuspendBlocker();
Jeff Brownad9ef192014-04-08 17:26:30 -0700377 }
378
379 /**
Jeff Brown4ccb8232014-01-16 22:16:42 -0800380 * Called within a Surface transaction whenever the size or orientation of a
381 * display may have changed. Provides an opportunity for the client to
382 * update the position of its surfaces as part of the same transaction.
383 */
384 public interface DisplayTransactionListener {
385 void onDisplayTransaction();
386 }
387}