| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 46 |
|
| 47 |
|
| 48 |
public final class DisplayInfo implements Parcelable { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public int layerStack; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public int flags; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public int type; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public int displayId; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public int displayGroupId; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public DisplayAddress address; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public DeviceProductInfo deviceProductInfo; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public String name; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public String uniqueId; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public int appWidth; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public int appHeight; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public int smallestNominalAppWidth; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public int smallestNominalAppHeight; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public int largestNominalAppWidth; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public int largestNominalAppHeight; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
@UnsupportedAppUsage |
| 143 |
public int logicalWidth; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
@UnsupportedAppUsage |
| 151 |
public int logicalHeight; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
@Nullable |
| 160 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 161 |
public DisplayCutout displayCutout; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
@Surface.Rotation |
| 174 |
@UnsupportedAppUsage |
| 175 |
public int rotation; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
public int modeId; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public int defaultModeId; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY; |
| 191 |
|
| 192 |
|
| 193 |
public int colorMode; |
| 194 |
|
| 195 |
|
| 196 |
public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT }; |
| 197 |
|
| 198 |
|
| 199 |
public Display.HdrCapabilities hdrCapabilities; |
| 200 |
|
| 201 |
|
| 202 |
public int[] userDisabledHdrTypes = {}; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public boolean minimalPostProcessingSupported; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public int logicalDensityDpi; |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
public float physicalXDpi; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
public float physicalYDpi; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
public long appVsyncOffsetNanos; |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public long presentationDeadlineNanos; |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
public int state; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public int ownerUid; |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
public String ownerPackageName; |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public float refreshRateOverride; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public int removeMode = Display.REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY; |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public float brightnessMinimum; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
public float brightnessMaximum; |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
public float brightnessDefault; |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
@Nullable |
| 312 |
public RoundedCorners roundedCorners; |
| 313 |
|
| 314 |
|
| 315 |
|
| 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; |
| 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 |
|
| 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 |
|
| 592 |
|
| 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 |
|
| 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 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, |
| 652 |
Configuration configuration) { |
| 653 |
getMetricsWithSize(outMetrics, compatInfo, configuration, logicalWidth, logicalHeight); |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public void getMaxBoundsMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, |
| 661 |
Configuration configuration) { |
| 662 |
Rect bounds = configuration.windowConfiguration.getMaxBounds(); |
| 663 |
|
| 664 |
getMetricsWithSize(outMetrics, compatInfo, 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 |
|
| 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 |
|
| 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 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 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 |
} |