Repository navigation
Expand file tree
/
Copy pathDisplay.java
More file actions
2985 lines (2755 loc) · 108 KB
/
Copy pathDisplay.java
File metadata and controls
2985 lines (2755 loc) · 108 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view;
import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
import static android.Manifest.permission.CONTROL_DISPLAY_BRIGHTNESS;
import static android.hardware.flags.Flags.FLAG_OVERLAYPROPERTIES_CLASS_API;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_GET_SUPPORTED_REFRESH_RATES;
import static com.android.server.display.feature.flags.Flags.FLAG_HIGHEST_HDR_SDR_RATIO_API;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_HAS_ARR_SUPPORT;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_GET_SUGGESTED_FRAME_RATE;
import android.Manifest;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.app.ActivityThread;
import android.app.KeyguardManager;
import android.app.WindowConfiguration;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.ColorSpace;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.OverlayProperties;
import android.hardware.display.BrightnessInfo;
import android.hardware.display.DeviceProductInfo;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerGlobal;
import android.hardware.graphics.common.DisplayDecorationSupport;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.SystemClock;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
/**
* Provides information about the size and density of a logical display.
* <p>
* The display area is described in two different ways.
* <ul>
* <li>The application display area specifies the part of the display that may contain
* an application window, excluding the system decorations. The application display area may
* be smaller than the real display area because the system subtracts the space needed
* for decor elements such as the status bar. Use {@link WindowMetrics#getBounds()} to query the
* application window bounds.</li>
* <li>The real display area specifies the part of the display that is accessible to an application
* in the current system state. The real display area may be smaller than the physical size of the
* display in a few scenarios. Use {@link WindowManager#getCurrentWindowMetrics()} to identify the
* current size of the activity window. UI-related work, such as choosing UI layouts, should rely
* upon {@link WindowMetrics#getBounds()}. See {@link #getRealSize} / {@link #getRealMetrics} for
* details.</li>
* </ul>
* </p><p>
* A logical display does not necessarily represent a particular physical display device
* such as the internal display or an external display. The contents of a logical
* display may be presented on one or more physical displays according to the devices
* that are currently attached and whether mirroring has been enabled.
* </p>
*/
@android.ravenwood.annotation.RavenwoodKeepPartialClass
public final class Display {
private static final String TAG = "Display";
private static final boolean DEBUG = false;
private final Object mLock = new Object();
private final DisplayManagerGlobal mGlobal;
private final int mDisplayId;
private final int mFlags;
private final int mType;
private final int mOwnerUid;
private final String mOwnerPackageName;
private final Resources mResources;
private DisplayAdjustments mDisplayAdjustments;
@UnsupportedAppUsage
private DisplayInfo mDisplayInfo; // never null
private boolean mIsValid;
// Temporary display metrics structure used for compatibility mode.
private final DisplayMetrics mTempMetrics = new DisplayMetrics();
// We cache the app width and height properties briefly between calls
// to getHeight() and getWidth() to ensure that applications perceive
// consistent results when the size changes (most of the time).
// Applications should now be using WindowMetrics instead.
private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
private long mLastCachedAppSizeUpdate;
private int mCachedAppWidthCompat;
private int mCachedAppHeightCompat;
private ArrayList<HdrSdrRatioListenerWrapper> mHdrSdrRatioListeners = new ArrayList<>();
/**
* The default Display id, which is the id of the primary display assuming there is one.
*/
public static final int DEFAULT_DISPLAY = 0;
/**
* Invalid display id.
*/
public static final int INVALID_DISPLAY = -1;
/**
* Invalid resolution width.
* @hide
*/
public static final int INVALID_DISPLAY_WIDTH = -1;
/**
* Invalid resolution height.
* @hide
*/
public static final int INVALID_DISPLAY_HEIGHT = -1;
/**
* Invalid refresh rate.
* @hide
*/
public static final float INVALID_DISPLAY_REFRESH_RATE = 0.0f;
/**
* The default display group id, which is the display group id of the primary display assuming
* there is one.
* @hide
*/
public static final int DEFAULT_DISPLAY_GROUP = 0;
/**
* Invalid display group id.
* @hide
*/
public static final int INVALID_DISPLAY_GROUP = -1;
/**
* Display flag: Indicates that the display supports compositing content
* that is stored in protected graphics buffers.
* <p>
* If this flag is set then the display device supports compositing protected buffers.
* </p><p>
* If this flag is not set then the display device may not support compositing
* protected buffers; the user may see a blank region on the screen instead of
* the protected content.
* </p><p>
* Secure (DRM) video decoders may allocate protected graphics buffers to request that
* a hardware-protected path be provided between the video decoder and the external
* display sink. If a hardware-protected path is not available, then content stored
* in protected graphics buffers may not be composited.
* </p><p>
* An application can use the absence of this flag as a hint that it should not use protected
* buffers for this display because the content may not be visible. For example,
* if the flag is not set then the application may choose not to show content on this
* display, show an informative error message, select an alternate content stream
* or adopt a different strategy for decoding content that does not rely on
* protected buffers.
* </p>
*
* @see #getFlags
*/
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
/**
* Display flag: Indicates that the display has a secure video output and
* supports compositing secure surfaces.
* <p>
* If this flag is set then the display device has a secure video output
* and is capable of showing secure surfaces. It may also be capable of
* showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
* </p><p>
* If this flag is not set then the display device may not have a secure video
* output; the user may see a blank region on the screen instead of
* the contents of secure surfaces or protected buffers.
* </p><p>
* Secure surfaces are used to prevent content rendered into those surfaces
* by applications from appearing in screenshots or from being viewed
* on non-secure displays. Protected buffers are used by secure video decoders
* for a similar purpose.
* </p><p>
* An application creates a window with a secure surface by specifying the
* {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
* Likewise, an application creates a {@link SurfaceView} with a secure surface
* by calling {@link SurfaceView#setSecure} before attaching the secure view to
* its containing window.
* </p><p>
* An application can use the absence of this flag as a hint that it should not create
* secure surfaces or protected buffers on this display because the content may
* not be visible. For example, if the flag is not set then the application may
* choose not to show content on this display, show an informative error message,
* select an alternate content stream or adopt a different strategy for decoding
* content that does not rely on secure surfaces or protected buffers.
* </p>
*
* @see #getFlags
*/
public static final int FLAG_SECURE = 1 << 1;
/**
* Display flag: Indicates that the display is private. Only the application that
* owns the display and apps that are already on the display can create windows on it.
*
* @see #getFlags
*/
public static final int FLAG_PRIVATE = 1 << 2;
/**
* Display flag: Indicates that the display is a presentation display.
* <p>
* This flag identifies secondary displays that are suitable for
* use as presentation displays such as external or wireless displays. Applications
* may automatically project their content to presentation displays to provide
* richer second screen experiences.
* </p>
*
* @see #getFlags
*/
public static final int FLAG_PRESENTATION = 1 << 3;
/**
* Display flag: Indicates that the display has a round shape.
* <p>
* This flag identifies displays that are circular, elliptical or otherwise
* do not permit the user to see all the way to the logical corners of the display.
* </p>
*
* @see #getFlags
*/
public static final int FLAG_ROUND = 1 << 4;
/**
* Display flag: Indicates that the display can show its content when non-secure keyguard is
* shown.
* <p>
* This flag identifies secondary displays that will continue showing content if keyguard can be
* dismissed without entering credentials.
* </p><p>
* An example of usage is a virtual display which content is displayed on external hardware
* display that is not visible to the system directly.
* </p>
*
* @see DisplayManager#VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD
* @see KeyguardManager#isDeviceSecure()
* @see KeyguardManager#isDeviceLocked()
* @see #getFlags
* @hide
*/
// TODO (b/114338689): Remove the flag and use IWindowManager#shouldShowWithInsecureKeyguard
public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
/**
* Display flag: Indicates that the display should show system decorations.
* <p>
* This flag identifies secondary displays that should show system decorations, such as
* navigation bar, home activity or wallpaper.
* </p>
* <p>Note that this flag doesn't work without {@link #FLAG_TRUSTED}</p>
*
* @see #getFlags()
* @hide
*/
public static final int FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 6;
/**
* Flag: The display is trusted to show system decorations and receive inputs without users'
* touch.
* @see #FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
*
* @see #getFlags()
* @hide
*/
@TestApi
public static final int FLAG_TRUSTED = 1 << 7;
/**
* Flag: Indicates that the display should not be a part of the default DisplayGroup and
* instead be part of a new DisplayGroup.
*
* @hide
* @see #getFlags()
*/
public static final int FLAG_OWN_DISPLAY_GROUP = 1 << 8;
/**
* Flag: Indicates that the display should always be unlocked. Only valid on virtual displays
* that aren't in the default display group.
*
* @hide
* @see #getFlags()
*/
@SuppressLint("UnflaggedApi") // Promotion to TestApi
@TestApi
public static final int FLAG_ALWAYS_UNLOCKED = 1 << 9;
/**
* Flag: Indicates that the display should not play sound effects or perform haptic feedback
* when the user touches the screen.
*
* @hide
* @see #getFlags()
*/
@SuppressLint("UnflaggedApi") // Promotion to TestApi
@TestApi
public static final int FLAG_TOUCH_FEEDBACK_DISABLED = 1 << 10;
/**
* Flag: Indicates that the display maintains its own focus and touch mode.
*
* This flag is similar to {@link com.android.internal.R.bool.config_perDisplayFocusEnabled} in
* behavior, but only applies to the specific display instead of system-wide to all displays.
*
* Note: The display must be trusted in order to have its own focus.
*
* @see #FLAG_TRUSTED
* @hide
*/
@SuppressLint("UnflaggedApi") // Promotion to TestApi
@TestApi
public static final int FLAG_OWN_FOCUS = 1 << 11;
/**
* Flag: Indicates that the display should not become the top focused display by stealing the
* top focus from another display.
*
* <p>The result is that only targeted input events (displayId of input event matches the
* displayId of the display) can reach this display. A display with this flag set can still
* become the top focused display, if the system consists of only one display or if all
* displays have this flag set. In both cases the default display becomes the top focused
* display.
*
* <p>Note: A display only has a focused window if either
* - the display is the top focused display or
* - the display manages its own focus (via {@link #FLAG_OWN_FOCUS})
* - or all the displays manage their own focus (via {@code config_perDisplayFocusEnabled} flag)
* If a display has no focused window, no input event is dispatched to it. Therefore this
* flag is only useful together with {@link #FLAG_OWN_FOCUS} and will be
* ignored if it is not set.
*
* <p>Note: The framework only supports IME on the top focused display (b/262520411). Therefore,
* Enabling this flag on a display implicitly disables showing any IME. This is not intended
* behavior but cannot be fixed until b/262520411 is implemented. If you need IME on display do
* not set this flag.
*
* @hide
* @see #getFlags()
*/
public static final int FLAG_STEAL_TOP_FOCUS_DISABLED = 1 << 12;
/**
* Display flag: Indicates that the display is a rear display.
* <p>
* This flag identifies complementary displays that are facing away from the user.
* </p>
*
* @hide
* @see #getFlags()
*/
public static final int FLAG_REAR = 1 << 13;
/**
* Display flag: Indicates that the orientation of this display is not fixed and is coupled to
* the orientation of its content.
*
* @hide
*/
public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 14;
/**
* Display flag: Indicates that the contents of the display should not be scaled
* to fit the physical screen dimensions. Used for development only to emulate
* devices with smaller physicals screens while preserving density.
*
* @hide
*/
public static final int FLAG_SCALING_DISABLED = 1 << 30;
/**
* Display type: Unknown display type.
* @hide
*/
@UnsupportedAppUsage
@TestApi
public static final int TYPE_UNKNOWN = 0;
/**
* Display type: Physical display connected through an internal port.
* @hide
*/
@TestApi
public static final int TYPE_INTERNAL = 1;
/**
* Display type: Physical display connected through an external port.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@TestApi
public static final int TYPE_EXTERNAL = 2;
/**
* Display type: WiFi display.
* @hide
*/
@UnsupportedAppUsage
@TestApi
public static final int TYPE_WIFI = 3;
/**
* Display type: Overlay display.
* @hide
*/
@TestApi
public static final int TYPE_OVERLAY = 4;
/**
* Display type: Virtual display.
* @hide
*/
@UnsupportedAppUsage
@TestApi
public static final int TYPE_VIRTUAL = 5;
/**
* The maximum display type value.
* Helpful to get all possible display values.
* @hide
*/
public static final int TYPE_MAX = TYPE_VIRTUAL;
/**
* Display state: The display state is unknown.
*
* @see #getState
*/
public static final int STATE_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_UNKNOWN; // 0
/**
* Display state: The display is off.
*
* @see #getState
*/
public static final int STATE_OFF = ViewProtoEnums.DISPLAY_STATE_OFF; // 1
/**
* Display state: The display is on.
*
* @see #getState
*/
public static final int STATE_ON = ViewProtoEnums.DISPLAY_STATE_ON; // 2
/**
* Display state: The display is dozing in a low power state; it is still
* on but is optimized for showing system-provided content while the
* device is non-interactive.
*
* @see #getState
* @see android.os.PowerManager#isInteractive
*/
public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3
/**
* Display state: The display is dozing in a suspended low power state; it is still
* on but the CPU is not updating it. This may be used in one of two ways: to show
* static system-provided content while the device is non-interactive, or to allow
* a "Sidekick" compute resource to update the display. For this reason, the
* CPU must not control the display in this mode.
*
* @see #getState
* @see android.os.PowerManager#isInteractive
*/
public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4
/**
* Display state: The display is on and optimized for VR mode.
*
* @see #getState
* @see android.os.PowerManager#isInteractive
*/
public static final int STATE_VR = ViewProtoEnums.DISPLAY_STATE_VR; // 5
/**
* Display state: The display is in a suspended full power state; it is still
* on but the CPU is not updating it. This may be used in one of two ways: to show
* static system-provided content while the device is non-interactive, or to allow
* a "Sidekick" compute resource to update the display. For this reason, the
* CPU must not control the display in this mode.
*
* @see #getState
* @see android.os.PowerManager#isInteractive
*/
public static final int STATE_ON_SUSPEND = ViewProtoEnums.DISPLAY_STATE_ON_SUSPEND; // 6
/**
* The cause of the display state change is unknown.
*
* @hide
*/
public static final int STATE_REASON_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_REASON_UNKNOWN;
/**
* The default power and display policy caused the display state.
*
* @hide
*/
public static final int STATE_REASON_DEFAULT_POLICY =
ViewProtoEnums.DISPLAY_STATE_REASON_DEFAULT_POLICY;
/**
* The display state was changed due to acquiring a draw wake lock.
*
* @hide
*/
public static final int STATE_REASON_DRAW_WAKE_LOCK =
ViewProtoEnums.DISPLAY_STATE_REASON_DRAW_WAKE_LOCK;
/**
* The display state was changed due to display offloading.
*
* @hide
*/
public static final int STATE_REASON_OFFLOAD = ViewProtoEnums.DISPLAY_STATE_REASON_OFFLOAD;
/**
* The display state was changed due to a tilt event.
*
* @hide
*/
public static final int STATE_REASON_TILT = ViewProtoEnums.DISPLAY_STATE_REASON_TILT;
/**
* The display state was changed due to the dream manager.
*
* @hide
*/
public static final int STATE_REASON_DREAM_MANAGER =
ViewProtoEnums.DISPLAY_STATE_REASON_DREAM_MANAGER;
/**
* The display state was changed due to a {@link KeyEvent}.
*
* @hide
*/
public static final int STATE_REASON_KEY = ViewProtoEnums.DISPLAY_STATE_REASON_KEY;
/**
* The display state was changed due to a {@link MotionEvent}.
*
* @hide
*/
public static final int STATE_REASON_MOTION = ViewProtoEnums.DISPLAY_STATE_REASON_MOTION;
/** @hide */
@IntDef(prefix = {"STATE_REASON_"}, value = {
STATE_REASON_UNKNOWN,
STATE_REASON_DEFAULT_POLICY,
STATE_REASON_DRAW_WAKE_LOCK,
STATE_REASON_OFFLOAD,
STATE_REASON_TILT,
STATE_REASON_DREAM_MANAGER,
STATE_REASON_KEY,
STATE_REASON_MOTION,
})
@Retention(RetentionPolicy.SOURCE)
public @interface StateReason {}
/* The color mode constants defined below must be kept in sync with the ones in
* system/core/include/system/graphics-base.h */
/**
* Display color mode: The current color mode is unknown or invalid.
* @hide
*/
public static final int COLOR_MODE_INVALID = -1;
/**
* Display color mode: The default or native gamut of the display.
* @hide
*/
public static final int COLOR_MODE_DEFAULT = 0;
/** @hide */
public static final int COLOR_MODE_BT601_625 = 1;
/** @hide */
public static final int COLOR_MODE_BT601_625_UNADJUSTED = 2;
/** @hide */
public static final int COLOR_MODE_BT601_525 = 3;
/** @hide */
public static final int COLOR_MODE_BT601_525_UNADJUSTED = 4;
/** @hide */
public static final int COLOR_MODE_BT709 = 5;
/** @hide */
public static final int COLOR_MODE_DCI_P3 = 6;
/** @hide */
public static final int COLOR_MODE_SRGB = 7;
/** @hide */
public static final int COLOR_MODE_ADOBE_RGB = 8;
/** @hide */
public static final int COLOR_MODE_DISPLAY_P3 = 9;
/** @hide **/
@IntDef(prefix = {"COLOR_MODE_"}, value = {
COLOR_MODE_INVALID,
COLOR_MODE_DEFAULT,
COLOR_MODE_BT601_625,
COLOR_MODE_BT601_625_UNADJUSTED,
COLOR_MODE_BT601_525,
COLOR_MODE_BT601_525_UNADJUSTED,
COLOR_MODE_BT709,
COLOR_MODE_DCI_P3,
COLOR_MODE_SRGB,
COLOR_MODE_ADOBE_RGB,
COLOR_MODE_DISPLAY_P3
})
@Retention(RetentionPolicy.SOURCE)
public @interface ColorMode {}
/**
* Indicates that when display is removed, all its activities will be moved to the primary
* display and the topmost activity should become focused.
*
* @hide
*/
// TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_MOVE_TO_PRIMARY
public static final int REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY = 0;
/**
* Indicates that when display is removed, all its stacks and tasks will be removed, all
* activities will be destroyed according to the usual lifecycle.
*
* @hide
*/
// TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY
@SuppressLint("UnflaggedApi") // Promotion to TestApi
@TestApi
public static final int REMOVE_MODE_DESTROY_CONTENT = 1;
/** @hide */
public static final int DISPLAY_MODE_ID_FOR_FRAME_RATE_OVERRIDE = 0xFF;
/**
* Internal method to create a display.
* The display created with this method will have a static {@link DisplayAdjustments} applied.
* Applications should use {@link android.content.Context#getDisplay} with
* {@link android.app.Activity} or a context associated with a {@link Display} via
* {@link android.content.Context#createDisplayContext(Display)}
* to get a display object associated with a {@link android.app.Context}, or
* {@link android.hardware.display.DisplayManager#getDisplay} to get a display object by id.
*
* @see android.content.Context#getDisplay()
* @see android.content.Context#createDisplayContext(Display)
* @hide
*/
public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
DisplayAdjustments daj) {
this(global, displayId, displayInfo, daj, null /*res*/);
}
/**
* Internal method to create a display.
* The display created with this method will be adjusted based on the adjustments in the
* supplied {@link Resources}.
*
* @hide
*/
public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
Resources res) {
this(global, displayId, displayInfo, null /*daj*/, res);
}
private Display(DisplayManagerGlobal global, int displayId,
/*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) {
mGlobal = global;
mDisplayId = displayId;
mDisplayInfo = displayInfo;
mResources = res;
mDisplayAdjustments = mResources != null
? new DisplayAdjustments(mResources.getConfiguration())
: daj != null ? new DisplayAdjustments(daj) : new DisplayAdjustments();
mIsValid = true;
// Cache properties that cannot change as long as the display is valid.
mFlags = displayInfo.flags;
mType = displayInfo.type;
mOwnerUid = displayInfo.ownerUid;
mOwnerPackageName = displayInfo.ownerPackageName;
}
/**
* Gets the display id.
* <p>
* Each logical display has a unique id.
* The default display has id {@link #DEFAULT_DISPLAY}.
* </p>
*/
public int getDisplayId() {
return mDisplayId;
}
/**
* Gets the display unique id.
* <p>
* Unique id is different from display id because physical displays have stable unique id across
* reboots.
*
* @see com.android.service.display.DisplayDevice#hasStableUniqueId().
* @hide
*/
@TestApi
public @Nullable String getUniqueId() {
return mDisplayInfo.uniqueId;
}
/**
* Returns true if this display is still valid, false if the display has been removed.
*
* If the display is invalid, then the methods of this class will
* continue to report the most recently observed display information.
* However, it is unwise (and rather fruitless) to continue using a
* {@link Display} object after the display's demise.
*
* It's possible for a display that was previously invalid to become
* valid again if a display with the same id is reconnected.
*
* @return True if the display is still valid.
*/
public boolean isValid() {
synchronized (mLock) {
updateDisplayInfoLocked();
return mIsValid;
}
}
/**
* Gets a full copy of the display information.
*
* @param outDisplayInfo The object to receive the copy of the display information.
* @return True if the display is still valid.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
synchronized (mLock) {
updateDisplayInfoLocked();
outDisplayInfo.copyFrom(mDisplayInfo);
return mIsValid;
}
}
/**
* Gets the display's layer stack.
*
* Each display has its own independent layer stack upon which surfaces
* are placed to be managed by surface flinger.
*
* @return The display's layer stack number.
* @hide
*/
public int getLayerStack() {
synchronized (mLock) {
updateDisplayInfoLocked();
return mDisplayInfo.layerStack;
}
}
/**
* Returns a combination of flags that describe the capabilities of the display.
*
* @return The display flags.
*
* @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
* @see #FLAG_SECURE
* @see #FLAG_PRIVATE
* @see #FLAG_ROUND
*/
public int getFlags() {
return mFlags;
}
/**
* Gets the display type.
*
* @return The display type.
*
* @see #TYPE_UNKNOWN
* @see #TYPE_INTERNAL
* @see #TYPE_EXTERNAL
* @see #TYPE_WIFI
* @see #TYPE_OVERLAY
* @see #TYPE_VIRTUAL
* @hide
*/
@UnsupportedAppUsage
@TestApi
public int getType() {
return mType;
}
/**
* Gets the display address, or null if none.
* Interpretation varies by display type.
*
* @return The display address.
* @hide
*/
public DisplayAddress getAddress() {
synchronized (mLock) {
updateDisplayInfoLocked();
return mDisplayInfo.address;
}
}
/**
* Gets the UID of the application that owns this display, or zero if it is
* owned by the system.
* <p>
* If the display is private, then only the owner can use it.
* </p>
*
* @hide
*/
public int getOwnerUid() {
return mOwnerUid;
}
/**
* Gets the package name of the application that owns this display, or null if it is
* owned by the system.
* <p>
* If the display is private, then only the owner can use it.
* </p>
*
* @hide
*/
@UnsupportedAppUsage
public String getOwnerPackageName() {
return mOwnerPackageName;
}
/**
* Gets the compatibility info used by this display instance.
*
* @return The display adjustments holder, or null if none is required.
* @hide
*/
@UnsupportedAppUsage
public DisplayAdjustments getDisplayAdjustments() {
if (mResources != null) {
final DisplayAdjustments currentAdjustments = mResources.getDisplayAdjustments();
if (!mDisplayAdjustments.equals(currentAdjustments)) {
mDisplayAdjustments = new DisplayAdjustments(currentAdjustments);
}
}
return mDisplayAdjustments;
}
/**
* Gets the name of the display.
* <p>
* Note that some displays may be renamed by the user.
* </p>
*
* @return The display's name.
*/
public String getName() {
synchronized (mLock) {
updateDisplayInfoLocked();
return mDisplayInfo.name;
}
}
/**
* Gets the default brightness configured for the display.
*
* @return Default brightness between 0.0-1.0
* @hide
*/
public float getBrightnessDefault() {
synchronized (mLock) {
updateDisplayInfoLocked();
return mDisplayInfo.brightnessDefault;
}
}
/**
* @return Brightness information about the display.
* @hide
*/
@RequiresPermission(CONTROL_DISPLAY_BRIGHTNESS)
public @Nullable BrightnessInfo getBrightnessInfo() {
return mGlobal.getBrightnessInfo(mDisplayId);
}
/**
* Gets the size of the display in pixels.
*
* <p>The return value does not necessarily represent the actual size (native resolution) of the
* display. The returned size might be adjusted to exclude certain system decor elements that
* are always visible, or the size might be scaled to provide compatibility with older
* applications that were originally designed for smaller displays.
*
* <p>The returned size can also be different depending on the WindowManager bound to the
* display:
* <ul>
* <li>If size is requested from an activity (either using a WindowManager accessed by
* {@code getWindowManager()} or {@code getSystemService(Context.WINDOW_SERVICE)}), the
* size of the current app window is returned. As a result, in multi-window mode, the
* returned size can be smaller than the size of the device screen.
* The returned window size can vary depending on API level:
* <ul>
* <li>API level 35 and above, the window size will be returned.
* <li>API level 34 and below, the window size minus system decoration areas and
* display cutout is returned.
* </ul>
* <li>If size is requested from a non-activity context (for example, the application
* context, where the WindowManager is accessed by
* {@code getApplicationContext().getSystemService(Context.WINDOW_SERVICE)}), the
* returned size can vary depending on API level:
* <ul>
* <li>API level 29 and below — The size of the entire display (based on
* current rotation) minus system decoration areas is returned.
* <li>API level 30 and above — The size of the top running activity in the
* current process is returned, system decoration areas exclusion follows the
* behavior defined above, based on the caller's API level. If the current
* process has no running activities, the size of the device default display,
* including system decoration areas, is returned.
* </ul>
* </ul>
*
* <p>For layout purposes, apps should make a request from an activity context to obtain the
* size of the display area available for app content.
*
* @param outSize A {@link Point} object which receives the display size information.
*
* @deprecated Use {@link WindowMetrics} instead. Obtain a {@code WindowMetrics} instance by
* calling {@link WindowManager#getCurrentWindowMetrics()}, then call
* {@link WindowMetrics#getBounds()} to get the dimensions of the application window.
*/
@Deprecated
public void getSize(Point outSize) {
synchronized (mLock) {
updateDisplayInfoLocked();
mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
outSize.x = mTempMetrics.widthPixels;
outSize.y = mTempMetrics.heightPixels;
}
}
/**
* Gets the size of the display as a rectangle, in pixels.
*
* @param outSize A {@link Rect} object to receive the size information.
*
* @deprecated Use {@link WindowMetrics#getBounds()} to get the dimensions of the application
* window.
*/
@Deprecated
public void getRectSize(Rect outSize) {
synchronized (mLock) {
updateDisplayInfoLocked();
mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
}
}
/**
* Return the range of display sizes an application can expect to encounter
* under normal operation, as long as there is no physical change in screen
* size. This is basically the sizes you will see as the orientation