1 /* 2 * Copyright (C) 2020 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.hardware.display; 18 19 import static android.view.Display.DEFAULT_DISPLAY; 20 21 import android.annotation.IntRange; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.hardware.display.DisplayManager.VirtualDisplayFlag; 25 import android.media.projection.MediaProjection; 26 import android.os.Handler; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 import android.view.Surface; 30 31 import com.android.internal.util.DataClass; 32 33 /** 34 * Holds configuration used to create {@link VirtualDisplay} instances. See 35 * {@link MediaProjection#createVirtualDisplay(VirtualDisplayConfig, VirtualDisplay.Callback, Handler)}. 36 * 37 * @hide 38 */ 39 @DataClass(genParcelable = true, genAidl = true, genBuilder = true) 40 public final class VirtualDisplayConfig implements Parcelable { 41 /** 42 * The name of the virtual display, must be non-empty. 43 */ 44 @NonNull 45 private String mName; 46 47 /** 48 * The width of the virtual display in pixels. Must be greater than 0. 49 */ 50 @IntRange(from = 1) 51 private int mWidth; 52 53 /** 54 * The height of the virtual display in pixels. Must be greater than 0. 55 */ 56 @IntRange(from = 1) 57 private int mHeight; 58 59 /** 60 * The density of the virtual display in dpi. Must be greater than 0. 61 */ 62 @IntRange(from = 1) 63 private int mDensityDpi; 64 65 /** 66 * A combination of virtual display flags. 67 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC}, 68 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PRESENTATION}, 69 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_SECURE}, 70 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}, 71 * or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. 72 */ 73 @VirtualDisplayFlag 74 private int mFlags = 0; 75 76 /** 77 * The surface to which the content of the virtual display should be rendered, or null if 78 * there is none initially. 79 */ 80 @Nullable 81 private Surface mSurface = null; 82 83 /** 84 * The unique identifier for the display. Shouldn't be displayed to the user. 85 * @hide 86 */ 87 @Nullable 88 private String mUniqueId = null; 89 90 /** 91 * The id of the display that the virtual display should mirror, or 92 * {@link android.view.Display#DEFAULT_DISPLAY} if there is none initially. 93 */ 94 private int mDisplayIdToMirror = DEFAULT_DISPLAY; 95 96 /** 97 * Indicates if WindowManager is responsible for mirroring content to this VirtualDisplay, or 98 * if DisplayManager should record contents instead. 99 */ 100 private boolean mWindowManagerMirroring = false; 101 102 103 104 // Code below generated by codegen v1.0.23. 105 // 106 // DO NOT MODIFY! 107 // CHECKSTYLE:OFF Generated code 108 // 109 // To regenerate run: 110 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/display/VirtualDisplayConfig.java 111 // 112 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 113 // Settings > Editor > Code Style > Formatter Control 114 //@formatter:off 115 116 117 @DataClass.Generated.Member VirtualDisplayConfig( @onNull String name, @IntRange(from = 1) int width, @IntRange(from = 1) int height, @IntRange(from = 1) int densityDpi, @VirtualDisplayFlag int flags, @Nullable Surface surface, @Nullable String uniqueId, int displayIdToMirror, boolean windowManagerMirroring)118 /* package-private */ VirtualDisplayConfig( 119 @NonNull String name, 120 @IntRange(from = 1) int width, 121 @IntRange(from = 1) int height, 122 @IntRange(from = 1) int densityDpi, 123 @VirtualDisplayFlag int flags, 124 @Nullable Surface surface, 125 @Nullable String uniqueId, 126 int displayIdToMirror, 127 boolean windowManagerMirroring) { 128 this.mName = name; 129 com.android.internal.util.AnnotationValidations.validate( 130 NonNull.class, null, mName); 131 this.mWidth = width; 132 com.android.internal.util.AnnotationValidations.validate( 133 IntRange.class, null, mWidth, 134 "from", 1); 135 this.mHeight = height; 136 com.android.internal.util.AnnotationValidations.validate( 137 IntRange.class, null, mHeight, 138 "from", 1); 139 this.mDensityDpi = densityDpi; 140 com.android.internal.util.AnnotationValidations.validate( 141 IntRange.class, null, mDensityDpi, 142 "from", 1); 143 this.mFlags = flags; 144 com.android.internal.util.AnnotationValidations.validate( 145 VirtualDisplayFlag.class, null, mFlags); 146 this.mSurface = surface; 147 this.mUniqueId = uniqueId; 148 this.mDisplayIdToMirror = displayIdToMirror; 149 this.mWindowManagerMirroring = windowManagerMirroring; 150 151 // onConstructed(); // You can define this method to get a callback 152 } 153 154 /** 155 * The name of the virtual display, must be non-empty. 156 */ 157 @DataClass.Generated.Member getName()158 public @NonNull String getName() { 159 return mName; 160 } 161 162 /** 163 * The width of the virtual display in pixels. Must be greater than 0. 164 */ 165 @DataClass.Generated.Member getWidth()166 public @IntRange(from = 1) int getWidth() { 167 return mWidth; 168 } 169 170 /** 171 * The height of the virtual display in pixels. Must be greater than 0. 172 */ 173 @DataClass.Generated.Member getHeight()174 public @IntRange(from = 1) int getHeight() { 175 return mHeight; 176 } 177 178 /** 179 * The density of the virtual display in dpi. Must be greater than 0. 180 */ 181 @DataClass.Generated.Member getDensityDpi()182 public @IntRange(from = 1) int getDensityDpi() { 183 return mDensityDpi; 184 } 185 186 /** 187 * A combination of virtual display flags. 188 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC}, 189 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PRESENTATION}, 190 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_SECURE}, 191 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}, 192 * or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. 193 */ 194 @DataClass.Generated.Member getFlags()195 public @VirtualDisplayFlag int getFlags() { 196 return mFlags; 197 } 198 199 /** 200 * The surface to which the content of the virtual display should be rendered, or null if 201 * there is none initially. 202 */ 203 @DataClass.Generated.Member getSurface()204 public @Nullable Surface getSurface() { 205 return mSurface; 206 } 207 208 /** 209 * The unique identifier for the display. Shouldn't be displayed to the user. 210 * 211 * @hide 212 */ 213 @DataClass.Generated.Member getUniqueId()214 public @Nullable String getUniqueId() { 215 return mUniqueId; 216 } 217 218 /** 219 * The id of the display that the virtual display should mirror, or 220 * {@link android.view.Display#DEFAULT_DISPLAY} if there is none initially. 221 */ 222 @DataClass.Generated.Member getDisplayIdToMirror()223 public int getDisplayIdToMirror() { 224 return mDisplayIdToMirror; 225 } 226 227 /** 228 * Indicates if WindowManager is responsible for mirroring content to this VirtualDisplay, or 229 * if DisplayManager should record contents instead. 230 */ 231 @DataClass.Generated.Member isWindowManagerMirroring()232 public boolean isWindowManagerMirroring() { 233 return mWindowManagerMirroring; 234 } 235 236 @Override 237 @DataClass.Generated.Member writeToParcel(@onNull Parcel dest, int flags)238 public void writeToParcel(@NonNull Parcel dest, int flags) { 239 // You can override field parcelling by defining methods like: 240 // void parcelFieldName(Parcel dest, int flags) { ... } 241 242 int flg = 0; 243 if (mWindowManagerMirroring) flg |= 0x100; 244 if (mSurface != null) flg |= 0x20; 245 if (mUniqueId != null) flg |= 0x40; 246 dest.writeInt(flg); 247 dest.writeString(mName); 248 dest.writeInt(mWidth); 249 dest.writeInt(mHeight); 250 dest.writeInt(mDensityDpi); 251 dest.writeInt(mFlags); 252 if (mSurface != null) dest.writeTypedObject(mSurface, flags); 253 if (mUniqueId != null) dest.writeString(mUniqueId); 254 dest.writeInt(mDisplayIdToMirror); 255 } 256 257 @Override 258 @DataClass.Generated.Member describeContents()259 public int describeContents() { return 0; } 260 261 /** @hide */ 262 @SuppressWarnings({"unchecked", "RedundantCast"}) 263 @DataClass.Generated.Member VirtualDisplayConfig(@onNull Parcel in)264 /* package-private */ VirtualDisplayConfig(@NonNull Parcel in) { 265 // You can override field unparcelling by defining methods like: 266 // static FieldType unparcelFieldName(Parcel in) { ... } 267 268 int flg = in.readInt(); 269 boolean windowManagerMirroring = (flg & 0x100) != 0; 270 String name = in.readString(); 271 int width = in.readInt(); 272 int height = in.readInt(); 273 int densityDpi = in.readInt(); 274 int flags = in.readInt(); 275 Surface surface = (flg & 0x20) == 0 ? null : (Surface) in.readTypedObject(Surface.CREATOR); 276 String uniqueId = (flg & 0x40) == 0 ? null : in.readString(); 277 int displayIdToMirror = in.readInt(); 278 279 this.mName = name; 280 com.android.internal.util.AnnotationValidations.validate( 281 NonNull.class, null, mName); 282 this.mWidth = width; 283 com.android.internal.util.AnnotationValidations.validate( 284 IntRange.class, null, mWidth, 285 "from", 1); 286 this.mHeight = height; 287 com.android.internal.util.AnnotationValidations.validate( 288 IntRange.class, null, mHeight, 289 "from", 1); 290 this.mDensityDpi = densityDpi; 291 com.android.internal.util.AnnotationValidations.validate( 292 IntRange.class, null, mDensityDpi, 293 "from", 1); 294 this.mFlags = flags; 295 com.android.internal.util.AnnotationValidations.validate( 296 VirtualDisplayFlag.class, null, mFlags); 297 this.mSurface = surface; 298 this.mUniqueId = uniqueId; 299 this.mDisplayIdToMirror = displayIdToMirror; 300 this.mWindowManagerMirroring = windowManagerMirroring; 301 302 // onConstructed(); // You can define this method to get a callback 303 } 304 305 @DataClass.Generated.Member 306 public static final @NonNull Parcelable.Creator<VirtualDisplayConfig> CREATOR 307 = new Parcelable.Creator<VirtualDisplayConfig>() { 308 @Override 309 public VirtualDisplayConfig[] newArray(int size) { 310 return new VirtualDisplayConfig[size]; 311 } 312 313 @Override 314 public VirtualDisplayConfig createFromParcel(@NonNull Parcel in) { 315 return new VirtualDisplayConfig(in); 316 } 317 }; 318 319 /** 320 * A builder for {@link VirtualDisplayConfig} 321 */ 322 @SuppressWarnings("WeakerAccess") 323 @DataClass.Generated.Member 324 public static final class Builder { 325 326 private @NonNull String mName; 327 private @IntRange(from = 1) int mWidth; 328 private @IntRange(from = 1) int mHeight; 329 private @IntRange(from = 1) int mDensityDpi; 330 private @VirtualDisplayFlag int mFlags; 331 private @Nullable Surface mSurface; 332 private @Nullable String mUniqueId; 333 private int mDisplayIdToMirror; 334 private boolean mWindowManagerMirroring; 335 336 private long mBuilderFieldsSet = 0L; 337 338 /** 339 * Creates a new Builder. 340 * 341 * @param name 342 * The name of the virtual display, must be non-empty. 343 * @param width 344 * The width of the virtual display in pixels. Must be greater than 0. 345 * @param height 346 * The height of the virtual display in pixels. Must be greater than 0. 347 * @param densityDpi 348 * The density of the virtual display in dpi. Must be greater than 0. 349 */ Builder( @onNull String name, @IntRange(from = 1) int width, @IntRange(from = 1) int height, @IntRange(from = 1) int densityDpi)350 public Builder( 351 @NonNull String name, 352 @IntRange(from = 1) int width, 353 @IntRange(from = 1) int height, 354 @IntRange(from = 1) int densityDpi) { 355 mName = name; 356 com.android.internal.util.AnnotationValidations.validate( 357 NonNull.class, null, mName); 358 mWidth = width; 359 com.android.internal.util.AnnotationValidations.validate( 360 IntRange.class, null, mWidth, 361 "from", 1); 362 mHeight = height; 363 com.android.internal.util.AnnotationValidations.validate( 364 IntRange.class, null, mHeight, 365 "from", 1); 366 mDensityDpi = densityDpi; 367 com.android.internal.util.AnnotationValidations.validate( 368 IntRange.class, null, mDensityDpi, 369 "from", 1); 370 } 371 372 /** 373 * The name of the virtual display, must be non-empty. 374 */ 375 @DataClass.Generated.Member setName(@onNull String value)376 public @NonNull Builder setName(@NonNull String value) { 377 checkNotUsed(); 378 mBuilderFieldsSet |= 0x1; 379 mName = value; 380 return this; 381 } 382 383 /** 384 * The width of the virtual display in pixels. Must be greater than 0. 385 */ 386 @DataClass.Generated.Member setWidth(@ntRangefrom = 1) int value)387 public @NonNull Builder setWidth(@IntRange(from = 1) int value) { 388 checkNotUsed(); 389 mBuilderFieldsSet |= 0x2; 390 mWidth = value; 391 return this; 392 } 393 394 /** 395 * The height of the virtual display in pixels. Must be greater than 0. 396 */ 397 @DataClass.Generated.Member setHeight(@ntRangefrom = 1) int value)398 public @NonNull Builder setHeight(@IntRange(from = 1) int value) { 399 checkNotUsed(); 400 mBuilderFieldsSet |= 0x4; 401 mHeight = value; 402 return this; 403 } 404 405 /** 406 * The density of the virtual display in dpi. Must be greater than 0. 407 */ 408 @DataClass.Generated.Member setDensityDpi(@ntRangefrom = 1) int value)409 public @NonNull Builder setDensityDpi(@IntRange(from = 1) int value) { 410 checkNotUsed(); 411 mBuilderFieldsSet |= 0x8; 412 mDensityDpi = value; 413 return this; 414 } 415 416 /** 417 * A combination of virtual display flags. 418 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC}, 419 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PRESENTATION}, 420 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_SECURE}, 421 * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}, 422 * or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. 423 */ 424 @DataClass.Generated.Member setFlags(@irtualDisplayFlag int value)425 public @NonNull Builder setFlags(@VirtualDisplayFlag int value) { 426 checkNotUsed(); 427 mBuilderFieldsSet |= 0x10; 428 mFlags = value; 429 return this; 430 } 431 432 /** 433 * The surface to which the content of the virtual display should be rendered, or null if 434 * there is none initially. 435 */ 436 @DataClass.Generated.Member setSurface(@onNull Surface value)437 public @NonNull Builder setSurface(@NonNull Surface value) { 438 checkNotUsed(); 439 mBuilderFieldsSet |= 0x20; 440 mSurface = value; 441 return this; 442 } 443 444 /** 445 * The unique identifier for the display. Shouldn't be displayed to the user. 446 * 447 * @hide 448 */ 449 @DataClass.Generated.Member setUniqueId(@onNull String value)450 public @NonNull Builder setUniqueId(@NonNull String value) { 451 checkNotUsed(); 452 mBuilderFieldsSet |= 0x40; 453 mUniqueId = value; 454 return this; 455 } 456 457 /** 458 * The id of the display that the virtual display should mirror, or 459 * {@link android.view.Display#DEFAULT_DISPLAY} if there is none initially. 460 */ 461 @DataClass.Generated.Member setDisplayIdToMirror(int value)462 public @NonNull Builder setDisplayIdToMirror(int value) { 463 checkNotUsed(); 464 mBuilderFieldsSet |= 0x80; 465 mDisplayIdToMirror = value; 466 return this; 467 } 468 469 /** 470 * Indicates if WindowManager is responsible for mirroring content to this VirtualDisplay, or 471 * if DisplayManager should record contents instead. 472 */ 473 @DataClass.Generated.Member setWindowManagerMirroring(boolean value)474 public @NonNull Builder setWindowManagerMirroring(boolean value) { 475 checkNotUsed(); 476 mBuilderFieldsSet |= 0x100; 477 mWindowManagerMirroring = value; 478 return this; 479 } 480 481 /** Builds the instance. This builder should not be touched after calling this! */ build()482 public @NonNull VirtualDisplayConfig build() { 483 checkNotUsed(); 484 mBuilderFieldsSet |= 0x200; // Mark builder used 485 486 if ((mBuilderFieldsSet & 0x10) == 0) { 487 mFlags = 0; 488 } 489 if ((mBuilderFieldsSet & 0x20) == 0) { 490 mSurface = null; 491 } 492 if ((mBuilderFieldsSet & 0x40) == 0) { 493 mUniqueId = null; 494 } 495 if ((mBuilderFieldsSet & 0x80) == 0) { 496 mDisplayIdToMirror = DEFAULT_DISPLAY; 497 } 498 if ((mBuilderFieldsSet & 0x100) == 0) { 499 mWindowManagerMirroring = false; 500 } 501 VirtualDisplayConfig o = new VirtualDisplayConfig( 502 mName, 503 mWidth, 504 mHeight, 505 mDensityDpi, 506 mFlags, 507 mSurface, 508 mUniqueId, 509 mDisplayIdToMirror, 510 mWindowManagerMirroring); 511 return o; 512 } 513 checkNotUsed()514 private void checkNotUsed() { 515 if ((mBuilderFieldsSet & 0x200) != 0) { 516 throw new IllegalStateException( 517 "This Builder should not be reused. Use a new Builder instance instead"); 518 } 519 } 520 } 521 522 @DataClass.Generated( 523 time = 1646227247934L, 524 codegenVersion = "1.0.23", 525 sourceFile = "frameworks/base/core/java/android/hardware/display/VirtualDisplayConfig.java", 526 inputSignatures = "private @android.annotation.NonNull java.lang.String mName\nprivate @android.annotation.IntRange int mWidth\nprivate @android.annotation.IntRange int mHeight\nprivate @android.annotation.IntRange int mDensityDpi\nprivate @android.hardware.display.DisplayManager.VirtualDisplayFlag int mFlags\nprivate @android.annotation.Nullable android.view.Surface mSurface\nprivate @android.annotation.Nullable java.lang.String mUniqueId\nprivate int mDisplayIdToMirror\nprivate boolean mWindowManagerMirroring\nclass VirtualDisplayConfig extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genParcelable=true, genAidl=true, genBuilder=true)") 527 @Deprecated __metadata()528 private void __metadata() {} 529 530 531 //@formatter:on 532 // End of generated code 533 534 } 535