Debian Codegraph @

core/java/android/view/DisplayInfo.java

raw symbols SCIP
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.view;
18
19 import static android.view.DisplayInfoProto.APP_HEIGHT;
20 import static android.view.DisplayInfoProto.APP_WIDTH;
21 import static android.view.DisplayInfoProto.FLAGS;
22 import static android.view.DisplayInfoProto.LOGICAL_HEIGHT;
23 import static android.view.DisplayInfoProto.LOGICAL_WIDTH;
24 import static android.view.DisplayInfoProto.NAME;
25
26 import android.annotation.Nullable;
27 import android.app.WindowConfiguration;
28 import android.compat.annotation.UnsupportedAppUsage;
29 import android.content.res.CompatibilityInfo;
30 import android.content.res.Configuration;
31 import android.graphics.Rect;
32 import android.hardware.display.DeviceProductInfo;
33 import android.os.Build;
34 import android.os.Parcel;
35 import android.os.Parcelable;
36 import android.os.Process;
37 import android.util.ArraySet;
38 import android.util.DisplayMetrics;
39 import android.util.proto.ProtoOutputStream;
40
41 import java.util.Arrays;
42 import java.util.Objects;
43
44 /**
45 * Describes the characteristics of a particular logical display.
46 * @hide
47 */
48 public final class DisplayInfo implements Parcelable {
49 /**
50 * The surface flinger layer stack associated with this logical display.
51 */
52 public int layerStack;
53
54 /**
55 * Display flags.
56 */
57 public int flags;
58
59 /**
60 * Display type.
61 */
62 public int type;
63
64 /**
65 * Logical display identifier.
66 */
67 public int displayId;
68
69 /**
70 * Display Group identifier.
71 */
72 public int displayGroupId;
73
74 /**
75 * Display address, or null if none.
76 * Interpretation varies by display type.
77 */
78 public DisplayAddress address;
79
80 /**
81 * Product-specific information about the display or the directly connected device on the
82 * display chain. For example, if the display is transitively connected, this field may contain
83 * product information about the intermediate device.
84 */
85 public DeviceProductInfo deviceProductInfo;
86
87 /**
88 * The human-readable name of the display.
89 */
90 public String name;
91
92 /**
93 * Unique identifier for the display. Shouldn't be displayed to the user.
94 */
95 public String uniqueId;
96
97 /**
98 * The width of the portion of the display that is available to applications, in pixels.
99 * Represents the size of the display minus any system decorations.
100 */
101 public int appWidth;
102
103 /**
104 * The height of the portion of the display that is available to applications, in pixels.
105 * Represents the size of the display minus any system decorations.
106 */
107 public int appHeight;
108
109 /**
110 * The smallest value of {@link #appWidth} that an application is likely to encounter,
111 * in pixels, excepting cases where the width may be even smaller due to the presence
112 * of a soft keyboard, for example.
113 */
114 public int smallestNominalAppWidth;
115
116 /**
117 * The smallest value of {@link #appHeight} that an application is likely to encounter,
118 * in pixels, excepting cases where the height may be even smaller due to the presence
119 * of a soft keyboard, for example.
120 */
121 public int smallestNominalAppHeight;
122
123 /**
124 * The largest value of {@link #appWidth} that an application is likely to encounter,
125 * in pixels, excepting cases where the width may be even larger due to system decorations
126 * such as the status bar being hidden, for example.
127 */
128 public int largestNominalAppWidth;
129
130 /**
131 * The largest value of {@link #appHeight} that an application is likely to encounter,
132 * in pixels, excepting cases where the height may be even larger due to system decorations
133 * such as the status bar being hidden, for example.
134 */
135 public int largestNominalAppHeight;
136
137 /**
138 * The logical width of the display, in pixels.
139 * Represents the usable size of the display which may be smaller than the
140 * physical size when the system is emulating a smaller display.
141 */
142 @UnsupportedAppUsage
143 public int logicalWidth;
144
145 /**
146 * The logical height of the display, in pixels.
147 * Represents the usable size of the display which may be smaller than the
148 * physical size when the system is emulating a smaller display.
149 */
150 @UnsupportedAppUsage
151 public int logicalHeight;
152
153 /**
154 * The {@link DisplayCutout} if present, otherwise {@code null}.
155 *
156 * @hide
157 */
158 // Remark on @UnsupportedAppUsage: Display.getCutout should be used instead
159 @Nullable
160 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
161 public DisplayCutout displayCutout;
162
163 /**
164 * The rotation of the display relative to its natural orientation.
165 * May be one of {@link android.view.Surface#ROTATION_0},
166 * {@link android.view.Surface#ROTATION_90}, {@link android.view.Surface#ROTATION_180},
167 * {@link android.view.Surface#ROTATION_270}.
168 * <p>
169 * The value of this field is indeterminate if the logical display is presented on
170 * more than one physical display.
171 * </p>
172 */
173 @Surface.Rotation
174 @UnsupportedAppUsage
175 public int rotation;
176
177 /**
178 * The active display mode.
179 */
180 public int modeId;
181
182 /**
183 * The default display mode.
184 */
185 public int defaultModeId;
186
187 /**
188 * The supported modes of this display.
189 */
190 public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY;
191
192 /** The active color mode. */
193 public int colorMode;
194
195 /** The list of supported color modes */
196 public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT };
197
198 /** The display's HDR capabilities */
199 public Display.HdrCapabilities hdrCapabilities;
200
201 /** The formats disabled by user **/
202 public int[] userDisabledHdrTypes = {};
203
204 /**
205 * Indicates whether the display can be switched into a mode with minimal post
206 * processing.
207 *
208 * @see android.view.Display#isMinimalPostProcessingSupported
209 */
210 public boolean minimalPostProcessingSupported;
211
212 /**
213 * The logical display density which is the basis for density-independent
214 * pixels.
215 */
216 public int logicalDensityDpi;
217
218 /**
219 * The exact physical pixels per inch of the screen in the X dimension.
220 * <p>
221 * The value of this field is indeterminate if the logical display is presented on
222 * more than one physical display.
223 * </p>
224 */
225 public float physicalXDpi;
226
227 /**
228 * The exact physical pixels per inch of the screen in the Y dimension.
229 * <p>
230 * The value of this field is indeterminate if the logical display is presented on
231 * more than one physical display.
232 * </p>
233 */
234 public float physicalYDpi;
235
236 /**
237 * This is a positive value indicating the phase offset of the VSYNC events provided by
238 * Choreographer relative to the display refresh. For example, if Choreographer reports
239 * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos).
240 */
241 public long appVsyncOffsetNanos;
242
243 /**
244 * This is how far in advance a buffer must be queued for presentation at
245 * a given time. If you want a buffer to appear on the screen at
246 * time N, you must submit the buffer before (N - bufferDeadlineNanos).
247 */
248 public long presentationDeadlineNanos;
249
250 /**
251 * The state of the display, such as {@link android.view.Display#STATE_ON}.
252 */
253 public int state;
254
255 /**
256 * The UID of the application that owns this display, or zero if it is owned by the system.
257 * <p>
258 * If the display is private, then only the owner can use it.
259 * </p>
260 */
261 public int ownerUid;
262
263 /**
264 * The package name of the application that owns this display, or null if it is
265 * owned by the system.
266 * <p>
267 * If the display is private, then only the owner can use it.
268 * </p>
269 */
270 public String ownerPackageName;
271
272 /**
273 * The refresh rate override for this app. 0 means no override.
274 */
275 public float refreshRateOverride;
276
277 /**
278 * @hide
279 * Get current remove mode of the display - what actions should be performed with the display's
280 * content when it is removed.
281 *
282 * @see Display#getRemoveMode()
283 */
284 // TODO (b/114338689): Remove the flag and use IWindowManager#getRemoveContentMode
285 public int removeMode = Display.REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY;
286
287 /**
288 * @hide
289 * The current minimum brightness constraint of the display. Value between 0.0 and 1.0,
290 * derived from the config constraints of the display device of this logical display.
291 */
292 public float brightnessMinimum;
293
294 /**
295 * @hide
296 * The current maximum brightness constraint of the display. Value between 0.0 and 1.0,
297 * derived from the config constraints of the display device of this logical display.
298 */
299 public float brightnessMaximum;
300
301 /**
302 * @hide
303 * The current default brightness of the display. Value between 0.0 and 1.0,
304 * derived from the configuration of the display device of this logical display.
305 */
306 public float brightnessDefault;
307
308 /**
309 * The {@link RoundedCorners} if present, otherwise {@code null}.
310 */
311 @Nullable
312 public RoundedCorners roundedCorners;
313
314 /**
315 * Install orientation of the display relative to its natural orientation.
316 */
317 @Surface.Rotation
318 public int installOrientation;
319
320 public static final @android.annotation.NonNull Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
321 @Override
322 public DisplayInfo createFromParcel(Parcel source) {
323 return new DisplayInfo(source);
324 }
325
326 @Override
327 public DisplayInfo[] newArray(int size) {
328 return new DisplayInfo[size];
329 }
330 };
331
332 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769467)
333 public DisplayInfo() {
334 }
335
336 public DisplayInfo(DisplayInfo other) {
337 copyFrom(other);
338 }
339
340 private DisplayInfo(Parcel source) {
341 readFromParcel(source);
342 }
343
344 @Override
345 public boolean equals(@Nullable Object o) {
346 return o instanceof DisplayInfo && equals((DisplayInfo)o);
347 }
348
349 public boolean equals(DisplayInfo other) {
350 return other != null
351 && layerStack == other.layerStack
352 && flags == other.flags
353 && type == other.type
354 && displayId == other.displayId
355 && displayGroupId == other.displayGroupId
356 && Objects.equals(address, other.address)
357 && Objects.equals(deviceProductInfo, other.deviceProductInfo)
358 && Objects.equals(uniqueId, other.uniqueId)
359 && appWidth == other.appWidth
360 && appHeight == other.appHeight
361 && smallestNominalAppWidth == other.smallestNominalAppWidth
362 && smallestNominalAppHeight == other.smallestNominalAppHeight
363 && largestNominalAppWidth == other.largestNominalAppWidth
364 && largestNominalAppHeight == other.largestNominalAppHeight
365 && logicalWidth == other.logicalWidth
366 && logicalHeight == other.logicalHeight
367 && Objects.equals(displayCutout, other.displayCutout)
368 && rotation == other.rotation
369 && modeId == other.modeId
370 && defaultModeId == other.defaultModeId
371 && Arrays.equals(supportedModes, other.supportedModes)
372 && colorMode == other.colorMode
373 && Arrays.equals(supportedColorModes, other.supportedColorModes)
374 && Objects.equals(hdrCapabilities, other.hdrCapabilities)
375 && Arrays.equals(userDisabledHdrTypes, other.userDisabledHdrTypes)
376 && minimalPostProcessingSupported == other.minimalPostProcessingSupported
377 && logicalDensityDpi == other.logicalDensityDpi
378 && physicalXDpi == other.physicalXDpi
379 && physicalYDpi == other.physicalYDpi
380 && appVsyncOffsetNanos == other.appVsyncOffsetNanos
381 && presentationDeadlineNanos == other.presentationDeadlineNanos
382 && state == other.state
383 && ownerUid == other.ownerUid
384 && Objects.equals(ownerPackageName, other.ownerPackageName)
385 && removeMode == other.removeMode
386 && getRefreshRate() == other.getRefreshRate()
387 && brightnessMinimum == other.brightnessMinimum
388 && brightnessMaximum == other.brightnessMaximum
389 && brightnessDefault == other.brightnessDefault
390 && Objects.equals(roundedCorners, other.roundedCorners)
391 && installOrientation == other.installOrientation;
392 }
393
394 @Override
395 public int hashCode() {
396 return 0; // don't care
397 }
398
399 public void copyFrom(DisplayInfo other) {
400 layerStack = other.layerStack;
401 flags = other.flags;
402 type = other.type;
403 displayId = other.displayId;
404 displayGroupId = other.displayGroupId;
405 address = other.address;
406 deviceProductInfo = other.deviceProductInfo;
407 name = other.name;
408 uniqueId = other.uniqueId;
409 appWidth = other.appWidth;
410 appHeight = other.appHeight;
411 smallestNominalAppWidth = other.smallestNominalAppWidth;
412 smallestNominalAppHeight = other.smallestNominalAppHeight;
413 largestNominalAppWidth = other.largestNominalAppWidth;
414 largestNominalAppHeight = other.largestNominalAppHeight;
415 logicalWidth = other.logicalWidth;
416 logicalHeight = other.logicalHeight;
417 displayCutout = other.displayCutout;
418 rotation = other.rotation;
419 modeId = other.modeId;
420 defaultModeId = other.defaultModeId;
421 supportedModes = Arrays.copyOf(other.supportedModes, other.supportedModes.length);
422 colorMode = other.colorMode;
423 supportedColorModes = Arrays.copyOf(
424 other.supportedColorModes, other.supportedColorModes.length);
425 hdrCapabilities = other.hdrCapabilities;
426 userDisabledHdrTypes = other.userDisabledHdrTypes;
427 minimalPostProcessingSupported = other.minimalPostProcessingSupported;
428 logicalDensityDpi = other.logicalDensityDpi;
429 physicalXDpi = other.physicalXDpi;
430 physicalYDpi = other.physicalYDpi;
431 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
432 presentationDeadlineNanos = other.presentationDeadlineNanos;
433 state = other.state;
434 ownerUid = other.ownerUid;
435 ownerPackageName = other.ownerPackageName;
436 removeMode = other.removeMode;
437 refreshRateOverride = other.refreshRateOverride;
438 brightnessMinimum = other.brightnessMinimum;
439 brightnessMaximum = other.brightnessMaximum;
440 brightnessDefault = other.brightnessDefault;
441 roundedCorners = other.roundedCorners;
442 installOrientation = other.installOrientation;
443 }
444
445 public void readFromParcel(Parcel source) {
446 layerStack = source.readInt();
447 flags = source.readInt();
448 type = source.readInt();
449 displayId = source.readInt();
450 displayGroupId = source.readInt();
451 address = source.readParcelable(null, android.view.DisplayAddress.class);
452 deviceProductInfo = source.readParcelable(null, android.hardware.display.DeviceProductInfo.class);
453 name = source.readString8();
454 appWidth = source.readInt();
455 appHeight = source.readInt();
456 smallestNominalAppWidth = source.readInt();
457 smallestNominalAppHeight = source.readInt();
458 largestNominalAppWidth = source.readInt();
459 largestNominalAppHeight = source.readInt();
460 logicalWidth = source.readInt();
461 logicalHeight = source.readInt();
462 displayCutout = DisplayCutout.ParcelableWrapper.readCutoutFromParcel(source);
463 rotation = source.readInt();
464 modeId = source.readInt();
465 defaultModeId = source.readInt();
466 int nModes = source.readInt();
467 supportedModes = new Display.Mode[nModes];
468 for (int i = 0; i < nModes; i++) {
469 supportedModes[i] = Display.Mode.CREATOR.createFromParcel(source);
470 }
471 colorMode = source.readInt();
472 int nColorModes = source.readInt();
473 supportedColorModes = new int[nColorModes];
474 for (int i = 0; i < nColorModes; i++) {
475 supportedColorModes[i] = source.readInt();
476 }
477 hdrCapabilities = source.readParcelable(null, android.view.Display.HdrCapabilities.class);
478 minimalPostProcessingSupported = source.readBoolean();
479 logicalDensityDpi = source.readInt();
480 physicalXDpi = source.readFloat();
481 physicalYDpi = source.readFloat();
482 appVsyncOffsetNanos = source.readLong();
483 presentationDeadlineNanos = source.readLong();
484 state = source.readInt();
485 ownerUid = source.readInt();
486 ownerPackageName = source.readString8();
487 uniqueId = source.readString8();
488 removeMode = source.readInt();
489 refreshRateOverride = source.readFloat();
490 brightnessMinimum = source.readFloat();
491 brightnessMaximum = source.readFloat();
492 brightnessDefault = source.readFloat();
493 roundedCorners = source.readTypedObject(RoundedCorners.CREATOR);
494 int numUserDisabledFormats = source.readInt();
495 userDisabledHdrTypes = new int[numUserDisabledFormats];
496 for (int i = 0; i < numUserDisabledFormats; i++) {
497 userDisabledHdrTypes[i] = source.readInt();
498 }
499 installOrientation = source.readInt();
500 }
501
502 @Override
503 public void writeToParcel(Parcel dest, int flags) {
504 dest.writeInt(layerStack);
505 dest.writeInt(this.flags);
506 dest.writeInt(type);
507 dest.writeInt(displayId);
508 dest.writeInt(displayGroupId);
509 dest.writeParcelable(address, flags);
510 dest.writeParcelable(deviceProductInfo, flags);
511 dest.writeString8(name);
512 dest.writeInt(appWidth);
513 dest.writeInt(appHeight);
514 dest.writeInt(smallestNominalAppWidth);
515 dest.writeInt(smallestNominalAppHeight);
516 dest.writeInt(largestNominalAppWidth);
517 dest.writeInt(largestNominalAppHeight);
518 dest.writeInt(logicalWidth);
519 dest.writeInt(logicalHeight);
520 DisplayCutout.ParcelableWrapper.writeCutoutToParcel(displayCutout, dest, flags);
521 dest.writeInt(rotation);
522 dest.writeInt(modeId);
523 dest.writeInt(defaultModeId);
524 dest.writeInt(supportedModes.length);
525 for (int i = 0; i < supportedModes.length; i++) {
526 supportedModes[i].writeToParcel(dest, flags);
527 }
528 dest.writeInt(colorMode);
529 dest.writeInt(supportedColorModes.length);
530 for (int i = 0; i < supportedColorModes.length; i++) {
531 dest.writeInt(supportedColorModes[i]);
532 }
533 dest.writeParcelable(hdrCapabilities, flags);
534 dest.writeBoolean(minimalPostProcessingSupported);
535 dest.writeInt(logicalDensityDpi);
536 dest.writeFloat(physicalXDpi);
537 dest.writeFloat(physicalYDpi);
538 dest.writeLong(appVsyncOffsetNanos);
539 dest.writeLong(presentationDeadlineNanos);
540 dest.writeInt(state);
541 dest.writeInt(ownerUid);
542 dest.writeString8(ownerPackageName);
543 dest.writeString8(uniqueId);
544 dest.writeInt(removeMode);
545 dest.writeFloat(refreshRateOverride);
546 dest.writeFloat(brightnessMinimum);
547 dest.writeFloat(brightnessMaximum);
548 dest.writeFloat(brightnessDefault);
549 dest.writeTypedObject(roundedCorners, flags);
550 dest.writeInt(userDisabledHdrTypes.length);
551 for (int i = 0; i < userDisabledHdrTypes.length; i++) {
552 dest.writeInt(userDisabledHdrTypes[i]);
553 }
554 dest.writeInt(installOrientation);
555 }
556
557 @Override
558 public int describeContents() {
559 return 0;
560 }
561
562 /**
563 * Returns the refresh rate the application would experience.
564 */
565 public float getRefreshRate() {
566 if (refreshRateOverride > 0) {
567 return refreshRateOverride;
568 }
569
570 return getMode().getRefreshRate();
571 }
572
573 public Display.Mode getMode() {
574 return findMode(modeId);
575 }
576
577 public Display.Mode getDefaultMode() {
578 return findMode(defaultModeId);
579 }
580
581 private Display.Mode findMode(int id) {
582 for (int i = 0; i < supportedModes.length; i++) {
583 if (supportedModes[i].getModeId() == id) {
584 return supportedModes[i];
585 }
586 }
587 throw new IllegalStateException("Unable to locate mode " + id);
588 }
589
590 /**
591 * Returns the id of the "default" mode with the given refresh rate, or {@code 0} if no suitable
592 * mode could be found.
593 */
594 @Nullable
595 public Display.Mode findDefaultModeByRefreshRate(float refreshRate) {
596 Display.Mode[] modes = supportedModes;
597 Display.Mode defaultMode = getDefaultMode();
598 for (int i = 0; i < modes.length; i++) {
599 if (modes[i].matches(
600 defaultMode.getPhysicalWidth(), defaultMode.getPhysicalHeight(), refreshRate)) {
601 return modes[i];
602 }
603 }
604 return null;
605 }
606
607 /**
608 * Returns the list of supported refresh rates in the default mode.
609 */
610 public float[] getDefaultRefreshRates() {
611 Display.Mode[] modes = supportedModes;
612 ArraySet<Float> rates = new ArraySet<>();
613 Display.Mode defaultMode = getDefaultMode();
614 for (int i = 0; i < modes.length; i++) {
615 Display.Mode mode = modes[i];
616 if (mode.getPhysicalWidth() == defaultMode.getPhysicalWidth()
617 && mode.getPhysicalHeight() == defaultMode.getPhysicalHeight()) {
618 rates.add(mode.getRefreshRate());
619 }
620 }
621 float[] result = new float[rates.size()];
622 int i = 0;
623 for (Float rate : rates) {
624 result[i++] = rate;
625 }
626 return result;
627 }
628
629 public void getAppMetrics(DisplayMetrics outMetrics) {
630 getAppMetrics(outMetrics, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
631 }
632
633 public void getAppMetrics(DisplayMetrics outMetrics, DisplayAdjustments displayAdjustments) {
634 getMetricsWithSize(outMetrics, displayAdjustments.getCompatibilityInfo(),
635 displayAdjustments.getConfiguration(), appWidth, appHeight);
636 }
637
638 public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfo ci,
639 Configuration configuration) {
640 getMetricsWithSize(outMetrics, ci, configuration, appWidth, appHeight);
641 }
642
643 /**
644 * Populates {@code outMetrics} with details of the logical display. Bounds are limited
645 * by the logical size of the display.
646 *
647 * @param outMetrics the {@link DisplayMetrics} to be populated
648 * @param compatInfo the {@link CompatibilityInfo} to be applied
649 * @param configuration the {@link Configuration}
650 */
651 public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo,
652 Configuration configuration) {
653 getMetricsWithSize(outMetrics, compatInfo, configuration, logicalWidth, logicalHeight);
654 }
655
656 /**
657 * Similar to {@link #getLogicalMetrics}, but the limiting bounds are determined from
658 * {@link WindowConfiguration#getMaxBounds()}
659 */
660 public void getMaxBoundsMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo,
661 Configuration configuration) {
662 Rect bounds = configuration.windowConfiguration.getMaxBounds();
663 // Pass in null configuration to ensure width and height are not overridden to app bounds.
664 getMetricsWithSize(outMetrics, compatInfo, /* configuration= */ null,
665 bounds.width(), bounds.height());
666 }
667
668 public int getNaturalWidth() {
669 return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ?
670 logicalWidth : logicalHeight;
671 }
672
673 public int getNaturalHeight() {
674 return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ?
675 logicalHeight : logicalWidth;
676 }
677
678 public boolean isHdr() {
679 int[] types = hdrCapabilities != null ? hdrCapabilities.getSupportedHdrTypes() : null;
680 return types != null && types.length > 0;
681 }
682
683 public boolean isWideColorGamut() {
684 for (int colorMode : supportedColorModes) {
685 if (colorMode == Display.COLOR_MODE_DCI_P3 || colorMode > Display.COLOR_MODE_SRGB) {
686 return true;
687 }
688 }
689 return false;
690 }
691
692 /**
693 * Returns true if the specified UID has access to this display.
694 */
695 public boolean hasAccess(int uid) {
696 return Display.hasAccess(uid, flags, ownerUid, displayId);
697 }
698
699 private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfo compatInfo,
700 Configuration configuration, int width, int height) {
701 outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi;
702 outMetrics.density = outMetrics.noncompatDensity =
703 logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
704 outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density;
705 outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi;
706 outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi;
707
708 final Rect appBounds = configuration != null
709 ? configuration.windowConfiguration.getAppBounds() : null;
710 width = appBounds != null ? appBounds.width() : width;
711 height = appBounds != null ? appBounds.height() : height;
712
713 outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width;
714 outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height;
715
716 if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) {
717 compatInfo.applyToDisplayMetrics(outMetrics);
718 }
719 }
720
721 // For debugging purposes
722 @Override
723 public String toString() {
724 StringBuilder sb = new StringBuilder();
725 sb.append("DisplayInfo{\"");
726 sb.append(name);
727 sb.append("\", displayId ");
728 sb.append(displayId);
729 sb.append("\", displayGroupId ");
730 sb.append(displayGroupId);
731 sb.append(flagsToString(flags));
732 sb.append(", real ");
733 sb.append(logicalWidth);
734 sb.append(" x ");
735 sb.append(logicalHeight);
736 sb.append(", largest app ");
737 sb.append(largestNominalAppWidth);
738 sb.append(" x ");
739 sb.append(largestNominalAppHeight);
740 sb.append(", smallest app ");
741 sb.append(smallestNominalAppWidth);
742 sb.append(" x ");
743 sb.append(smallestNominalAppHeight);
744 sb.append(", appVsyncOff ");
745 sb.append(appVsyncOffsetNanos);
746 sb.append(", presDeadline ");
747 sb.append(presentationDeadlineNanos);
748 sb.append(", mode ");
749 sb.append(modeId);
750 sb.append(", defaultMode ");
751 sb.append(defaultModeId);
752 sb.append(", modes ");
753 sb.append(Arrays.toString(supportedModes));
754 sb.append(", hdrCapabilities ");
755 sb.append(hdrCapabilities);
756 sb.append(", userDisabledHdrTypes ");
757 sb.append(Arrays.toString(userDisabledHdrTypes));
758 sb.append(", minimalPostProcessingSupported ");
759 sb.append(minimalPostProcessingSupported);
760 sb.append(", rotation ");
761 sb.append(rotation);
762 sb.append(", state ");
763 sb.append(Display.stateToString(state));
764
765 if (Process.myUid() != Process.SYSTEM_UID) {
766 sb.append("}");
767 return sb.toString();
768 }
769
770 sb.append(", type ");
771 sb.append(Display.typeToString(type));
772 sb.append(", uniqueId \"");
773 sb.append(uniqueId);
774 sb.append("\", app ");
775 sb.append(appWidth);
776 sb.append(" x ");
777 sb.append(appHeight);
778 sb.append(", density ");
779 sb.append(logicalDensityDpi);
780 sb.append(" (");
781 sb.append(physicalXDpi);
782 sb.append(" x ");
783 sb.append(physicalYDpi);
784 sb.append(") dpi, layerStack ");
785 sb.append(layerStack);
786 sb.append(", colorMode ");
787 sb.append(colorMode);
788 sb.append(", supportedColorModes ");
789 sb.append(Arrays.toString(supportedColorModes));
790 if (address != null) {
791 sb.append(", address ").append(address);
792 }
793 sb.append(", deviceProductInfo ");
794 sb.append(deviceProductInfo);
795 if (ownerUid != 0 || ownerPackageName != null) {
796 sb.append(", owner ").append(ownerPackageName);
797 sb.append(" (uid ").append(ownerUid).append(")");
798 }
799 sb.append(", removeMode ");
800 sb.append(removeMode);
801 sb.append(", refreshRateOverride ");
802 sb.append(refreshRateOverride);
803 sb.append(", brightnessMinimum ");
804 sb.append(brightnessMinimum);
805 sb.append(", brightnessMaximum ");
806 sb.append(brightnessMaximum);
807 sb.append(", brightnessDefault ");
808 sb.append(brightnessDefault);
809 sb.append(", installOrientation ");
810 sb.append(Surface.rotationToString(installOrientation));
811 sb.append("}");
812 return sb.toString();
813 }
814
815 /**
816 * Write to a protocol buffer output stream.
817 * Protocol buffer message definition at {@link android.view.DisplayInfoProto}
818 *
819 * @param protoOutputStream Stream to write the Rect object to.
820 * @param fieldId Field Id of the DisplayInfoProto as defined in the parent message
821 */
822 public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId) {
823 final long token = protoOutputStream.start(fieldId);
824 protoOutputStream.write(LOGICAL_WIDTH, logicalWidth);
825 protoOutputStream.write(LOGICAL_HEIGHT, logicalHeight);
826 protoOutputStream.write(APP_WIDTH, appWidth);
827 protoOutputStream.write(APP_HEIGHT, appHeight);
828 protoOutputStream.write(NAME, name);
829 protoOutputStream.write(FLAGS, flags);
830 protoOutputStream.end(token);
831 }
832
833 private static String flagsToString(int flags) {
834 StringBuilder result = new StringBuilder();
835 if ((flags & Display.FLAG_SECURE) != 0) {
836 result.append(", FLAG_SECURE");
837 }
838 if ((flags & Display.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
839 result.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
840 }
841 if ((flags & Display.FLAG_PRIVATE) != 0) {
842 result.append(", FLAG_PRIVATE");
843 }
844 if ((flags & Display.FLAG_PRESENTATION) != 0) {
845 result.append(", FLAG_PRESENTATION");
846 }
847 if ((flags & Display.FLAG_SCALING_DISABLED) != 0) {
848 result.append(", FLAG_SCALING_DISABLED");
849 }
850 if ((flags & Display.FLAG_ROUND) != 0) {
851 result.append(", FLAG_ROUND");
852 }
853 if ((flags & Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
854 result.append(", FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD");
855 }
856 if ((flags & Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0) {
857 result.append(", FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS");
858 }
859 if ((flags & Display.FLAG_TRUSTED) != 0) {
860 result.append(", FLAG_TRUSTED");
861 }
862 if ((flags & Display.FLAG_OWN_DISPLAY_GROUP) != 0) {
863 result.append(", FLAG_OWN_DISPLAY_GROUP");
864 }
865 if ((flags & Display.FLAG_ALWAYS_UNLOCKED) != 0) {
866 result.append(", FLAG_ALWAYS_UNLOCKED");
867 }
868 if ((flags & Display.FLAG_TOUCH_FEEDBACK_DISABLED) != 0) {
869 result.append(", FLAG_TOUCH_FEEDBACK_DISABLED");
870 }
871 return result.toString();
872 }
873 }