1 /*
2  * Copyright (C) 2012 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 static android.view.Display.DEFAULT_DISPLAY;
20 import static android.view.Display.HdrCapabilities.HdrType;
21 
22 import android.Manifest;
23 import android.annotation.FloatRange;
24 import android.annotation.IntDef;
25 import android.annotation.LongDef;
26 import android.annotation.NonNull;
27 import android.annotation.Nullable;
28 import android.annotation.RequiresPermission;
29 import android.annotation.SystemApi;
30 import android.annotation.SystemService;
31 import android.annotation.TestApi;
32 import android.app.KeyguardManager;
33 import android.compat.annotation.UnsupportedAppUsage;
34 import android.content.Context;
35 import android.content.res.Resources;
36 import android.graphics.Point;
37 import android.media.projection.MediaProjection;
38 import android.os.Build;
39 import android.os.Handler;
40 import android.util.Pair;
41 import android.util.Slog;
42 import android.util.SparseArray;
43 import android.view.Display;
44 import android.view.Surface;
45 
46 import java.lang.annotation.Retention;
47 import java.lang.annotation.RetentionPolicy;
48 import java.util.ArrayList;
49 import java.util.List;
50 
51 
52 /**
53  * Manages the properties of attached displays.
54  */
55 @SystemService(Context.DISPLAY_SERVICE)
56 public final class DisplayManager {
57     private static final String TAG = "DisplayManager";
58     private static final boolean DEBUG = false;
59 
60     private final Context mContext;
61     private final DisplayManagerGlobal mGlobal;
62 
63     private final Object mLock = new Object();
64     private final SparseArray<Display> mDisplays = new SparseArray<Display>();
65 
66     private final ArrayList<Display> mTempDisplays = new ArrayList<Display>();
67 
68     /**
69      * Broadcast receiver that indicates when the Wifi display status changes.
70      * <p>
71      * The status is provided as a {@link WifiDisplayStatus} object in the
72      * {@link #EXTRA_WIFI_DISPLAY_STATUS} extra.
73      * </p><p>
74      * This broadcast is only sent to registered receivers and can only be sent by the system.
75      * </p>
76      * @hide
77      */
78     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
79     public static final String ACTION_WIFI_DISPLAY_STATUS_CHANGED =
80             "android.hardware.display.action.WIFI_DISPLAY_STATUS_CHANGED";
81 
82     /**
83      * Contains a {@link WifiDisplayStatus} object.
84      * @hide
85      */
86     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
87     public static final String EXTRA_WIFI_DISPLAY_STATUS =
88             "android.hardware.display.extra.WIFI_DISPLAY_STATUS";
89 
90     /**
91      * Display category: Presentation displays.
92      * <p>
93      * This category can be used to identify secondary displays that are suitable for
94      * use as presentation displays such as external or wireless displays.  Applications
95      * may automatically project their content to presentation displays to provide
96      * richer second screen experiences.
97      * </p>
98      *
99      * @see android.app.Presentation
100      * @see Display#FLAG_PRESENTATION
101      * @see #getDisplays(String)
102      */
103     public static final String DISPLAY_CATEGORY_PRESENTATION =
104             "android.hardware.display.category.PRESENTATION";
105 
106     /**
107      * Virtual display flag: Create a public display.
108      *
109      * <h3>Public virtual displays</h3>
110      * <p>
111      * When this flag is set, the virtual display is public.
112      * </p><p>
113      * A public virtual display behaves just like most any other display that is connected
114      * to the system such as an external or wireless display.  Applications can open
115      * windows on the display and the system may mirror the contents of other displays
116      * onto it.
117      * </p><p>
118      * Creating a public virtual display that isn't restricted to own-content only implicitly
119      * creates an auto-mirroring display. See {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} for
120      * restrictions on who is allowed to create an auto-mirroring display.
121      * </p>
122      *
123      * <h3>Private virtual displays</h3>
124      * <p>
125      * When this flag is not set, the virtual display is private as defined by the
126      * {@link Display#FLAG_PRIVATE} display flag.
127      * </p>
128      *
129      * <p>
130      * A private virtual display belongs to the application that created it.  Only the a owner of a
131      * private virtual display and the apps that are already on that display are allowed to place
132      * windows upon it.  The private virtual display also does not participate in display mirroring:
133      * it will neither receive mirrored content from another display nor allow its own content to be
134      * mirrored elsewhere.  More precisely, the only processes that are allowed to enumerate or
135      * interact with the private display are those that have the same UID as the application that
136      * originally created the private virtual display or as the activities that are already on that
137      * display.
138      * </p>
139      *
140      * @see #createVirtualDisplay
141      * @see #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
142      * @see #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
143      */
144     public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1 << 0;
145 
146     /**
147      * Virtual display flag: Create a presentation display.
148      *
149      * <h3>Presentation virtual displays</h3>
150      * <p>
151      * When this flag is set, the virtual display is registered as a presentation
152      * display in the {@link #DISPLAY_CATEGORY_PRESENTATION presentation display category}.
153      * Applications may automatically project their content to presentation displays
154      * to provide richer second screen experiences.
155      * </p>
156      *
157      * <h3>Non-presentation virtual displays</h3>
158      * <p>
159      * When this flag is not set, the virtual display is not registered as a presentation
160      * display.  Applications can still project their content on the display but they
161      * will typically not do so automatically.  This option is appropriate for
162      * more special-purpose displays.
163      * </p>
164      *
165      * @see android.app.Presentation
166      * @see #createVirtualDisplay
167      * @see #DISPLAY_CATEGORY_PRESENTATION
168      * @see Display#FLAG_PRESENTATION
169      */
170     public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 1 << 1;
171 
172     /**
173      * Virtual display flag: Create a secure display.
174      *
175      * <h3>Secure virtual displays</h3>
176      * <p>
177      * When this flag is set, the virtual display is considered secure as defined
178      * by the {@link Display#FLAG_SECURE} display flag.  The caller promises to take
179      * reasonable measures, such as over-the-air encryption, to prevent the contents
180      * of the display from being intercepted or recorded on a persistent medium.
181      * </p><p>
182      * Creating a secure virtual display requires the CAPTURE_SECURE_VIDEO_OUTPUT permission.
183      * This permission is reserved for use by system components and is not available to
184      * third-party applications.
185      * </p>
186      *
187      * <h3>Non-secure virtual displays</h3>
188      * <p>
189      * When this flag is not set, the virtual display is considered unsecure.
190      * The content of secure windows will be blanked if shown on this display.
191      * </p>
192      *
193      * @see Display#FLAG_SECURE
194      * @see #createVirtualDisplay
195      */
196     public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 1 << 2;
197 
198     /**
199      * Virtual display flag: Only show this display's own content; do not mirror
200      * the content of another display.
201      *
202      * <p>
203      * This flag is used in conjunction with {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}.
204      * Ordinarily public virtual displays will automatically mirror the content of the
205      * default display if they have no windows of their own.  When this flag is
206      * specified, the virtual display will only ever show its own content and
207      * will be blanked instead if it has no windows.
208      * </p>
209      *
210      * <p>
211      * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.  If both
212      * flags are specified then the own-content only behavior will be applied.
213      * </p>
214      *
215      * <p>
216      * This behavior of this flag is implied whenever neither {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}
217      * nor {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR} have been set.  This flag is only required to
218      * override the default behavior when creating a public display.
219      * </p>
220      *
221      * @see #createVirtualDisplay
222      */
223     public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 1 << 3;
224 
225 
226     /**
227      * Virtual display flag: Allows content to be mirrored on private displays when no content is
228      * being shown.
229      *
230      * <p>
231      * This flag is mutually exclusive with {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}.
232      * If both flags are specified then the own-content only behavior will be applied.
233      * </p>
234      *
235      * <p>
236      * The behavior of this flag is implied whenever {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC} is set
237      * and {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY} has not been set.   This flag is only
238      * required to override the default behavior when creating a private display.
239      * </p>
240      *
241      * <p>
242      * Creating an auto-mirroing virtual display requires the CAPTURE_VIDEO_OUTPUT
243      * or CAPTURE_SECURE_VIDEO_OUTPUT permission.
244      * These permissions are reserved for use by system components and are not available to
245      * third-party applications.
246      *
247      * Alternatively, an appropriate {@link MediaProjection} may be used to create an
248      * auto-mirroring virtual display.
249      * </p>
250      *
251      * @see #createVirtualDisplay
252      */
253     public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR = 1 << 4;
254 
255     /**
256      * Virtual display flag: Allows content to be displayed on private virtual displays when
257      * keyguard is shown but is insecure.
258      *
259      * <p>
260      * This might be used in a case when the content of a virtual display is captured and sent to an
261      * external hardware display that is not visible to the system directly. This flag will allow
262      * the continued display of content while other displays will be covered by a keyguard which
263      * doesn't require providing credentials to unlock. This means that there is either no password
264      * or other authentication method set, or the device is in a trusted state -
265      * {@link android.service.trust.TrustAgentService} has available and active trust agent.
266      * </p><p>
267      * This flag can only be applied to private displays as defined by the
268      * {@link Display#FLAG_PRIVATE} display flag. It is mutually exclusive with
269      * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}. If both flags are specified then this flag's behavior
270      * will not be applied.
271      * </p>
272      *
273      * @see #createVirtualDisplay
274      * @see KeyguardManager#isDeviceSecure()
275      * @see KeyguardManager#isDeviceLocked()
276      * @hide
277      */
278     // TODO (b/114338689): Remove the flag and use IWindowManager#shouldShowWithInsecureKeyguard
279     // TODO: Update name and documentation and un-hide the flag. Don't change the value before that.
280     public static final int VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
281 
282     /**
283      * Virtual display flag: Specifies that the virtual display can be associated with a
284      * touchpad device that matches its uniqueId.
285      *
286      * @see #createVirtualDisplay
287      * @hide
288      */
289     public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6;
290 
291     /**
292      * Virtual display flag: Indicates that the orientation of this display device is coupled to
293      * the rotation of its associated logical display.
294      *
295      * @see #createVirtualDisplay
296      * @hide
297      */
298     public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 1 << 7;
299 
300     /**
301      * Virtual display flag: Indicates that the contents will be destroyed once
302      * the display is removed.
303      *
304      * Public virtual displays without this flag will move their content to main display
305      * stack once they're removed. Private vistual displays will always destroy their
306      * content on removal even without this flag.
307      *
308      * @see #createVirtualDisplay
309      * @hide
310      */
311     // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY
312     public static final int VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL = 1 << 8;
313 
314     /**
315      * Virtual display flag: Indicates that the display should support system decorations. Virtual
316      * displays without this flag shouldn't show home, IME or any other system decorations.
317      * <p>This flag doesn't work without {@link #VIRTUAL_DISPLAY_FLAG_TRUSTED}</p>
318      *
319      * @see #createVirtualDisplay
320      * @see #VIRTUAL_DISPLAY_FLAG_TRUSTED
321      * @hide
322      */
323     // TODO (b/114338689): Remove the flag and use IWindowManager#setShouldShowSystemDecors
324     @TestApi
325     public static final int VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 9;
326 
327     /**
328      * Virtual display flags: Indicates that the display is trusted to show system decorations and
329      * receive inputs without users' touch.
330      *
331      * @see #createVirtualDisplay
332      * @see #VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
333      * @hide
334      */
335     @TestApi
336     public static final int VIRTUAL_DISPLAY_FLAG_TRUSTED = 1 << 10;
337 
338     /**
339      * Virtual display flags: Indicates that the display should not be a part of the default
340      * DisplayGroup and instead be part of a new DisplayGroup.
341      *
342      * @see #createVirtualDisplay
343      * @hide
344      */
345     public static final int VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP = 1 << 11;
346 
347 
348     /** @hide */
349     @IntDef(prefix = {"MATCH_CONTENT_FRAMERATE_"}, value = {
350             MATCH_CONTENT_FRAMERATE_UNKNOWN,
351             MATCH_CONTENT_FRAMERATE_NEVER,
352             MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY,
353             MATCH_CONTENT_FRAMERATE_ALWAYS,
354     })
355     @Retention(RetentionPolicy.SOURCE)
356     public @interface MatchContentFrameRateType {}
357 
358     /**
359      * Match content frame rate user preference is unknown.
360      */
361     public static final int MATCH_CONTENT_FRAMERATE_UNKNOWN = -1;
362 
363     /**
364      * No mode switching is allowed.
365      */
366     public static final int MATCH_CONTENT_FRAMERATE_NEVER = 0;
367 
368     /**
369      * Only refresh rate switches without visual interruptions are allowed.
370      */
371     public static final int MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY = 1;
372 
373     /**
374      * Refresh rate switches between all refresh rates are allowed even if they have visual
375      * interruptions for the user.
376      */
377     public static final int MATCH_CONTENT_FRAMERATE_ALWAYS = 2;
378 
379     /** @hide */
380     @IntDef(prefix = {"SWITCHING_TYPE_"}, value = {
381             SWITCHING_TYPE_NONE,
382             SWITCHING_TYPE_WITHIN_GROUPS,
383             SWITCHING_TYPE_ACROSS_AND_WITHIN_GROUPS,
384     })
385     @Retention(RetentionPolicy.SOURCE)
386     public @interface SwitchingType {}
387 
388     /**
389      * No mode switching will happen.
390      * @hide
391      */
392     @TestApi
393     public static final int SWITCHING_TYPE_NONE = 0;
394 
395     /**
396      * Allow only refresh rate switching between modes in the same configuration group. This way
397      * only switches without visual interruptions for the user will be allowed.
398      * @hide
399      */
400     @TestApi
401     public static final int SWITCHING_TYPE_WITHIN_GROUPS = 1;
402 
403     /**
404      * Allow refresh rate switching between all refresh rates even if the switch with have visual
405      * interruptions for the user.
406      * @hide
407      */
408     @TestApi
409     public static final int SWITCHING_TYPE_ACROSS_AND_WITHIN_GROUPS = 2;
410 
411     /**
412      * @hide
413      */
414     @LongDef(flag = true, prefix = {"EVENT_FLAG_"}, value = {
415             EVENT_FLAG_DISPLAY_ADDED,
416             EVENT_FLAG_DISPLAY_CHANGED,
417             EVENT_FLAG_DISPLAY_REMOVED,
418             EVENT_FLAG_DISPLAY_BRIGHTNESS
419     })
420     @Retention(RetentionPolicy.SOURCE)
421     public @interface EventsMask {}
422 
423     /**
424      * Event type for when a new display is added.
425      *
426      * @see #registerDisplayListener(DisplayListener, Handler, long)
427      *
428      * @hide
429      */
430     public static final long EVENT_FLAG_DISPLAY_ADDED = 1L << 0;
431 
432     /**
433      * Event type for when a display is removed.
434      *
435      * @see #registerDisplayListener(DisplayListener, Handler, long)
436      *
437      * @hide
438      */
439     public static final long EVENT_FLAG_DISPLAY_REMOVED = 1L << 1;
440 
441     /**
442      * Event type for when a display is changed.
443      *
444      * @see #registerDisplayListener(DisplayListener, Handler, long)
445      *
446      * @hide
447      */
448     public static final long EVENT_FLAG_DISPLAY_CHANGED = 1L << 2;
449 
450     /**
451      * Event flag to register for a display's brightness changes. This notification is sent
452      * through the {@link DisplayListener#onDisplayChanged} callback method. New brightness
453      * values can be retrieved via {@link android.view.Display#getBrightnessInfo()}.
454      *
455      * @see #registerDisplayListener(DisplayListener, Handler, long)
456      *
457      * @hide
458      */
459     public static final long EVENT_FLAG_DISPLAY_BRIGHTNESS = 1L << 3;
460 
461     /** @hide */
DisplayManager(Context context)462     public DisplayManager(Context context) {
463         mContext = context;
464         mGlobal = DisplayManagerGlobal.getInstance();
465     }
466 
467     /**
468      * Gets information about a logical display.
469      *
470      * The display metrics may be adjusted to provide compatibility
471      * for legacy applications.
472      *
473      * @param displayId The logical display id.
474      * @return The display object, or null if there is no valid display with the given id.
475      */
getDisplay(int displayId)476     public Display getDisplay(int displayId) {
477         synchronized (mLock) {
478             return getOrCreateDisplayLocked(displayId, false /*assumeValid*/);
479         }
480     }
481 
482     /**
483      * Gets all currently valid logical displays.
484      *
485      * @return An array containing all displays.
486      */
getDisplays()487     public Display[] getDisplays() {
488         return getDisplays(null);
489     }
490 
491     /**
492      * Gets all currently valid logical displays of the specified category.
493      * <p>
494      * When there are multiple displays in a category the returned displays are sorted
495      * of preference.  For example, if the requested category is
496      * {@link #DISPLAY_CATEGORY_PRESENTATION} and there are multiple presentation displays
497      * then the displays are sorted so that the first display in the returned array
498      * is the most preferred presentation display.  The application may simply
499      * use the first display or allow the user to choose.
500      * </p>
501      *
502      * @param category The requested display category or null to return all displays.
503      * @return An array containing all displays sorted by order of preference.
504      *
505      * @see #DISPLAY_CATEGORY_PRESENTATION
506      */
getDisplays(String category)507     public Display[] getDisplays(String category) {
508         final int[] displayIds = mGlobal.getDisplayIds();
509         synchronized (mLock) {
510             try {
511                 if (category == null) {
512                     addAllDisplaysLocked(mTempDisplays, displayIds);
513                 } else if (category.equals(DISPLAY_CATEGORY_PRESENTATION)) {
514                     addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_WIFI);
515                     addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_EXTERNAL);
516                     addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_OVERLAY);
517                     addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_VIRTUAL);
518                     addPresentationDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_INTERNAL);
519                 }
520                 return mTempDisplays.toArray(new Display[mTempDisplays.size()]);
521             } finally {
522                 mTempDisplays.clear();
523             }
524         }
525     }
526 
addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds)527     private void addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds) {
528         for (int i = 0; i < displayIds.length; i++) {
529             Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/);
530             if (display != null) {
531                 displays.add(display);
532             }
533         }
534     }
535 
addPresentationDisplaysLocked( ArrayList<Display> displays, int[] displayIds, int matchType)536     private void addPresentationDisplaysLocked(
537             ArrayList<Display> displays, int[] displayIds, int matchType) {
538         for (int i = 0; i < displayIds.length; i++) {
539             if (displayIds[i] == DEFAULT_DISPLAY) {
540                 continue;
541             }
542             Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/);
543             if (display != null
544                     && (display.getFlags() & Display.FLAG_PRESENTATION) != 0
545                     && display.getType() == matchType) {
546                 displays.add(display);
547             }
548         }
549     }
550 
getOrCreateDisplayLocked(int displayId, boolean assumeValid)551     private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) {
552         Display display = mDisplays.get(displayId);
553         if (display == null) {
554             // TODO: We cannot currently provide any override configurations for metrics on displays
555             // other than the display the context is associated with.
556             final Resources resources = mContext.getDisplayId() == displayId
557                     ? mContext.getResources() : null;
558 
559             display = mGlobal.getCompatibleDisplay(displayId, resources);
560             if (display != null) {
561                 mDisplays.put(displayId, display);
562             }
563         } else if (!assumeValid && !display.isValid()) {
564             display = null;
565         }
566         return display;
567     }
568 
569     /**
570      * Registers a display listener to receive notifications about when
571      * displays are added, removed or changed.
572      *
573      * @param listener The listener to register.
574      * @param handler The handler on which the listener should be invoked, or null
575      * if the listener should be invoked on the calling thread's looper.
576      *
577      * @see #unregisterDisplayListener
578      */
registerDisplayListener(DisplayListener listener, Handler handler)579     public void registerDisplayListener(DisplayListener listener, Handler handler) {
580         registerDisplayListener(listener, handler, EVENT_FLAG_DISPLAY_ADDED
581                 | EVENT_FLAG_DISPLAY_CHANGED | EVENT_FLAG_DISPLAY_REMOVED);
582     }
583 
584     /**
585      * Registers a display listener to receive notifications about given display event types.
586      *
587      * @param listener The listener to register.
588      * @param handler The handler on which the listener should be invoked, or null
589      * if the listener should be invoked on the calling thread's looper.
590      * @param eventsMask A bitmask of the event types for which this listener is subscribed.
591      *
592      * @see #EVENT_FLAG_DISPLAY_ADDED
593      * @see #EVENT_FLAG_DISPLAY_CHANGED
594      * @see #EVENT_FLAG_DISPLAY_REMOVED
595      * @see #EVENT_FLAG_DISPLAY_BRIGHTNESS
596      * @see #registerDisplayListener(DisplayListener, Handler)
597      * @see #unregisterDisplayListener
598      *
599      * @hide
600      */
registerDisplayListener(@onNull DisplayListener listener, @Nullable Handler handler, @EventsMask long eventsMask)601     public void registerDisplayListener(@NonNull DisplayListener listener,
602             @Nullable Handler handler, @EventsMask long eventsMask) {
603         mGlobal.registerDisplayListener(listener, handler, eventsMask);
604     }
605 
606     /**
607      * Unregisters a display listener.
608      *
609      * @param listener The listener to unregister.
610      *
611      * @see #registerDisplayListener
612      */
unregisterDisplayListener(DisplayListener listener)613     public void unregisterDisplayListener(DisplayListener listener) {
614         mGlobal.unregisterDisplayListener(listener);
615     }
616 
617     /**
618      * Starts scanning for available Wifi displays.
619      * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
620      * <p>
621      * Calls to this method nest and must be matched by an equal number of calls to
622      * {@link #stopWifiDisplayScan()}.
623      * </p><p>
624      * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
625      * </p>
626      *
627      * @hide
628      */
629     @UnsupportedAppUsage
startWifiDisplayScan()630     public void startWifiDisplayScan() {
631         mGlobal.startWifiDisplayScan();
632     }
633 
634     /**
635      * Stops scanning for available Wifi displays.
636      * <p>
637      * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
638      * </p>
639      *
640      * @hide
641      */
642     @UnsupportedAppUsage
stopWifiDisplayScan()643     public void stopWifiDisplayScan() {
644         mGlobal.stopWifiDisplayScan();
645     }
646 
647     /**
648      * Connects to a Wifi display.
649      * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
650      * <p>
651      * Automatically remembers the display after a successful connection, if not
652      * already remembered.
653      * </p><p>
654      * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
655      * </p>
656      *
657      * @param deviceAddress The MAC address of the device to which we should connect.
658      * @hide
659      */
660     @UnsupportedAppUsage
connectWifiDisplay(String deviceAddress)661     public void connectWifiDisplay(String deviceAddress) {
662         mGlobal.connectWifiDisplay(deviceAddress);
663     }
664 
665     /** @hide */
666     @UnsupportedAppUsage
pauseWifiDisplay()667     public void pauseWifiDisplay() {
668         mGlobal.pauseWifiDisplay();
669     }
670 
671     /** @hide */
672     @UnsupportedAppUsage
resumeWifiDisplay()673     public void resumeWifiDisplay() {
674         mGlobal.resumeWifiDisplay();
675     }
676 
677     /**
678      * Disconnects from the current Wifi display.
679      * The results are sent as a {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED} broadcast.
680      * @hide
681      */
682     @UnsupportedAppUsage
disconnectWifiDisplay()683     public void disconnectWifiDisplay() {
684         mGlobal.disconnectWifiDisplay();
685     }
686 
687     /**
688      * Renames a Wifi display.
689      * <p>
690      * The display must already be remembered for this call to succeed.  In other words,
691      * we must already have successfully connected to the display at least once and then
692      * not forgotten it.
693      * </p><p>
694      * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
695      * </p>
696      *
697      * @param deviceAddress The MAC address of the device to rename.
698      * @param alias The alias name by which to remember the device, or null
699      * or empty if no alias should be used.
700      * @hide
701      */
702     @UnsupportedAppUsage
renameWifiDisplay(String deviceAddress, String alias)703     public void renameWifiDisplay(String deviceAddress, String alias) {
704         mGlobal.renameWifiDisplay(deviceAddress, alias);
705     }
706 
707     /**
708      * Forgets a previously remembered Wifi display.
709      * <p>
710      * Automatically disconnects from the display if currently connected to it.
711      * </p><p>
712      * Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
713      * </p>
714      *
715      * @param deviceAddress The MAC address of the device to forget.
716      * @hide
717      */
718     @UnsupportedAppUsage
forgetWifiDisplay(String deviceAddress)719     public void forgetWifiDisplay(String deviceAddress) {
720         mGlobal.forgetWifiDisplay(deviceAddress);
721     }
722 
723     /**
724      * Gets the current Wifi display status.
725      * Watch for changes in the status by registering a broadcast receiver for
726      * {@link #ACTION_WIFI_DISPLAY_STATUS_CHANGED}.
727      *
728      * @return The current Wifi display status.
729      * @hide
730      */
731     @UnsupportedAppUsage
getWifiDisplayStatus()732     public WifiDisplayStatus getWifiDisplayStatus() {
733         return mGlobal.getWifiDisplayStatus();
734     }
735 
736     /**
737      * Set the level of color saturation to apply to the display.
738      * @param level The amount of saturation to apply, between 0 and 1 inclusive.
739      * 0 produces a grayscale image, 1 is normal.
740      *
741      * @hide
742      * @deprecated use {@link ColorDisplayManager#setSaturationLevel(int)} instead. The level passed
743      * as a parameter here will be rounded to the nearest hundredth.
744      */
745     @SystemApi
746     @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_SATURATION)
setSaturationLevel(float level)747     public void setSaturationLevel(float level) {
748         if (level < 0f || level > 1f) {
749             throw new IllegalArgumentException("Saturation level must be between 0 and 1");
750         }
751         final ColorDisplayManager cdm = mContext.getSystemService(ColorDisplayManager.class);
752         cdm.setSaturationLevel(Math.round(level * 100f));
753     }
754 
755     /**
756      * Sets the HDR types that have been disabled by user.
757      * @param userDisabledTypes the HDR types to disable.
758      * @hide
759      */
760     @TestApi
761     @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
setUserDisabledHdrTypes(@onNull @drType int[] userDisabledTypes)762     public void setUserDisabledHdrTypes(@NonNull @HdrType int[] userDisabledTypes) {
763         mGlobal.setUserDisabledHdrTypes(userDisabledTypes);
764     }
765 
766     /**
767      * Sets whether or not the user disabled HDR types are returned from
768      * {@link Display#getHdrCapabilities}.
769      *
770      * @param areUserDisabledHdrTypesAllowed If true, the user-disabled types
771      * are ignored and returned, if the display supports them. If false, the
772      * user-disabled types are taken into consideration and are never returned,
773      * even if the display supports them.
774      * @hide
775      */
776     @TestApi
777     @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
setAreUserDisabledHdrTypesAllowed(boolean areUserDisabledHdrTypesAllowed)778     public void setAreUserDisabledHdrTypesAllowed(boolean areUserDisabledHdrTypesAllowed) {
779         mGlobal.setAreUserDisabledHdrTypesAllowed(areUserDisabledHdrTypesAllowed);
780     }
781 
782     /**
783      * Returns whether or not the user-disabled HDR types are returned from
784      * {@link Display#getHdrCapabilities}.
785      *
786      * @hide
787      */
788     @TestApi
areUserDisabledHdrTypesAllowed()789     public boolean areUserDisabledHdrTypesAllowed() {
790         return mGlobal.areUserDisabledHdrTypesAllowed();
791     }
792 
793     /**
794      * Returns the HDR formats disabled by the user.
795      *
796      * @hide
797      */
798     @TestApi
getUserDisabledHdrTypes()799     public @NonNull int[] getUserDisabledHdrTypes() {
800         return mGlobal.getUserDisabledHdrTypes();
801     }
802 
803 
804     /**
805      * Creates a virtual display.
806      *
807      * @see #createVirtualDisplay(String, int, int, int, Surface, int,
808      * VirtualDisplay.Callback, Handler)
809      */
createVirtualDisplay(@onNull String name, int width, int height, int densityDpi, @Nullable Surface surface, int flags)810     public VirtualDisplay createVirtualDisplay(@NonNull String name,
811             int width, int height, int densityDpi, @Nullable Surface surface, int flags) {
812         return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null);
813     }
814 
815     /**
816      * Creates a virtual display.
817      * <p>
818      * The content of a virtual display is rendered to a {@link Surface} provided
819      * by the application.
820      * </p><p>
821      * The virtual display should be {@link VirtualDisplay#release released}
822      * when no longer needed.  Because a virtual display renders to a surface
823      * provided by the application, it will be released automatically when the
824      * process terminates and all remaining windows on it will be forcibly removed.
825      * </p><p>
826      * The behavior of the virtual display depends on the flags that are provided
827      * to this method.  By default, virtual displays are created to be private,
828      * non-presentation and unsecure.  Permissions may be required to use certain flags.
829      * </p><p>
830      * As of {@link android.os.Build.VERSION_CODES#KITKAT_WATCH}, the surface may
831      * be attached or detached dynamically using {@link VirtualDisplay#setSurface}.
832      * Previously, the surface had to be non-null when {@link #createVirtualDisplay}
833      * was called and could not be changed for the lifetime of the display.
834      * </p><p>
835      * Detaching the surface that backs a virtual display has a similar effect to
836      * turning off the screen.
837      * </p>
838      *
839      * @param name The name of the virtual display, must be non-empty.
840      * @param width The width of the virtual display in pixels, must be greater than 0.
841      * @param height The height of the virtual display in pixels, must be greater than 0.
842      * @param densityDpi The density of the virtual display in dpi, must be greater than 0.
843      * @param surface The surface to which the content of the virtual display should
844      * be rendered, or null if there is none initially.
845      * @param flags A combination of virtual display flags:
846      * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION},
847      * {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
848      * or {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
849      * @param callback Callback to call when the state of the {@link VirtualDisplay} changes
850      * @param handler The handler on which the listener should be invoked, or null
851      * if the listener should be invoked on the calling thread's looper.
852      * @return The newly created virtual display, or null if the application could
853      * not create the virtual display.
854      *
855      * @throws SecurityException if the caller does not have permission to create
856      * a virtual display with the specified flags.
857      */
createVirtualDisplay(@onNull String name, int width, int height, int densityDpi, @Nullable Surface surface, int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler)858     public VirtualDisplay createVirtualDisplay(@NonNull String name,
859             int width, int height, int densityDpi, @Nullable Surface surface, int flags,
860             @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
861         final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(name, width,
862                 height, densityDpi);
863         builder.setFlags(flags);
864         if (surface != null) {
865             builder.setSurface(surface);
866         }
867         return createVirtualDisplay(null /* projection */, builder.build(), callback, handler,
868                 null /* windowContext */);
869     }
870 
871     // TODO : Remove this hidden API after remove all callers. (Refer to MultiDisplayService)
872     /** @hide */
createVirtualDisplay(@ullable MediaProjection projection, @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface, int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler, @Nullable String uniqueId)873     public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection,
874             @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface,
875             int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler,
876             @Nullable String uniqueId) {
877         final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(name, width,
878                 height, densityDpi);
879         builder.setFlags(flags);
880         if (uniqueId != null) {
881             builder.setUniqueId(uniqueId);
882         }
883         if (surface != null) {
884             builder.setSurface(surface);
885         }
886         return createVirtualDisplay(projection, builder.build(), callback, handler,
887                 null /* windowContext */);
888     }
889 
890     /** @hide */
createVirtualDisplay(@ullable MediaProjection projection, @NonNull VirtualDisplayConfig virtualDisplayConfig, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler, @Nullable Context windowContext)891     public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection,
892             @NonNull VirtualDisplayConfig virtualDisplayConfig,
893             @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler,
894             @Nullable Context windowContext) {
895         return mGlobal.createVirtualDisplay(mContext, projection, virtualDisplayConfig, callback,
896                 handler, windowContext);
897     }
898 
899     /**
900      * Gets the stable device display size, in pixels.
901      *
902      * This should really only be used for things like server-side filtering of available
903      * applications. Most applications don't need the level of stability guaranteed by this and
904      * should instead query either the size of the display they're currently running on or the
905      * size of the default display.
906      * @hide
907      */
908     @SystemApi
getStableDisplaySize()909     public Point getStableDisplaySize() {
910         return mGlobal.getStableDisplaySize();
911     }
912 
913     /**
914      * Fetch {@link BrightnessChangeEvent}s.
915      * @hide until we make it a system api.
916      */
917     @SystemApi
918     @RequiresPermission(Manifest.permission.BRIGHTNESS_SLIDER_USAGE)
getBrightnessEvents()919     public List<BrightnessChangeEvent> getBrightnessEvents() {
920         return mGlobal.getBrightnessEvents(mContext.getOpPackageName());
921     }
922 
923     /**
924      * Fetch {@link AmbientBrightnessDayStats}s.
925      *
926      * @hide until we make it a system api
927      */
928     @SystemApi
929     @RequiresPermission(Manifest.permission.ACCESS_AMBIENT_LIGHT_STATS)
getAmbientBrightnessStats()930     public List<AmbientBrightnessDayStats> getAmbientBrightnessStats() {
931         return mGlobal.getAmbientBrightnessStats();
932     }
933 
934     /**
935      * Sets the global display brightness configuration.
936      *
937      * @hide
938      */
939     @SystemApi
940     @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
setBrightnessConfiguration(BrightnessConfiguration c)941     public void setBrightnessConfiguration(BrightnessConfiguration c) {
942         setBrightnessConfigurationForUser(c, mContext.getUserId(), mContext.getPackageName());
943     }
944 
945     /**
946      * Sets the brightness configuration for the specified display.
947      * If the specified display doesn't exist, then this will return and do nothing.
948      *
949      * @hide
950      */
951     @SystemApi
952     @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
setBrightnessConfigurationForDisplay(@onNull BrightnessConfiguration c, @NonNull String uniqueId)953     public void setBrightnessConfigurationForDisplay(@NonNull BrightnessConfiguration c,
954             @NonNull String uniqueId) {
955         mGlobal.setBrightnessConfigurationForDisplay(c, uniqueId, mContext.getUserId(),
956                 mContext.getPackageName());
957     }
958 
959     /**
960      * Gets the brightness configuration for the specified display and default user.
961      * Returns the default configuration if unset or display is invalid.
962      *
963      * @hide
964      */
965     @Nullable
966     @SystemApi
967     @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
getBrightnessConfigurationForDisplay( @onNull String uniqueId)968     public BrightnessConfiguration getBrightnessConfigurationForDisplay(
969             @NonNull String uniqueId) {
970         return mGlobal.getBrightnessConfigurationForDisplay(uniqueId, mContext.getUserId());
971     }
972 
973     /**
974      * Sets the global display brightness configuration for a specific user.
975      *
976      * Note this requires the INTERACT_ACROSS_USERS permission if setting the configuration for a
977      * user other than the one you're currently running as.
978      *
979      * @hide
980      */
setBrightnessConfigurationForUser(BrightnessConfiguration c, int userId, String packageName)981     public void setBrightnessConfigurationForUser(BrightnessConfiguration c, int userId,
982             String packageName) {
983         mGlobal.setBrightnessConfigurationForUser(c, userId, packageName);
984     }
985 
986     /**
987      * Gets the global display brightness configuration or the default curve if one hasn't been set.
988      *
989      * @hide
990      */
991     @SystemApi
992     @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
getBrightnessConfiguration()993     public BrightnessConfiguration getBrightnessConfiguration() {
994         return getBrightnessConfigurationForUser(mContext.getUserId());
995     }
996 
997     /**
998      * Gets the global display brightness configuration or the default curve if one hasn't been set
999      * for a specific user.
1000      *
1001      * Note this requires the INTERACT_ACROSS_USERS permission if getting the configuration for a
1002      * user other than the one you're currently running as.
1003      *
1004      * @hide
1005      */
getBrightnessConfigurationForUser(int userId)1006     public BrightnessConfiguration getBrightnessConfigurationForUser(int userId) {
1007         return mGlobal.getBrightnessConfigurationForUser(userId);
1008     }
1009 
1010     /**
1011      * Gets the default global display brightness configuration or null one hasn't
1012      * been configured.
1013      *
1014      * @hide
1015      */
1016     @SystemApi
1017     @RequiresPermission(Manifest.permission.CONFIGURE_DISPLAY_BRIGHTNESS)
1018     @Nullable
getDefaultBrightnessConfiguration()1019     public BrightnessConfiguration getDefaultBrightnessConfiguration() {
1020         return mGlobal.getDefaultBrightnessConfiguration();
1021     }
1022 
1023 
1024     /**
1025      * Gets the last requested minimal post processing setting for the display with displayId.
1026      *
1027      * @hide
1028      */
1029     @TestApi
isMinimalPostProcessingRequested(int displayId)1030     public boolean isMinimalPostProcessingRequested(int displayId) {
1031         return mGlobal.isMinimalPostProcessingRequested(displayId);
1032     }
1033 
1034     /**
1035      * Temporarily sets the brightness of the display.
1036      * <p>
1037      * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS} permission.
1038      * </p>
1039      *
1040      * @param brightness The brightness value from 0.0f to 1.0f.
1041      *
1042      * @hide Requires signature permission.
1043      */
setTemporaryBrightness(int displayId, float brightness)1044     public void setTemporaryBrightness(int displayId, float brightness) {
1045         mGlobal.setTemporaryBrightness(displayId, brightness);
1046     }
1047 
1048 
1049     /**
1050      * Sets the brightness of the specified display.
1051      * <p>
1052      * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS}
1053      * permission.
1054      * </p>
1055      *
1056      * @param displayId the logical display id
1057      * @param brightness The brightness value from 0.0f to 1.0f.
1058      *
1059      * @hide
1060      */
1061     @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS)
setBrightness(int displayId, @FloatRange(from = 0f, to = 1f) float brightness)1062     public void setBrightness(int displayId, @FloatRange(from = 0f, to = 1f) float brightness) {
1063         mGlobal.setBrightness(displayId, brightness);
1064     }
1065 
1066 
1067     /**
1068      * Gets the brightness of the specified display.
1069      * <p>
1070      * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS}
1071      * permission.
1072      * </p>
1073      *
1074      * @param displayId The display of which brightness value to get from.
1075      *
1076      * @hide
1077      */
1078     @RequiresPermission(Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS)
1079     @FloatRange(from = 0f, to = 1f)
getBrightness(int displayId)1080     public float getBrightness(int displayId) {
1081         return mGlobal.getBrightness(displayId);
1082     }
1083 
1084 
1085     /**
1086      * Temporarily sets the auto brightness adjustment factor.
1087      * <p>
1088      * Requires the {@link android.Manifest.permission#CONTROL_DISPLAY_BRIGHTNESS} permission.
1089      * </p>
1090      *
1091      * @param adjustment The adjustment factor from -1.0 to 1.0.
1092      *
1093      * @hide Requires signature permission.
1094      */
setTemporaryAutoBrightnessAdjustment(float adjustment)1095     public void setTemporaryAutoBrightnessAdjustment(float adjustment) {
1096         mGlobal.setTemporaryAutoBrightnessAdjustment(adjustment);
1097     }
1098 
1099     /**
1100      * Returns the minimum brightness curve, which guarantess that any brightness curve that dips
1101      * below it is rejected by the system.
1102      * This prevent auto-brightness from setting the screen so dark as to prevent the user from
1103      * resetting or disabling it, and maps lux to the absolute minimum nits that are still readable
1104      * in that ambient brightness.
1105      *
1106      * @return The minimum brightness curve (as lux values and their corresponding nits values).
1107      *
1108      * @hide
1109      */
1110     @SystemApi
getMinimumBrightnessCurve()1111     public Pair<float[], float[]> getMinimumBrightnessCurve() {
1112         return mGlobal.getMinimumBrightnessCurve();
1113     }
1114 
1115     /**
1116      * When enabled the app requested mode is always selected regardless of user settings and
1117      * policies for low brightness, low battery, etc.
1118      *
1119      * @hide
1120      */
1121     @TestApi
1122     @RequiresPermission(Manifest.permission.OVERRIDE_DISPLAY_MODE_REQUESTS)
setShouldAlwaysRespectAppRequestedMode(boolean enabled)1123     public void setShouldAlwaysRespectAppRequestedMode(boolean enabled) {
1124         mGlobal.setShouldAlwaysRespectAppRequestedMode(enabled);
1125     }
1126 
1127     /**
1128      * Returns whether we are running in a mode which always selects the app requested display mode
1129      * and ignores user settings and policies for low brightness, low battery etc.
1130      *
1131      * @hide
1132      */
1133     @TestApi
1134     @RequiresPermission(Manifest.permission.OVERRIDE_DISPLAY_MODE_REQUESTS)
shouldAlwaysRespectAppRequestedMode()1135     public boolean shouldAlwaysRespectAppRequestedMode() {
1136         return mGlobal.shouldAlwaysRespectAppRequestedMode();
1137     }
1138 
1139     /**
1140      * Sets the refresh rate switching type.
1141      * This matches {@link android.provider.Settings.Secure.MATCH_CONTENT_FRAME_RATE}
1142      *
1143      * @hide
1144      */
1145     @TestApi
1146     @RequiresPermission(Manifest.permission.MODIFY_REFRESH_RATE_SWITCHING_TYPE)
setRefreshRateSwitchingType(@witchingType int newValue)1147     public void setRefreshRateSwitchingType(@SwitchingType int newValue) {
1148         mGlobal.setRefreshRateSwitchingType(newValue);
1149     }
1150 
1151     /**
1152      * Returns the user preference for "Match content frame rate".
1153      * <p>
1154      * Never: Even if the app requests it, the device will never try to match its output to the
1155      * original frame rate of the content.
1156      * </p><p>
1157      * Seamless: If the app requests it, the device will match its output to the original frame
1158      * rate of the content, ONLY if the display can transition seamlessly.
1159      * </p><p>
1160      * Always: If the app requests it, the device will match its output to the original
1161      * frame rate of the content. This may cause the screen to go blank for a
1162      * second when exiting or entering a video playback.
1163      * </p>
1164      */
getMatchContentFrameRateUserPreference()1165     @MatchContentFrameRateType public int getMatchContentFrameRateUserPreference() {
1166         return toMatchContentFrameRateSetting(mGlobal.getRefreshRateSwitchingType());
1167     }
1168 
1169     @MatchContentFrameRateType
toMatchContentFrameRateSetting(@witchingType int switchingType)1170     private int toMatchContentFrameRateSetting(@SwitchingType int switchingType) {
1171         switch (switchingType) {
1172             case SWITCHING_TYPE_NONE:
1173                 return MATCH_CONTENT_FRAMERATE_NEVER;
1174             case SWITCHING_TYPE_WITHIN_GROUPS:
1175                 return MATCH_CONTENT_FRAMERATE_SEAMLESSS_ONLY;
1176             case SWITCHING_TYPE_ACROSS_AND_WITHIN_GROUPS:
1177                 return MATCH_CONTENT_FRAMERATE_ALWAYS;
1178             default:
1179                 Slog.e(TAG, switchingType + " is not a valid value of switching type.");
1180                 return MATCH_CONTENT_FRAMERATE_UNKNOWN;
1181         }
1182     }
1183 
1184     /**
1185      * Listens for changes in available display devices.
1186      */
1187     public interface DisplayListener {
1188         /**
1189          * Called whenever a logical display has been added to the system.
1190          * Use {@link DisplayManager#getDisplay} to get more information about
1191          * the display.
1192          *
1193          * @param displayId The id of the logical display that was added.
1194          */
onDisplayAdded(int displayId)1195         void onDisplayAdded(int displayId);
1196 
1197         /**
1198          * Called whenever a logical display has been removed from the system.
1199          *
1200          * @param displayId The id of the logical display that was removed.
1201          */
onDisplayRemoved(int displayId)1202         void onDisplayRemoved(int displayId);
1203 
1204         /**
1205          * Called whenever the properties of a logical {@link android.view.Display},
1206          * such as size and density, have changed.
1207          *
1208          * @param displayId The id of the logical display that changed.
1209          */
onDisplayChanged(int displayId)1210         void onDisplayChanged(int displayId);
1211     }
1212 
1213     /**
1214      * Interface for accessing keys belonging to {@link
1215      * android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER}.
1216      * @hide
1217      */
1218     public interface DeviceConfig {
1219 
1220         /**
1221          * Key for refresh rate in the low zone defined by thresholds.
1222          *
1223          * Note that the name and value don't match because they were added before we had a high
1224          * zone to consider.
1225          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1226          * @see android.R.integer#config_defaultZoneBehavior
1227          */
1228         String KEY_REFRESH_RATE_IN_LOW_ZONE = "refresh_rate_in_zone";
1229 
1230         /**
1231          * Key for accessing the low display brightness thresholds for the configured refresh
1232          * rate zone.
1233          * The value will be a pair of comma separated integers representing the minimum and maximum
1234          * thresholds of the zone, respectively, in display backlight units (i.e. [0, 255]).
1235          *
1236          * Note that the name and value don't match because they were added before we had a high
1237          * zone to consider.
1238          *
1239          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1240          * @see android.R.array#config_brightnessThresholdsOfPeakRefreshRate
1241          * @hide
1242          */
1243         String KEY_FIXED_REFRESH_RATE_LOW_DISPLAY_BRIGHTNESS_THRESHOLDS =
1244                 "peak_refresh_rate_brightness_thresholds";
1245 
1246         /**
1247          * Key for accessing the low ambient brightness thresholds for the configured refresh
1248          * rate zone. The value will be a pair of comma separated integers representing the minimum
1249          * and maximum thresholds of the zone, respectively, in lux.
1250          *
1251          * Note that the name and value don't match because they were added before we had a high
1252          * zone to consider.
1253          *
1254          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1255          * @see android.R.array#config_ambientThresholdsOfPeakRefreshRate
1256          * @hide
1257          */
1258         String KEY_FIXED_REFRESH_RATE_LOW_AMBIENT_BRIGHTNESS_THRESHOLDS =
1259                 "peak_refresh_rate_ambient_thresholds";
1260         /**
1261          * Key for refresh rate in the high zone defined by thresholds.
1262          *
1263          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1264          * @see android.R.integer#config_fixedRefreshRateInHighZone
1265          */
1266         String KEY_REFRESH_RATE_IN_HIGH_ZONE = "refresh_rate_in_high_zone";
1267 
1268         /**
1269          * Key for accessing the display brightness thresholds for the configured refresh rate zone.
1270          * The value will be a pair of comma separated integers representing the minimum and maximum
1271          * thresholds of the zone, respectively, in display backlight units (i.e. [0, 255]).
1272          *
1273          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1274          * @see android.R.array#config_brightnessHighThresholdsOfFixedRefreshRate
1275          * @hide
1276          */
1277         String KEY_FIXED_REFRESH_RATE_HIGH_DISPLAY_BRIGHTNESS_THRESHOLDS =
1278                 "fixed_refresh_rate_high_display_brightness_thresholds";
1279 
1280         /**
1281          * Key for accessing the ambient brightness thresholds for the configured refresh rate zone.
1282          * The value will be a pair of comma separated integers representing the minimum and maximum
1283          * thresholds of the zone, respectively, in lux.
1284          *
1285          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1286          * @see android.R.array#config_ambientHighThresholdsOfFixedRefreshRate
1287          * @hide
1288          */
1289         String KEY_FIXED_REFRESH_RATE_HIGH_AMBIENT_BRIGHTNESS_THRESHOLDS =
1290                 "fixed_refresh_rate_high_ambient_brightness_thresholds";
1291 
1292         /**
1293          * Key for refresh rate when the device is in high brightness mode for sunlight visility.
1294          *
1295          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1296          * @see android.R.integer#config_defaultRefreshRateInHbmSunlight
1297          */
1298         String KEY_REFRESH_RATE_IN_HBM_SUNLIGHT = "refresh_rate_in_hbm_sunlight";
1299 
1300         /**
1301          * Key for refresh rate when the device is in high brightness mode for HDR.
1302          *
1303          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1304          * @see android.R.integer#config_defaultRefreshRateInHbmHdr
1305          */
1306         String KEY_REFRESH_RATE_IN_HBM_HDR = "refresh_rate_in_hbm_hdr";
1307 
1308         /**
1309          * Key for default peak refresh rate
1310          *
1311          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1312          * @see android.R.integer#config_defaultPeakRefreshRate
1313          * @hide
1314          */
1315         String KEY_PEAK_REFRESH_RATE_DEFAULT = "peak_refresh_rate_default";
1316 
1317         // TODO(b/162536543): rename it once it is proved not harmful for users.
1318         /**
1319          * Key for controlling which packages are explicitly blocked from running at refresh rates
1320          * higher than 60hz. An app may be added to this list if they exhibit performance issues at
1321          * higher refresh rates.
1322          *
1323          * @see android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER
1324          * @see android.R.array#config_highRefreshRateBlacklist
1325          * @hide
1326          */
1327         String KEY_HIGH_REFRESH_RATE_BLACKLIST = "high_refresh_rate_blacklist";
1328     }
1329 }
1330