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