Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 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 android.content.res.CompatibilityInfo; |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import android.util.DisplayMetrics; |
| 24 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 25 | import java.util.Arrays; |
| 26 | |
| 27 | import libcore.util.EmptyArray; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 28 | import libcore.util.Objects; |
| 29 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Describes the characteristics of a particular logical display. |
| 32 | * @hide |
| 33 | */ |
| 34 | public final class DisplayInfo implements Parcelable { |
| 35 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 36 | * The surface flinger layer stack associated with this logical display. |
| 37 | */ |
| 38 | public int layerStack; |
| 39 | |
| 40 | /** |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 41 | * Display flags. |
| 42 | */ |
| 43 | public int flags; |
| 44 | |
| 45 | /** |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 46 | * Display type. |
| 47 | */ |
| 48 | public int type; |
| 49 | |
| 50 | /** |
| 51 | * Display address, or null if none. |
| 52 | * Interpretation varies by display type. |
| 53 | */ |
| 54 | public String address; |
| 55 | |
| 56 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 57 | * The human-readable name of the display. |
| 58 | */ |
| 59 | public String name; |
| 60 | |
| 61 | /** |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 62 | * Unique identifier for the display. Shouldn't be displayed to the user. |
| 63 | */ |
| 64 | public String uniqueId; |
| 65 | |
| 66 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 67 | * The width of the portion of the display that is available to applications, in pixels. |
| 68 | * Represents the size of the display minus any system decorations. |
| 69 | */ |
| 70 | public int appWidth; |
| 71 | |
| 72 | /** |
| 73 | * The height of the portion of the display that is available to applications, in pixels. |
| 74 | * Represents the size of the display minus any system decorations. |
| 75 | */ |
| 76 | public int appHeight; |
| 77 | |
| 78 | /** |
| 79 | * The smallest value of {@link #appWidth} that an application is likely to encounter, |
| 80 | * in pixels, excepting cases where the width may be even smaller due to the presence |
| 81 | * of a soft keyboard, for example. |
| 82 | */ |
| 83 | public int smallestNominalAppWidth; |
| 84 | |
| 85 | /** |
| 86 | * The smallest value of {@link #appHeight} that an application is likely to encounter, |
| 87 | * in pixels, excepting cases where the height may be even smaller due to the presence |
| 88 | * of a soft keyboard, for example. |
| 89 | */ |
| 90 | public int smallestNominalAppHeight; |
| 91 | |
| 92 | /** |
| 93 | * The largest value of {@link #appWidth} that an application is likely to encounter, |
| 94 | * in pixels, excepting cases where the width may be even larger due to system decorations |
| 95 | * such as the status bar being hidden, for example. |
| 96 | */ |
| 97 | public int largestNominalAppWidth; |
| 98 | |
| 99 | /** |
| 100 | * The largest value of {@link #appHeight} that an application is likely to encounter, |
| 101 | * in pixels, excepting cases where the height may be even larger due to system decorations |
| 102 | * such as the status bar being hidden, for example. |
| 103 | */ |
| 104 | public int largestNominalAppHeight; |
| 105 | |
| 106 | /** |
| 107 | * The logical width of the display, in pixels. |
| 108 | * Represents the usable size of the display which may be smaller than the |
| 109 | * physical size when the system is emulating a smaller display. |
| 110 | */ |
| 111 | public int logicalWidth; |
| 112 | |
| 113 | /** |
| 114 | * The logical height of the display, in pixels. |
| 115 | * Represents the usable size of the display which may be smaller than the |
| 116 | * physical size when the system is emulating a smaller display. |
| 117 | */ |
| 118 | public int logicalHeight; |
| 119 | |
| 120 | /** |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 121 | * @hide |
| 122 | * Number of overscan pixels on the left side of the display. |
| 123 | */ |
| 124 | public int overscanLeft; |
| 125 | |
| 126 | /** |
| 127 | * @hide |
| 128 | * Number of overscan pixels on the top side of the display. |
| 129 | */ |
| 130 | public int overscanTop; |
| 131 | |
| 132 | /** |
| 133 | * @hide |
| 134 | * Number of overscan pixels on the right side of the display. |
| 135 | */ |
| 136 | public int overscanRight; |
| 137 | |
| 138 | /** |
| 139 | * @hide |
| 140 | * Number of overscan pixels on the bottom side of the display. |
| 141 | */ |
| 142 | public int overscanBottom; |
| 143 | |
| 144 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 145 | * The rotation of the display relative to its natural orientation. |
| 146 | * May be one of {@link android.view.Surface#ROTATION_0}, |
| 147 | * {@link android.view.Surface#ROTATION_90}, {@link android.view.Surface#ROTATION_180}, |
| 148 | * {@link android.view.Surface#ROTATION_270}. |
| 149 | * <p> |
| 150 | * The value of this field is indeterminate if the logical display is presented on |
| 151 | * more than one physical display. |
| 152 | * </p> |
| 153 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 154 | @Surface.Rotation |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 155 | public int rotation; |
| 156 | |
| 157 | /** |
| 158 | * The refresh rate of this display in frames per second. |
| 159 | * <p> |
| 160 | * The value of this field is indeterminate if the logical display is presented on |
| 161 | * more than one physical display. |
| 162 | * </p> |
| 163 | */ |
| 164 | public float refreshRate; |
| 165 | |
| 166 | /** |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 167 | * The supported refresh rates of this display at the current resolution in frames per second. |
| 168 | */ |
| 169 | public float[] supportedRefreshRates = EmptyArray.FLOAT; |
| 170 | |
| 171 | /** |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 172 | * The logical display density which is the basis for density-independent |
| 173 | * pixels. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 174 | */ |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 175 | public int logicalDensityDpi; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * The exact physical pixels per inch of the screen in the X dimension. |
| 179 | * <p> |
| 180 | * The value of this field is indeterminate if the logical display is presented on |
| 181 | * more than one physical display. |
| 182 | * </p> |
| 183 | */ |
| 184 | public float physicalXDpi; |
| 185 | |
| 186 | /** |
| 187 | * The exact physical pixels per inch of the screen in the Y dimension. |
| 188 | * <p> |
| 189 | * The value of this field is indeterminate if the logical display is presented on |
| 190 | * more than one physical display. |
| 191 | * </p> |
| 192 | */ |
| 193 | public float physicalYDpi; |
| 194 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 195 | /** |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 196 | * This is a positive value indicating the phase offset of the VSYNC events provided by |
| 197 | * Choreographer relative to the display refresh. For example, if Choreographer reports |
| 198 | * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos). |
| 199 | */ |
| 200 | public long appVsyncOffsetNanos; |
| 201 | |
| 202 | /** |
| 203 | * This is how far in advance a buffer must be queued for presentation at |
| 204 | * a given time. If you want a buffer to appear on the screen at |
| 205 | * time N, you must submit the buffer before (N - bufferDeadlineNanos). |
| 206 | */ |
| 207 | public long presentationDeadlineNanos; |
| 208 | |
| 209 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 210 | * The state of the display, such as {@link android.view.Display#STATE_ON}. |
| 211 | */ |
| 212 | public int state; |
| 213 | |
| 214 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 215 | * The UID of the application that owns this display, or zero if it is owned by the system. |
| 216 | * <p> |
| 217 | * If the display is private, then only the owner can use it. |
| 218 | * </p> |
| 219 | */ |
| 220 | public int ownerUid; |
| 221 | |
| 222 | /** |
| 223 | * The package name of the application that owns this display, or null if it is |
| 224 | * owned by the system. |
| 225 | * <p> |
| 226 | * If the display is private, then only the owner can use it. |
| 227 | * </p> |
| 228 | */ |
| 229 | public String ownerPackageName; |
| 230 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 231 | public static final Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 232 | @Override |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 233 | public DisplayInfo createFromParcel(Parcel source) { |
| 234 | return new DisplayInfo(source); |
| 235 | } |
| 236 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 237 | @Override |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 238 | public DisplayInfo[] newArray(int size) { |
| 239 | return new DisplayInfo[size]; |
| 240 | } |
| 241 | }; |
| 242 | |
| 243 | public DisplayInfo() { |
| 244 | } |
| 245 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 246 | public DisplayInfo(DisplayInfo other) { |
| 247 | copyFrom(other); |
| 248 | } |
| 249 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 250 | private DisplayInfo(Parcel source) { |
| 251 | readFromParcel(source); |
| 252 | } |
| 253 | |
| 254 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 255 | public boolean equals(Object o) { |
| 256 | return o instanceof DisplayInfo && equals((DisplayInfo)o); |
| 257 | } |
| 258 | |
| 259 | public boolean equals(DisplayInfo other) { |
| 260 | return other != null |
| 261 | && layerStack == other.layerStack |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 262 | && flags == other.flags |
| 263 | && type == other.type |
| 264 | && Objects.equal(address, other.address) |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 265 | && Objects.equal(uniqueId, other.uniqueId) |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 266 | && appWidth == other.appWidth |
| 267 | && appHeight == other.appHeight |
| 268 | && smallestNominalAppWidth == other.smallestNominalAppWidth |
| 269 | && smallestNominalAppHeight == other.smallestNominalAppHeight |
| 270 | && largestNominalAppWidth == other.largestNominalAppWidth |
| 271 | && largestNominalAppHeight == other.largestNominalAppHeight |
| 272 | && logicalWidth == other.logicalWidth |
| 273 | && logicalHeight == other.logicalHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 274 | && overscanLeft == other.overscanLeft |
| 275 | && overscanTop == other.overscanTop |
| 276 | && overscanRight == other.overscanRight |
| 277 | && overscanBottom == other.overscanBottom |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 278 | && rotation == other.rotation |
| 279 | && refreshRate == other.refreshRate |
| 280 | && logicalDensityDpi == other.logicalDensityDpi |
| 281 | && physicalXDpi == other.physicalXDpi |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 282 | && physicalYDpi == other.physicalYDpi |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 283 | && appVsyncOffsetNanos == other.appVsyncOffsetNanos |
| 284 | && presentationDeadlineNanos == other.presentationDeadlineNanos |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 285 | && state == other.state |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 286 | && ownerUid == other.ownerUid |
| 287 | && Objects.equal(ownerPackageName, other.ownerPackageName); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public int hashCode() { |
| 292 | return 0; // don't care |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | public void copyFrom(DisplayInfo other) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 296 | layerStack = other.layerStack; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 297 | flags = other.flags; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 298 | type = other.type; |
| 299 | address = other.address; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 300 | name = other.name; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 301 | uniqueId = other.uniqueId; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 302 | appWidth = other.appWidth; |
| 303 | appHeight = other.appHeight; |
| 304 | smallestNominalAppWidth = other.smallestNominalAppWidth; |
| 305 | smallestNominalAppHeight = other.smallestNominalAppHeight; |
| 306 | largestNominalAppWidth = other.largestNominalAppWidth; |
| 307 | largestNominalAppHeight = other.largestNominalAppHeight; |
| 308 | logicalWidth = other.logicalWidth; |
| 309 | logicalHeight = other.logicalHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 310 | overscanLeft = other.overscanLeft; |
| 311 | overscanTop = other.overscanTop; |
| 312 | overscanRight = other.overscanRight; |
| 313 | overscanBottom = other.overscanBottom; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 314 | rotation = other.rotation; |
| 315 | refreshRate = other.refreshRate; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 316 | supportedRefreshRates = Arrays.copyOf( |
| 317 | other.supportedRefreshRates, other.supportedRefreshRates.length); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 318 | logicalDensityDpi = other.logicalDensityDpi; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 319 | physicalXDpi = other.physicalXDpi; |
| 320 | physicalYDpi = other.physicalYDpi; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 321 | appVsyncOffsetNanos = other.appVsyncOffsetNanos; |
| 322 | presentationDeadlineNanos = other.presentationDeadlineNanos; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 323 | state = other.state; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 324 | ownerUid = other.ownerUid; |
| 325 | ownerPackageName = other.ownerPackageName; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | public void readFromParcel(Parcel source) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 329 | layerStack = source.readInt(); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 330 | flags = source.readInt(); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 331 | type = source.readInt(); |
| 332 | address = source.readString(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 333 | name = source.readString(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 334 | appWidth = source.readInt(); |
| 335 | appHeight = source.readInt(); |
| 336 | smallestNominalAppWidth = source.readInt(); |
| 337 | smallestNominalAppHeight = source.readInt(); |
| 338 | largestNominalAppWidth = source.readInt(); |
| 339 | largestNominalAppHeight = source.readInt(); |
| 340 | logicalWidth = source.readInt(); |
| 341 | logicalHeight = source.readInt(); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 342 | overscanLeft = source.readInt(); |
| 343 | overscanTop = source.readInt(); |
| 344 | overscanRight = source.readInt(); |
| 345 | overscanBottom = source.readInt(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 346 | rotation = source.readInt(); |
| 347 | refreshRate = source.readFloat(); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 348 | supportedRefreshRates = source.createFloatArray(); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 349 | logicalDensityDpi = source.readInt(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 350 | physicalXDpi = source.readFloat(); |
| 351 | physicalYDpi = source.readFloat(); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 352 | appVsyncOffsetNanos = source.readLong(); |
| 353 | presentationDeadlineNanos = source.readLong(); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 354 | state = source.readInt(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 355 | ownerUid = source.readInt(); |
| 356 | ownerPackageName = source.readString(); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 357 | uniqueId = source.readString(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public void writeToParcel(Parcel dest, int flags) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 362 | dest.writeInt(layerStack); |
Jeff Brown | 3f2ba62 | 2012-10-04 14:57:44 -0700 | [diff] [blame] | 363 | dest.writeInt(this.flags); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 364 | dest.writeInt(type); |
| 365 | dest.writeString(address); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 366 | dest.writeString(name); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 367 | dest.writeInt(appWidth); |
| 368 | dest.writeInt(appHeight); |
| 369 | dest.writeInt(smallestNominalAppWidth); |
| 370 | dest.writeInt(smallestNominalAppHeight); |
| 371 | dest.writeInt(largestNominalAppWidth); |
| 372 | dest.writeInt(largestNominalAppHeight); |
| 373 | dest.writeInt(logicalWidth); |
| 374 | dest.writeInt(logicalHeight); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 375 | dest.writeInt(overscanLeft); |
| 376 | dest.writeInt(overscanTop); |
| 377 | dest.writeInt(overscanRight); |
| 378 | dest.writeInt(overscanBottom); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 379 | dest.writeInt(rotation); |
| 380 | dest.writeFloat(refreshRate); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 381 | dest.writeFloatArray(supportedRefreshRates); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 382 | dest.writeInt(logicalDensityDpi); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 383 | dest.writeFloat(physicalXDpi); |
| 384 | dest.writeFloat(physicalYDpi); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 385 | dest.writeLong(appVsyncOffsetNanos); |
| 386 | dest.writeLong(presentationDeadlineNanos); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 387 | dest.writeInt(state); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 388 | dest.writeInt(ownerUid); |
| 389 | dest.writeString(ownerPackageName); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 390 | dest.writeString(uniqueId); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 393 | @Override |
| 394 | public int describeContents() { |
| 395 | return 0; |
| 396 | } |
| 397 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 398 | public void getAppMetrics(DisplayMetrics outMetrics) { |
| 399 | getAppMetrics(outMetrics, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 402 | public void getAppMetrics(DisplayMetrics outMetrics, DisplayAdjustments displayAdjustments) { |
| 403 | getMetricsWithSize(outMetrics, displayAdjustments.getCompatibilityInfo(), |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 404 | displayAdjustments.getConfiguration(), appWidth, appHeight); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 407 | public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfo ci, |
| 408 | Configuration configuration) { |
| 409 | getMetricsWithSize(outMetrics, ci, configuration, appWidth, appHeight); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 413 | Configuration configuration) { |
| 414 | getMetricsWithSize(outMetrics, compatInfo, configuration, logicalWidth, logicalHeight); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 417 | public int getNaturalWidth() { |
| 418 | return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ? |
| 419 | logicalWidth : logicalHeight; |
| 420 | } |
| 421 | |
| 422 | public int getNaturalHeight() { |
| 423 | return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ? |
| 424 | logicalHeight : logicalWidth; |
| 425 | } |
| 426 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 427 | /** |
| 428 | * Returns true if the specified UID has access to this display. |
| 429 | */ |
| 430 | public boolean hasAccess(int uid) { |
| 431 | return Display.hasAccess(uid, flags, ownerUid); |
| 432 | } |
| 433 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 434 | private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 435 | Configuration configuration, int width, int height) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 436 | outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 437 | outMetrics.density = outMetrics.noncompatDensity = |
| 438 | logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 439 | outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density; |
| 440 | outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi; |
| 441 | outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi; |
| 442 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 443 | width = (configuration != null |
| 444 | && configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) |
| 445 | ? (int)((configuration.screenWidthDp * outMetrics.density) + 0.5f) : width; |
| 446 | height = (configuration != null |
| 447 | && configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) |
| 448 | ? (int)((configuration.screenHeightDp * outMetrics.density) + 0.5f) : height; |
| 449 | |
| 450 | outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width; |
| 451 | outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height; |
| 452 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 453 | if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
| 454 | compatInfo.applyToDisplayMetrics(outMetrics); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 457 | |
| 458 | // For debugging purposes |
| 459 | @Override |
| 460 | public String toString() { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 461 | StringBuilder sb = new StringBuilder(); |
| 462 | sb.append("DisplayInfo{\""); |
| 463 | sb.append(name); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 464 | sb.append("\", uniqueId \""); |
| 465 | sb.append(uniqueId); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 466 | sb.append("\", app "); |
| 467 | sb.append(appWidth); |
| 468 | sb.append(" x "); |
| 469 | sb.append(appHeight); |
| 470 | sb.append(", real "); |
| 471 | sb.append(logicalWidth); |
| 472 | sb.append(" x "); |
| 473 | sb.append(logicalHeight); |
| 474 | if (overscanLeft != 0 || overscanTop != 0 || overscanRight != 0 || overscanBottom != 0) { |
| 475 | sb.append(", overscan ("); |
| 476 | sb.append(overscanLeft); |
| 477 | sb.append(","); |
| 478 | sb.append(overscanTop); |
| 479 | sb.append(","); |
| 480 | sb.append(overscanRight); |
| 481 | sb.append(","); |
| 482 | sb.append(overscanBottom); |
| 483 | sb.append(")"); |
| 484 | } |
| 485 | sb.append(", largest app "); |
| 486 | sb.append(largestNominalAppWidth); |
| 487 | sb.append(" x "); |
| 488 | sb.append(largestNominalAppHeight); |
| 489 | sb.append(", smallest app "); |
| 490 | sb.append(smallestNominalAppWidth); |
| 491 | sb.append(" x "); |
| 492 | sb.append(smallestNominalAppHeight); |
| 493 | sb.append(", "); |
| 494 | sb.append(refreshRate); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 495 | sb.append(" fps, supportedRefreshRates "); |
| 496 | sb.append(Arrays.toString(supportedRefreshRates)); |
| 497 | sb.append(", rotation "); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 498 | sb.append(rotation); |
| 499 | sb.append(", density "); |
| 500 | sb.append(logicalDensityDpi); |
| 501 | sb.append(" ("); |
| 502 | sb.append(physicalXDpi); |
| 503 | sb.append(" x "); |
| 504 | sb.append(physicalYDpi); |
| 505 | sb.append(") dpi, layerStack "); |
| 506 | sb.append(layerStack); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 507 | sb.append(", appVsyncOff "); |
| 508 | sb.append(appVsyncOffsetNanos); |
| 509 | sb.append(", presDeadline "); |
| 510 | sb.append(presentationDeadlineNanos); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 511 | sb.append(", type "); |
| 512 | sb.append(Display.typeToString(type)); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 513 | if (address != null) { |
| 514 | sb.append(", address ").append(address); |
| 515 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 516 | sb.append(", state "); |
| 517 | sb.append(Display.stateToString(state)); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 518 | if (ownerUid != 0 || ownerPackageName != null) { |
| 519 | sb.append(", owner ").append(ownerPackageName); |
| 520 | sb.append(" (uid ").append(ownerUid).append(")"); |
| 521 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 522 | sb.append(flagsToString(flags)); |
| 523 | sb.append("}"); |
| 524 | return sb.toString(); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | private static String flagsToString(int flags) { |
| 528 | StringBuilder result = new StringBuilder(); |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 529 | if ((flags & Display.FLAG_SECURE) != 0) { |
| 530 | result.append(", FLAG_SECURE"); |
| 531 | } |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 532 | if ((flags & Display.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) { |
| 533 | result.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS"); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 534 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 535 | if ((flags & Display.FLAG_PRIVATE) != 0) { |
| 536 | result.append(", FLAG_PRIVATE"); |
| 537 | } |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 538 | if ((flags & Display.FLAG_PRESENTATION) != 0) { |
| 539 | result.append(", FLAG_PRESENTATION"); |
| 540 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 541 | if ((flags & Display.FLAG_SCALING_DISABLED) != 0) { |
| 542 | result.append(", FLAG_SCALING_DISABLED"); |
| 543 | } |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 544 | return result.toString(); |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 545 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 546 | } |