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.hardware.display;
18 
19 import android.annotation.IntDef;
20 import android.annotation.Nullable;
21 import android.companion.virtual.IVirtualDevice;
22 import android.graphics.Point;
23 import android.hardware.SensorManager;
24 import android.hardware.input.HostUsiVersion;
25 import android.os.Handler;
26 import android.os.PowerManager;
27 import android.util.IntArray;
28 import android.util.SparseArray;
29 import android.view.Display;
30 import android.view.DisplayInfo;
31 import android.view.SurfaceControl;
32 import android.view.SurfaceControl.RefreshRateRange;
33 import android.view.SurfaceControl.Transaction;
34 import android.window.DisplayWindowPolicyController;
35 import android.window.ScreenCapture;
36 
37 import java.lang.annotation.Retention;
38 import java.lang.annotation.RetentionPolicy;
39 import java.util.List;
40 import java.util.Set;
41 
42 /**
43  * Display manager local system service interface.
44  *
45  * @hide Only for use within the system server.
46  */
47 public abstract class DisplayManagerInternal {
48 
49     @IntDef(prefix = {"REFRESH_RATE_LIMIT_"}, value = {
50             REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE
51     })
52     @Retention(RetentionPolicy.SOURCE)
53     public @interface RefreshRateLimitType {}
54 
55     /** Refresh rate should be limited when High Brightness Mode is active. */
56     public static final int REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE = 1;
57 
58     /**
59      * Called by the power manager to initialize power management facilities.
60      */
initPowerManagement(DisplayPowerCallbacks callbacks, Handler handler, SensorManager sensorManager)61     public abstract void initPowerManagement(DisplayPowerCallbacks callbacks,
62             Handler handler, SensorManager sensorManager);
63 
64     /**
65      * Called by the VirtualDeviceManagerService to create a VirtualDisplay owned by a
66      * VirtualDevice.
67      */
createVirtualDisplay(VirtualDisplayConfig config, IVirtualDisplayCallback callback, IVirtualDevice virtualDevice, DisplayWindowPolicyController dwpc, String packageName)68     public abstract int createVirtualDisplay(VirtualDisplayConfig config,
69             IVirtualDisplayCallback callback, IVirtualDevice virtualDevice,
70             DisplayWindowPolicyController dwpc, String packageName);
71 
72     /**
73      * Called by the power manager to request a new power state.
74      * <p>
75      * The display power controller makes a copy of the provided object and then
76      * begins adjusting the power state to match what was requested.
77      * </p>
78      *
79      * @param groupId The identifier for the display group being requested to change power state
80      * @param request The requested power state.
81      * @param waitForNegativeProximity If {@code true}, issues a request to wait for
82      * negative proximity before turning the screen back on, assuming the screen
83      * was turned off by the proximity sensor.
84      * @return {@code true} if display group is ready, {@code false} if there are important
85      * changes that must be made asynchronously (such as turning the screen on), in which case
86      * the caller should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged}
87      * then try the request again later until the state converges. If the provided {@code groupId}
88      * cannot be found then {@code true} will be returned.
89      */
requestPowerState(int groupId, DisplayPowerRequest request, boolean waitForNegativeProximity)90     public abstract boolean requestPowerState(int groupId, DisplayPowerRequest request,
91             boolean waitForNegativeProximity);
92 
93     /**
94      * Returns {@code true} if the proximity sensor screen-off function is available.
95      */
isProximitySensorAvailable()96     public abstract boolean isProximitySensorAvailable();
97 
98     /**
99      * Registers a display group listener which will be informed of the addition, removal, or change
100      * of display groups.
101      *
102      * @param listener The listener to register.
103      */
registerDisplayGroupListener(DisplayGroupListener listener)104     public abstract void registerDisplayGroupListener(DisplayGroupListener listener);
105 
106     /**
107      * Unregisters a display group listener which will be informed of the addition, removal, or
108      * change of display groups.
109      *
110      * @param listener The listener to unregister.
111      */
unregisterDisplayGroupListener(DisplayGroupListener listener)112     public abstract void unregisterDisplayGroupListener(DisplayGroupListener listener);
113 
114     /**
115      * Screenshot for internal system-only use such as rotation, etc.  This method includes
116      * secure layers and the result should never be exposed to non-system applications.
117      * This method does not apply any rotation and provides the output in natural orientation.
118      *
119      * @param displayId The display id to take the screenshot of.
120      * @return The buffer or null if we have failed.
121      */
systemScreenshot(int displayId)122     public abstract ScreenCapture.ScreenshotHardwareBuffer systemScreenshot(int displayId);
123 
124     /**
125      * General screenshot functionality that excludes secure layers and applies appropriate
126      * rotation that the device is currently in.
127      *
128      * @param displayId The display id to take the screenshot of.
129      * @return The buffer or null if we have failed.
130      */
userScreenshot(int displayId)131     public abstract ScreenCapture.ScreenshotHardwareBuffer userScreenshot(int displayId);
132 
133     /**
134      * Returns information about the specified logical display.
135      *
136      * @param displayId The logical display id.
137      * @return The logical display info, or null if the display does not exist.  The
138      * returned object must be treated as immutable.
139      */
getDisplayInfo(int displayId)140     public abstract DisplayInfo getDisplayInfo(int displayId);
141 
142     /**
143      * Returns a set of DisplayInfo, for the states that may be assumed by either the given display,
144      * or any other display within that display's group.
145      *
146      * @param displayId The logical display id to fetch DisplayInfo for.
147      */
getPossibleDisplayInfo(int displayId)148     public abstract Set<DisplayInfo> getPossibleDisplayInfo(int displayId);
149 
150     /**
151      * Returns the position of the display's projection.
152      *
153      * @param displayId The logical display id.
154      * @return The x, y coordinates of the display, or null if the display does not exist. The
155      * return object must be treated as immutable.
156      */
157     @Nullable
getDisplayPosition(int displayId)158     public abstract Point getDisplayPosition(int displayId);
159 
160     /**
161      * Registers a display transaction listener to provide the client a chance to
162      * update its surfaces within the same transaction as any display layout updates.
163      *
164      * @param listener The listener to register.
165      */
registerDisplayTransactionListener(DisplayTransactionListener listener)166     public abstract void registerDisplayTransactionListener(DisplayTransactionListener listener);
167 
168     /**
169      * Unregisters a display transaction listener to provide the client a chance to
170      * update its surfaces within the same transaction as any display layout updates.
171      *
172      * @param listener The listener to unregister.
173      */
unregisterDisplayTransactionListener(DisplayTransactionListener listener)174     public abstract void unregisterDisplayTransactionListener(DisplayTransactionListener listener);
175 
176     /**
177      * Overrides the display information of a particular logical display.
178      * This is used by the window manager to control the size and characteristics
179      * of the default display.  It is expected to apply the requested change
180      * to the display information synchronously so that applications will immediately
181      * observe the new state.
182      *
183      * NOTE: This method must be the only entry point by which the window manager
184      * influences the logical configuration of displays.
185      *
186      * @param displayId The logical display id.
187      * @param info The new data to be stored.
188      */
setDisplayInfoOverrideFromWindowManager( int displayId, DisplayInfo info)189     public abstract void setDisplayInfoOverrideFromWindowManager(
190             int displayId, DisplayInfo info);
191 
192     /**
193      * Get current display info without override from WindowManager.
194      * Current implementation of LogicalDisplay#getDisplayInfoLocked() always returns display info
195      * with overrides from WM if set. This method can be used for getting real display size without
196      * overrides to determine if real changes to display metrics happened.
197      * @param displayId Id of the target display.
198      * @param outInfo {@link DisplayInfo} to fill.
199      */
getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo)200     public abstract void getNonOverrideDisplayInfo(int displayId, DisplayInfo outInfo);
201 
202     /**
203      * Called by the window manager to perform traversals while holding a
204      * surface flinger transaction.
205      */
performTraversal(Transaction t)206     public abstract void performTraversal(Transaction t);
207 
208     /**
209      * Tells the display manager about properties of the display that depend on the windows on it.
210      * This includes whether there is interesting unique content on the specified logical display,
211      * and whether the one of the windows has a preferred refresh rate.
212      * <p>
213      * If the display has unique content, then the display manager arranges for it
214      * to be presented on a physical display if appropriate.  Otherwise, the display manager
215      * may choose to make the physical display mirror some other logical display.
216      * </p>
217      *
218      * <p>
219      * If one of the windows on the display has a preferred refresh rate that's supported by the
220      * display, then the display manager will request its use.
221      * </p>
222      *
223      * @param displayId The logical display id to update.
224      * @param hasContent True if the logical display has content. This is used to control automatic
225      * mirroring.
226      * @param requestedRefreshRate The preferred refresh rate for the top-most visible window that
227      * has a preference.
228      * @param requestedModeId The preferred mode id for the top-most visible window that has a
229      * preference.
230      * @param requestedMinRefreshRate The preferred lowest refresh rate for the top-most visible
231      *                                window that has a preference.
232      * @param requestedMaxRefreshRate The preferred highest refresh rate for the top-most visible
233      *                                window that has a preference.
234      * @param requestedMinimalPostProcessing The preferred minimal post processing setting for the
235      * display. This is true when there is at least one visible window that wants minimal post
236      * processng on.
237      * @param disableHdrConversion The preferred HDR conversion setting for the window.
238      * @param inTraversal True if called from WindowManagerService during a window traversal
239      * prior to call to performTraversalInTransactionFromWindowManager.
240      */
setDisplayProperties(int displayId, boolean hasContent, float requestedRefreshRate, int requestedModeId, float requestedMinRefreshRate, float requestedMaxRefreshRate, boolean requestedMinimalPostProcessing, boolean disableHdrConversion, boolean inTraversal)241     public abstract void setDisplayProperties(int displayId, boolean hasContent,
242             float requestedRefreshRate, int requestedModeId, float requestedMinRefreshRate,
243             float requestedMaxRefreshRate, boolean requestedMinimalPostProcessing,
244             boolean disableHdrConversion, boolean inTraversal);
245 
246     /**
247      * Applies an offset to the contents of a display, for example to avoid burn-in.
248      * <p>
249      * TODO: Technically this should be associated with a physical rather than logical
250      * display but this is good enough for now.
251      * </p>
252      *
253      * @param displayId The logical display id to update.
254      * @param x The X offset by which to shift the contents of the display.
255      * @param y The Y offset by which to shift the contents of the display.
256      */
setDisplayOffsets(int displayId, int x, int y)257     public abstract void setDisplayOffsets(int displayId, int x, int y);
258 
259     /**
260      * Disables scaling for a display.
261      *
262      * @param displayId The logical display id to disable scaling for.
263      * @param disableScaling {@code true} to disable scaling,
264      * {@code false} to use the default scaling behavior of the logical display.
265      */
setDisplayScalingDisabled(int displayId, boolean disableScaling)266     public abstract void setDisplayScalingDisabled(int displayId, boolean disableScaling);
267 
268     /**
269      * Provide a list of UIDs that are present on the display and are allowed to access it.
270      *
271      * @param displayAccessUIDs Mapping displayId -> int array of UIDs.
272      */
setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs)273     public abstract void setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs);
274 
275     /**
276      * Persist brightness slider events and ambient brightness stats.
277      */
persistBrightnessTrackerState()278     public abstract void persistBrightnessTrackerState();
279 
280     /**
281      * Notifies the display manager that resource overlays have changed.
282      */
onOverlayChanged()283     public abstract void onOverlayChanged();
284 
285     /**
286      * Get the attributes available for display color sampling.
287      * @param displayId id of the display to collect the sample from.
288      *
289      * @return The attributes the display supports, or null if sampling is not supported.
290      */
291     @Nullable
getDisplayedContentSamplingAttributes( int displayId)292     public abstract DisplayedContentSamplingAttributes getDisplayedContentSamplingAttributes(
293             int displayId);
294 
295     /**
296      * Enable or disable the collection of color samples.
297      *
298      * @param displayId id of the display to collect the sample from.
299      * @param componentMask a bitmask of the color channels to collect samples for, or zero for all
300      *                      available.
301      * @param maxFrames maintain a ringbuffer of the last maxFrames.
302      * @param enable True to enable, False to disable.
303      *
304      * @return True if sampling was enabled, false if failure.
305      */
setDisplayedContentSamplingEnabled( int displayId, boolean enable, int componentMask, int maxFrames)306     public abstract boolean setDisplayedContentSamplingEnabled(
307             int displayId, boolean enable, int componentMask, int maxFrames);
308 
309     /**
310      * Accesses the color histogram statistics of displayed frames on devices that support sampling.
311      *
312      * @param displayId id of the display to collect the sample from
313      * @param maxFrames limit the statistics to the last maxFrames number of frames.
314      * @param timestamp discard statistics that were collected prior to timestamp, where timestamp
315      *                  is given as CLOCK_MONOTONIC.
316      * @return The statistics representing a histogram of the color distribution of the frames
317      *         displayed on-screen, or null if sampling is not supported.
318     */
319     @Nullable
getDisplayedContentSample( int displayId, long maxFrames, long timestamp)320     public abstract DisplayedContentSample getDisplayedContentSample(
321             int displayId, long maxFrames, long timestamp);
322 
323     /**
324      * Temporarily ignore proximity-sensor-based display behavior until there is a change
325      * to the proximity sensor state. This allows the display to turn back on even if something
326      * is obstructing the proximity sensor.
327      */
ignoreProximitySensorUntilChanged()328     public abstract void ignoreProximitySensorUntilChanged();
329 
330     /**
331      * Returns the refresh rate switching type.
332      */
333     @DisplayManager.SwitchingType
getRefreshRateSwitchingType()334     public abstract int getRefreshRateSwitchingType();
335 
336     /**
337      * TODO: b/191384041 - Replace this with getRefreshRateLimitations()
338      * Return the refresh rate restriction for the specified display and sensor pairing. If the
339      * specified sensor is identified as an associated sensor in the specified display's
340      * display-device-config file, then return any refresh rate restrictions that it might define.
341      * If no restriction is specified, or the sensor is not associated with the display, then null
342      * will be returned.
343      *
344      * @param displayId The display to check against.
345      * @param name The name of the sensor.
346      * @param type The type of sensor.
347      *
348      * @return The min/max refresh-rate restriction as a {@link Pair} of floats, or null if not
349      * restricted.
350      */
getRefreshRateForDisplayAndSensor( int displayId, String name, String type)351     public abstract RefreshRateRange getRefreshRateForDisplayAndSensor(
352             int displayId, String name, String type);
353 
354     /**
355      * Returns a list of various refresh rate limitations for the specified display.
356      *
357      * @param displayId The display to get limitations for.
358      *
359      * @return a list of {@link RefreshRateLimitation}s describing the various limits.
360      */
getRefreshRateLimitations(int displayId)361     public abstract List<RefreshRateLimitation> getRefreshRateLimitations(int displayId);
362 
363     /**
364      * For the given displayId, updates if WindowManager is responsible for mirroring on that
365      * display. If {@code false}, then SurfaceFlinger performs no layer mirroring to the
366      * given display.
367      * Only used for mirroring started from MediaProjection.
368      */
setWindowManagerMirroring(int displayId, boolean isMirroring)369     public abstract void setWindowManagerMirroring(int displayId, boolean isMirroring);
370 
371     /**
372      * Returns the default size of the surface associated with the display, or null if the surface
373      * is not provided for layer mirroring by SurfaceFlinger. Size is rotated to reflect the current
374      * display device orientation.
375      * Used for mirroring from MediaProjection, or a physical display based on display flags.
376      */
getDisplaySurfaceDefaultSize(int displayId)377     public abstract Point getDisplaySurfaceDefaultSize(int displayId);
378 
379     /**
380      * Get a new displayId which represents the display you want to mirror. If mirroring is not
381      * enabled on the display, {@link Display#INVALID_DISPLAY} will be returned.
382      *
383      * @param displayId The id of the display.
384      * @return The displayId that should be mirrored or INVALID_DISPLAY if mirroring is not enabled.
385      */
getDisplayIdToMirror(int displayId)386     public abstract int getDisplayIdToMirror(int displayId);
387 
388     /**
389      * Receives early interactivity changes from power manager.
390      *
391      * @param interactive The interactive state that the device is moving into.
392      */
onEarlyInteractivityChange(boolean interactive)393     public abstract void onEarlyInteractivityChange(boolean interactive);
394 
395     /**
396      * Get {@link DisplayWindowPolicyController} associated to the {@link DisplayInfo#displayId}
397      *
398      * @param displayId The id of the display.
399      * @return The associated {@link DisplayWindowPolicyController}.
400      */
getDisplayWindowPolicyController(int displayId)401     public abstract DisplayWindowPolicyController getDisplayWindowPolicyController(int displayId);
402 
403     /**
404      * Get DisplayPrimaries from SF for a particular display.
405      */
getDisplayNativePrimaries(int displayId)406     public abstract SurfaceControl.DisplayPrimaries getDisplayNativePrimaries(int displayId);
407 
408     /**
409      * Get the version of the Universal Stylus Initiative (USI) Protocol supported by the display.
410      * @param displayId The id of the display.
411      * @return The USI version, or null if not supported
412      */
413     @Nullable
getHostUsiVersion(int displayId)414     public abstract HostUsiVersion getHostUsiVersion(int displayId);
415 
416     /**
417      * Get the ALS data for a particular display.
418      *
419      * @param displayId The id of the display.
420      * @return {@link AmbientLightSensorData}
421      */
422     @Nullable
getAmbientLightSensorData(int displayId)423     public abstract AmbientLightSensorData getAmbientLightSensorData(int displayId);
424 
425     /**
426      * Get all available DisplayGroupIds.
427      */
getDisplayGroupIds()428     public abstract IntArray getDisplayGroupIds();
429 
430     /**
431      * Describes the requested power state of the display.
432      *
433      * This object is intended to describe the general characteristics of the
434      * power state, such as whether the screen should be on or off and the current
435      * brightness controls leaving the DisplayPowerController to manage the
436      * details of how the transitions between states should occur.  The goal is for
437      * the PowerManagerService to focus on the global power state and not
438      * have to micro-manage screen off animations, auto-brightness and other effects.
439      */
440     public static class DisplayPowerRequest {
441         // Policy: Turn screen off as if the user pressed the power button
442         // including playing a screen off animation if applicable.
443         public static final int POLICY_OFF = 0;
444         // Policy: Enable dozing and always-on display functionality.
445         public static final int POLICY_DOZE = 1;
446         // Policy: Make the screen dim when the user activity timeout is
447         // about to expire.
448         public static final int POLICY_DIM = 2;
449         // Policy: Make the screen bright as usual.
450         public static final int POLICY_BRIGHT = 3;
451 
452         // The basic overall policy to apply: off, doze, dim or bright.
453         public int policy;
454 
455         // If true, the proximity sensor overrides the screen state when an object is
456         // nearby, turning it off temporarily until the object is moved away.
457         public boolean useProximitySensor;
458 
459         // An override of the screen brightness.
460         // Set to PowerManager.BRIGHTNESS_INVALID if there's no override.
461         public float screenBrightnessOverride;
462 
463         // An override of the screen auto-brightness adjustment factor in the range -1 (dimmer) to
464         // 1 (brighter). Set to Float.NaN if there's no override.
465         public float screenAutoBrightnessAdjustmentOverride;
466 
467         // If true, scales the brightness to a fraction of desired (as defined by
468         // screenLowPowerBrightnessFactor).
469         public boolean lowPowerMode;
470 
471         // The factor to adjust the screen brightness in low power mode in the range
472         // 0 (screen off) to 1 (no change)
473         public float screenLowPowerBrightnessFactor;
474 
475         // If true, applies a brightness boost.
476         public boolean boostScreenBrightness;
477 
478         // If true, prevents the screen from completely turning on if it is currently off.
479         // The display does not enter a "ready" state if this flag is true and screen on is
480         // blocked.  The window manager policy blocks screen on while it prepares the keyguard to
481         // prevent the user from seeing intermediate updates.
482         //
483         // Technically, we may not block the screen itself from turning on (because that introduces
484         // extra unnecessary latency) but we do prevent content on screen from becoming
485         // visible to the user.
486         public boolean blockScreenOn;
487 
488         // Overrides the policy for adjusting screen brightness and state while dozing.
489         public int dozeScreenState;
490         public float dozeScreenBrightness;
491 
DisplayPowerRequest()492         public DisplayPowerRequest() {
493             policy = POLICY_BRIGHT;
494             useProximitySensor = false;
495             screenBrightnessOverride = PowerManager.BRIGHTNESS_INVALID_FLOAT;
496             screenAutoBrightnessAdjustmentOverride = Float.NaN;
497             screenLowPowerBrightnessFactor = 0.5f;
498             blockScreenOn = false;
499             dozeScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
500             dozeScreenState = Display.STATE_UNKNOWN;
501         }
502 
DisplayPowerRequest(DisplayPowerRequest other)503         public DisplayPowerRequest(DisplayPowerRequest other) {
504             copyFrom(other);
505         }
506 
isBrightOrDim()507         public boolean isBrightOrDim() {
508             return policy == POLICY_BRIGHT || policy == POLICY_DIM;
509         }
510 
copyFrom(DisplayPowerRequest other)511         public void copyFrom(DisplayPowerRequest other) {
512             policy = other.policy;
513             useProximitySensor = other.useProximitySensor;
514             screenBrightnessOverride = other.screenBrightnessOverride;
515             screenAutoBrightnessAdjustmentOverride = other.screenAutoBrightnessAdjustmentOverride;
516             screenLowPowerBrightnessFactor = other.screenLowPowerBrightnessFactor;
517             blockScreenOn = other.blockScreenOn;
518             lowPowerMode = other.lowPowerMode;
519             boostScreenBrightness = other.boostScreenBrightness;
520             dozeScreenBrightness = other.dozeScreenBrightness;
521             dozeScreenState = other.dozeScreenState;
522         }
523 
524         @Override
equals(@ullable Object o)525         public boolean equals(@Nullable Object o) {
526             return o instanceof DisplayPowerRequest
527                     && equals((DisplayPowerRequest)o);
528         }
529 
equals(DisplayPowerRequest other)530         public boolean equals(DisplayPowerRequest other) {
531             return other != null
532                     && policy == other.policy
533                     && useProximitySensor == other.useProximitySensor
534                     && floatEquals(screenBrightnessOverride,
535                             other.screenBrightnessOverride)
536                     && floatEquals(screenAutoBrightnessAdjustmentOverride,
537                             other.screenAutoBrightnessAdjustmentOverride)
538                     && screenLowPowerBrightnessFactor
539                     == other.screenLowPowerBrightnessFactor
540                     && blockScreenOn == other.blockScreenOn
541                     && lowPowerMode == other.lowPowerMode
542                     && boostScreenBrightness == other.boostScreenBrightness
543                     && floatEquals(dozeScreenBrightness, other.dozeScreenBrightness)
544                     && dozeScreenState == other.dozeScreenState;
545         }
546 
floatEquals(float f1, float f2)547         private boolean floatEquals(float f1, float f2) {
548             return f1 == f2 || Float.isNaN(f1) && Float.isNaN(f2);
549         }
550 
551         @Override
hashCode()552         public int hashCode() {
553             return 0; // don't care
554         }
555 
556         @Override
toString()557         public String toString() {
558             return "policy=" + policyToString(policy)
559                     + ", useProximitySensor=" + useProximitySensor
560                     + ", screenBrightnessOverride=" + screenBrightnessOverride
561                     + ", screenAutoBrightnessAdjustmentOverride="
562                     + screenAutoBrightnessAdjustmentOverride
563                     + ", screenLowPowerBrightnessFactor=" + screenLowPowerBrightnessFactor
564                     + ", blockScreenOn=" + blockScreenOn
565                     + ", lowPowerMode=" + lowPowerMode
566                     + ", boostScreenBrightness=" + boostScreenBrightness
567                     + ", dozeScreenBrightness=" + dozeScreenBrightness
568                     + ", dozeScreenState=" + Display.stateToString(dozeScreenState);
569         }
570 
policyToString(int policy)571         public static String policyToString(int policy) {
572             switch (policy) {
573                 case POLICY_OFF:
574                     return "OFF";
575                 case POLICY_DOZE:
576                     return "DOZE";
577                 case POLICY_DIM:
578                     return "DIM";
579                 case POLICY_BRIGHT:
580                     return "BRIGHT";
581                 default:
582                     return Integer.toString(policy);
583             }
584         }
585     }
586 
587     /**
588      * Asynchronous callbacks from the power controller to the power manager service.
589      */
590     public interface DisplayPowerCallbacks {
onStateChanged()591         void onStateChanged();
onProximityPositive()592         void onProximityPositive();
onProximityNegative()593         void onProximityNegative();
onDisplayStateChange(boolean allInactive, boolean allOff)594         void onDisplayStateChange(boolean allInactive, boolean allOff);
595 
596         /**
597          * Acquires a suspend blocker with a specified label.
598          *
599          * @param id A logging label for the acquisition.
600          */
acquireSuspendBlocker(String id)601         void acquireSuspendBlocker(String id);
602 
603         /**
604          * Releases a suspend blocker with a specified label.
605          *
606          * @param id A logging label for the release.
607          */
releaseSuspendBlocker(String id)608         void releaseSuspendBlocker(String id);
609     }
610 
611     /**
612      * Called within a Surface transaction whenever the size or orientation of a
613      * display may have changed.  Provides an opportunity for the client to
614      * update the position of its surfaces as part of the same transaction.
615      */
616     public interface DisplayTransactionListener {
onDisplayTransaction(Transaction t)617         void onDisplayTransaction(Transaction t);
618     }
619 
620     /**
621      * Called when there are changes to {@link com.android.server.display.DisplayGroup
622      * DisplayGroups}.
623      */
624     public interface DisplayGroupListener {
625         /**
626          * A new display group with the provided {@code groupId} was added.
627          *
628          * <ol>
629          *     <li>The {@code groupId} is applied to all appropriate {@link Display displays}.
630          *     <li>This method is called.
631          *     <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners}
632          *     are informed of any corresponding changes.
633          * </ol>
634          */
onDisplayGroupAdded(int groupId)635         void onDisplayGroupAdded(int groupId);
636 
637         /**
638          * The display group with the provided {@code groupId} was removed.
639          *
640          * <ol>
641          *     <li>All affected {@link Display displays} have their group IDs updated appropriately.
642          *     <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners}
643          *     are informed of any corresponding changes.
644          *     <li>This method is called.
645          * </ol>
646          */
onDisplayGroupRemoved(int groupId)647         void onDisplayGroupRemoved(int groupId);
648 
649         /**
650          * The display group with the provided {@code groupId} has changed.
651          *
652          * <ol>
653          *     <li>All affected {@link Display displays} have their group IDs updated appropriately.
654          *     <li>{@link android.hardware.display.DisplayManager.DisplayListener DisplayListeners}
655          *     are informed of any corresponding changes.
656          *     <li>This method is called.
657          * </ol>
658          */
onDisplayGroupChanged(int groupId)659         void onDisplayGroupChanged(int groupId);
660     }
661 
662     /**
663      * Describes a limitation on a display's refresh rate. Includes the allowed refresh rate
664      * range as well as information about when it applies, such as high-brightness-mode.
665      */
666     public static final class RefreshRateLimitation {
667         @RefreshRateLimitType public int type;
668 
669         /** The range the that refresh rate should be limited to. */
670         public RefreshRateRange range;
671 
RefreshRateLimitation(@efreshRateLimitType int type, float min, float max)672         public RefreshRateLimitation(@RefreshRateLimitType int type, float min, float max) {
673             this.type = type;
674             range = new RefreshRateRange(min, max);
675         }
676 
677         @Override
toString()678         public String toString() {
679             return "RefreshRateLimitation(" + type + ": " + range + ")";
680         }
681     }
682 
683     /**
684      * Class to provide Ambient sensor data using the API
685      * {@link DisplayManagerInternal#getAmbientLightSensorData(int)}
686      */
687     public static final class AmbientLightSensorData {
688         public String sensorName;
689         public String sensorType;
690 
AmbientLightSensorData(String name, String type)691         public AmbientLightSensorData(String name, String type) {
692             sensorName = name;
693             sensorType = type;
694         }
695 
696         @Override
toString()697         public String toString() {
698             return "AmbientLightSensorData(" + sensorName + ", " + sensorType + ")";
699         }
700     }
701 }
702