blob: 1442cb72ed5925ce63dc9e50274be5fcacef8e76 [file] [log] [blame]
Jeff Brownfa25bf52012-07-23 19:26:30 -07001/*
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
17package android.view;
18
19import android.content.res.CompatibilityInfo;
20import android.os.Parcel;
21import android.os.Parcelable;
Jeff Browna506a6e2013-06-04 00:02:38 -070022import android.os.Process;
Jeff Brownfa25bf52012-07-23 19:26:30 -070023import android.util.DisplayMetrics;
24
Jeff Brown4ed8fe72012-08-30 18:18:29 -070025import libcore.util.Objects;
26
Jeff Brownfa25bf52012-07-23 19:26:30 -070027/**
28 * Describes the characteristics of a particular logical display.
29 * @hide
30 */
31public final class DisplayInfo implements Parcelable {
32 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -070033 * The surface flinger layer stack associated with this logical display.
34 */
35 public int layerStack;
36
37 /**
Jeff Brownc5df37c2012-09-13 11:45:07 -070038 * Display flags.
39 */
40 public int flags;
41
42 /**
Jeff Brown92130f62012-10-24 21:28:33 -070043 * Display type.
44 */
45 public int type;
46
47 /**
48 * Display address, or null if none.
49 * Interpretation varies by display type.
50 */
51 public String address;
52
53 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -070054 * The human-readable name of the display.
55 */
56 public String name;
57
58 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -070059 * The width of the portion of the display that is available to applications, in pixels.
60 * Represents the size of the display minus any system decorations.
61 */
62 public int appWidth;
63
64 /**
65 * The height of the portion of the display that is available to applications, in pixels.
66 * Represents the size of the display minus any system decorations.
67 */
68 public int appHeight;
69
70 /**
71 * The smallest value of {@link #appWidth} that an application is likely to encounter,
72 * in pixels, excepting cases where the width may be even smaller due to the presence
73 * of a soft keyboard, for example.
74 */
75 public int smallestNominalAppWidth;
76
77 /**
78 * The smallest value of {@link #appHeight} that an application is likely to encounter,
79 * in pixels, excepting cases where the height may be even smaller due to the presence
80 * of a soft keyboard, for example.
81 */
82 public int smallestNominalAppHeight;
83
84 /**
85 * The largest value of {@link #appWidth} that an application is likely to encounter,
86 * in pixels, excepting cases where the width may be even larger due to system decorations
87 * such as the status bar being hidden, for example.
88 */
89 public int largestNominalAppWidth;
90
91 /**
92 * The largest value of {@link #appHeight} that an application is likely to encounter,
93 * in pixels, excepting cases where the height may be even larger due to system decorations
94 * such as the status bar being hidden, for example.
95 */
96 public int largestNominalAppHeight;
97
98 /**
99 * The logical width of the display, in pixels.
100 * Represents the usable size of the display which may be smaller than the
101 * physical size when the system is emulating a smaller display.
102 */
103 public int logicalWidth;
104
105 /**
106 * The logical height of the display, in pixels.
107 * Represents the usable size of the display which may be smaller than the
108 * physical size when the system is emulating a smaller display.
109 */
110 public int logicalHeight;
111
112 /**
Dianne Hackbornc652de82013-02-15 16:32:56 -0800113 * @hide
114 * Number of overscan pixels on the left side of the display.
115 */
116 public int overscanLeft;
117
118 /**
119 * @hide
120 * Number of overscan pixels on the top side of the display.
121 */
122 public int overscanTop;
123
124 /**
125 * @hide
126 * Number of overscan pixels on the right side of the display.
127 */
128 public int overscanRight;
129
130 /**
131 * @hide
132 * Number of overscan pixels on the bottom side of the display.
133 */
134 public int overscanBottom;
135
136 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700137 * The rotation of the display relative to its natural orientation.
138 * May be one of {@link android.view.Surface#ROTATION_0},
139 * {@link android.view.Surface#ROTATION_90}, {@link android.view.Surface#ROTATION_180},
140 * {@link android.view.Surface#ROTATION_270}.
141 * <p>
142 * The value of this field is indeterminate if the logical display is presented on
143 * more than one physical display.
144 * </p>
145 */
146 public int rotation;
147
148 /**
149 * The refresh rate of this display in frames per second.
150 * <p>
151 * The value of this field is indeterminate if the logical display is presented on
152 * more than one physical display.
153 * </p>
154 */
155 public float refreshRate;
156
157 /**
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700158 * The logical display density which is the basis for density-independent
159 * pixels.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700160 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700161 public int logicalDensityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700162
163 /**
164 * The exact physical pixels per inch of the screen in the X dimension.
165 * <p>
166 * The value of this field is indeterminate if the logical display is presented on
167 * more than one physical display.
168 * </p>
169 */
170 public float physicalXDpi;
171
172 /**
173 * The exact physical pixels per inch of the screen in the Y dimension.
174 * <p>
175 * The value of this field is indeterminate if the logical display is presented on
176 * more than one physical display.
177 * </p>
178 */
179 public float physicalYDpi;
180
Jeff Browna506a6e2013-06-04 00:02:38 -0700181 /**
182 * The UID of the application that owns this display, or zero if it is owned by the system.
183 * <p>
184 * If the display is private, then only the owner can use it.
185 * </p>
186 */
187 public int ownerUid;
188
189 /**
190 * The package name of the application that owns this display, or null if it is
191 * owned by the system.
192 * <p>
193 * If the display is private, then only the owner can use it.
194 * </p>
195 */
196 public String ownerPackageName;
197
Jeff Brownfa25bf52012-07-23 19:26:30 -0700198 public static final Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
Jeff Brown92130f62012-10-24 21:28:33 -0700199 @Override
Jeff Brownfa25bf52012-07-23 19:26:30 -0700200 public DisplayInfo createFromParcel(Parcel source) {
201 return new DisplayInfo(source);
202 }
203
Jeff Brown92130f62012-10-24 21:28:33 -0700204 @Override
Jeff Brownfa25bf52012-07-23 19:26:30 -0700205 public DisplayInfo[] newArray(int size) {
206 return new DisplayInfo[size];
207 }
208 };
209
210 public DisplayInfo() {
211 }
212
Jeff Brownbd6e1502012-08-28 03:27:37 -0700213 public DisplayInfo(DisplayInfo other) {
214 copyFrom(other);
215 }
216
Jeff Brownfa25bf52012-07-23 19:26:30 -0700217 private DisplayInfo(Parcel source) {
218 readFromParcel(source);
219 }
220
221 @Override
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700222 public boolean equals(Object o) {
223 return o instanceof DisplayInfo && equals((DisplayInfo)o);
224 }
225
226 public boolean equals(DisplayInfo other) {
227 return other != null
228 && layerStack == other.layerStack
Jeff Brown92130f62012-10-24 21:28:33 -0700229 && flags == other.flags
230 && type == other.type
231 && Objects.equal(address, other.address)
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700232 && Objects.equal(name, other.name)
233 && appWidth == other.appWidth
234 && appHeight == other.appHeight
235 && smallestNominalAppWidth == other.smallestNominalAppWidth
236 && smallestNominalAppHeight == other.smallestNominalAppHeight
237 && largestNominalAppWidth == other.largestNominalAppWidth
238 && largestNominalAppHeight == other.largestNominalAppHeight
239 && logicalWidth == other.logicalWidth
240 && logicalHeight == other.logicalHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -0800241 && overscanLeft == other.overscanLeft
242 && overscanTop == other.overscanTop
243 && overscanRight == other.overscanRight
244 && overscanBottom == other.overscanBottom
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700245 && rotation == other.rotation
246 && refreshRate == other.refreshRate
247 && logicalDensityDpi == other.logicalDensityDpi
248 && physicalXDpi == other.physicalXDpi
Jeff Browna506a6e2013-06-04 00:02:38 -0700249 && physicalYDpi == other.physicalYDpi
250 && ownerUid == other.ownerUid
251 && Objects.equal(ownerPackageName, other.ownerPackageName);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700252 }
253
254 @Override
255 public int hashCode() {
256 return 0; // don't care
Jeff Brownfa25bf52012-07-23 19:26:30 -0700257 }
258
259 public void copyFrom(DisplayInfo other) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700260 layerStack = other.layerStack;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700261 flags = other.flags;
Jeff Brown92130f62012-10-24 21:28:33 -0700262 type = other.type;
263 address = other.address;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700264 name = other.name;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700265 appWidth = other.appWidth;
266 appHeight = other.appHeight;
267 smallestNominalAppWidth = other.smallestNominalAppWidth;
268 smallestNominalAppHeight = other.smallestNominalAppHeight;
269 largestNominalAppWidth = other.largestNominalAppWidth;
270 largestNominalAppHeight = other.largestNominalAppHeight;
271 logicalWidth = other.logicalWidth;
272 logicalHeight = other.logicalHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -0800273 overscanLeft = other.overscanLeft;
274 overscanTop = other.overscanTop;
275 overscanRight = other.overscanRight;
276 overscanBottom = other.overscanBottom;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700277 rotation = other.rotation;
278 refreshRate = other.refreshRate;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700279 logicalDensityDpi = other.logicalDensityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700280 physicalXDpi = other.physicalXDpi;
281 physicalYDpi = other.physicalYDpi;
Jeff Browna506a6e2013-06-04 00:02:38 -0700282 ownerUid = other.ownerUid;
283 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700284 }
285
286 public void readFromParcel(Parcel source) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700287 layerStack = source.readInt();
Jeff Brownc5df37c2012-09-13 11:45:07 -0700288 flags = source.readInt();
Jeff Brown92130f62012-10-24 21:28:33 -0700289 type = source.readInt();
290 address = source.readString();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700291 name = source.readString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700292 appWidth = source.readInt();
293 appHeight = source.readInt();
294 smallestNominalAppWidth = source.readInt();
295 smallestNominalAppHeight = source.readInt();
296 largestNominalAppWidth = source.readInt();
297 largestNominalAppHeight = source.readInt();
298 logicalWidth = source.readInt();
299 logicalHeight = source.readInt();
Dianne Hackbornc652de82013-02-15 16:32:56 -0800300 overscanLeft = source.readInt();
301 overscanTop = source.readInt();
302 overscanRight = source.readInt();
303 overscanBottom = source.readInt();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700304 rotation = source.readInt();
305 refreshRate = source.readFloat();
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700306 logicalDensityDpi = source.readInt();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700307 physicalXDpi = source.readFloat();
308 physicalYDpi = source.readFloat();
Jeff Browna506a6e2013-06-04 00:02:38 -0700309 ownerUid = source.readInt();
310 ownerPackageName = source.readString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700311 }
312
313 @Override
314 public void writeToParcel(Parcel dest, int flags) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700315 dest.writeInt(layerStack);
Jeff Brown3f2ba622012-10-04 14:57:44 -0700316 dest.writeInt(this.flags);
Jeff Brown92130f62012-10-24 21:28:33 -0700317 dest.writeInt(type);
318 dest.writeString(address);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700319 dest.writeString(name);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700320 dest.writeInt(appWidth);
321 dest.writeInt(appHeight);
322 dest.writeInt(smallestNominalAppWidth);
323 dest.writeInt(smallestNominalAppHeight);
324 dest.writeInt(largestNominalAppWidth);
325 dest.writeInt(largestNominalAppHeight);
326 dest.writeInt(logicalWidth);
327 dest.writeInt(logicalHeight);
Dianne Hackbornc652de82013-02-15 16:32:56 -0800328 dest.writeInt(overscanLeft);
329 dest.writeInt(overscanTop);
330 dest.writeInt(overscanRight);
331 dest.writeInt(overscanBottom);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700332 dest.writeInt(rotation);
333 dest.writeFloat(refreshRate);
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700334 dest.writeInt(logicalDensityDpi);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700335 dest.writeFloat(physicalXDpi);
336 dest.writeFloat(physicalYDpi);
Jeff Browna506a6e2013-06-04 00:02:38 -0700337 dest.writeInt(ownerUid);
338 dest.writeString(ownerPackageName);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700339 }
340
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700341 @Override
342 public int describeContents() {
343 return 0;
344 }
345
Jeff Brownfa25bf52012-07-23 19:26:30 -0700346 public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfoHolder cih) {
347 getMetricsWithSize(outMetrics, cih, appWidth, appHeight);
348 }
349
350 public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfoHolder cih) {
351 getMetricsWithSize(outMetrics, cih, logicalWidth, logicalHeight);
352 }
353
Jeff Brown7f3994e2012-12-04 14:04:28 -0800354 public int getNaturalWidth() {
355 return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ?
356 logicalWidth : logicalHeight;
357 }
358
359 public int getNaturalHeight() {
360 return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ?
361 logicalHeight : logicalWidth;
362 }
363
Jeff Browna506a6e2013-06-04 00:02:38 -0700364 /**
365 * Returns true if the specified UID has access to this display.
366 */
367 public boolean hasAccess(int uid) {
368 return Display.hasAccess(uid, flags, ownerUid);
369 }
370
Jeff Brownfa25bf52012-07-23 19:26:30 -0700371 private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfoHolder cih,
372 int width, int height) {
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700373 outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700374 outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width;
375 outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height;
376
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700377 outMetrics.density = outMetrics.noncompatDensity =
378 logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700379 outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density;
380 outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi;
381 outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi;
382
383 if (cih != null) {
384 CompatibilityInfo ci = cih.getIfNeeded();
385 if (ci != null) {
386 ci.applyToDisplayMetrics(outMetrics);
387 }
388 }
389 }
Jeff Brownbf5740e2012-08-19 23:20:02 -0700390
391 // For debugging purposes
392 @Override
393 public String toString() {
Dianne Hackbornc652de82013-02-15 16:32:56 -0800394 StringBuilder sb = new StringBuilder();
395 sb.append("DisplayInfo{\"");
396 sb.append(name);
397 sb.append("\", app ");
398 sb.append(appWidth);
399 sb.append(" x ");
400 sb.append(appHeight);
401 sb.append(", real ");
402 sb.append(logicalWidth);
403 sb.append(" x ");
404 sb.append(logicalHeight);
405 if (overscanLeft != 0 || overscanTop != 0 || overscanRight != 0 || overscanBottom != 0) {
406 sb.append(", overscan (");
407 sb.append(overscanLeft);
408 sb.append(",");
409 sb.append(overscanTop);
410 sb.append(",");
411 sb.append(overscanRight);
412 sb.append(",");
413 sb.append(overscanBottom);
414 sb.append(")");
415 }
416 sb.append(", largest app ");
417 sb.append(largestNominalAppWidth);
418 sb.append(" x ");
419 sb.append(largestNominalAppHeight);
420 sb.append(", smallest app ");
421 sb.append(smallestNominalAppWidth);
422 sb.append(" x ");
423 sb.append(smallestNominalAppHeight);
424 sb.append(", ");
425 sb.append(refreshRate);
426 sb.append(" fps, rotation");
427 sb.append(rotation);
428 sb.append(", density ");
429 sb.append(logicalDensityDpi);
430 sb.append(" (");
431 sb.append(physicalXDpi);
432 sb.append(" x ");
433 sb.append(physicalYDpi);
434 sb.append(") dpi, layerStack ");
435 sb.append(layerStack);
436 sb.append(", type ");
437 sb.append(Display.typeToString(type));
Jeff Browna506a6e2013-06-04 00:02:38 -0700438 if (address != null) {
439 sb.append(", address ").append(address);
440 }
441 if (ownerUid != 0 || ownerPackageName != null) {
442 sb.append(", owner ").append(ownerPackageName);
443 sb.append(" (uid ").append(ownerUid).append(")");
444 }
Dianne Hackbornc652de82013-02-15 16:32:56 -0800445 sb.append(flagsToString(flags));
446 sb.append("}");
447 return sb.toString();
Jeff Brownc5df37c2012-09-13 11:45:07 -0700448 }
449
450 private static String flagsToString(int flags) {
451 StringBuilder result = new StringBuilder();
Jeff Brownf0681b32012-10-23 17:35:57 -0700452 if ((flags & Display.FLAG_SECURE) != 0) {
453 result.append(", FLAG_SECURE");
454 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700455 if ((flags & Display.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
456 result.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700457 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700458 if ((flags & Display.FLAG_PRIVATE) != 0) {
459 result.append(", FLAG_PRIVATE");
460 }
Jeff Brownc5df37c2012-09-13 11:45:07 -0700461 return result.toString();
Jeff Brownbf5740e2012-08-19 23:20:02 -0700462 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700463}