Make VirtualDisplayConfig public.

Replace all new createVirtualDisplay overloads with a new one taking
a VirtualDisplayConfig argument.

Bug: 270334704
Test: atest VirtualDisplayConfigTest
Test: atest VirtualDisplayTest
Test: atest RestrictActivityTest

Change-Id: I644c5000e4e3d99f1cae5f2258624c9583f4f1b1
This commit is contained in:
Vladimir Komsiyski
2023-02-22 20:23:42 +01:00
parent 9e4c08d050
commit bd8ce082f6
6 changed files with 301 additions and 540 deletions

View File

@@ -19520,9 +19520,9 @@ package android.hardware.display {
public final class DisplayManager {
method public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull String, @IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, @Nullable android.view.Surface, int);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull String, @IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, float, @Nullable android.view.Surface, int);
method public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull String, @IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, @Nullable android.view.Surface, int, @Nullable android.hardware.display.VirtualDisplay.Callback, @Nullable android.os.Handler);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull String, @IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, float, @Nullable android.view.Surface, int, @Nullable android.os.Handler, @Nullable android.hardware.display.VirtualDisplay.Callback);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull android.hardware.display.VirtualDisplayConfig);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull android.hardware.display.VirtualDisplayConfig, @Nullable android.os.Handler, @Nullable android.hardware.display.VirtualDisplay.Callback);
method public android.view.Display getDisplay(int);
method public android.view.Display[] getDisplays();
method public android.view.Display[] getDisplays(String);
@@ -19577,6 +19577,30 @@ package android.hardware.display {
method public void onStopped();
}
public final class VirtualDisplayConfig implements android.os.Parcelable {
method public int describeContents();
method public int getDensityDpi();
method @NonNull public java.util.List<java.lang.String> getDisplayCategories();
method public int getFlags();
method public int getHeight();
method @NonNull public String getName();
method public float getRequestedRefreshRate();
method @Nullable public android.view.Surface getSurface();
method public int getWidth();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.hardware.display.VirtualDisplayConfig> CREATOR;
}
public static final class VirtualDisplayConfig.Builder {
ctor public VirtualDisplayConfig.Builder(@NonNull String, @IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int);
method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder addDisplayCategory(@NonNull String);
method @NonNull public android.hardware.display.VirtualDisplayConfig build();
method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setDisplayCategories(@NonNull java.util.List<java.lang.String>);
method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setFlags(int);
method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setRequestedRefreshRate(@FloatRange(from=0.0f) float);
method @NonNull public android.hardware.display.VirtualDisplayConfig.Builder setSurface(@Nullable android.view.Surface);
}
}
package android.hardware.fingerprint {

View File

@@ -3214,8 +3214,8 @@ package android.companion.virtual {
method @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void close();
method @NonNull public android.content.Context createContext();
method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.companion.virtual.audio.VirtualAudioDevice createVirtualAudioDevice(@NonNull android.hardware.display.VirtualDisplay, @Nullable java.util.concurrent.Executor, @Nullable android.companion.virtual.audio.VirtualAudioDevice.AudioConfigurationChangeCallback);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, @Nullable android.view.Surface, int, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.display.VirtualDisplay.Callback);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, @NonNull java.util.List<java.lang.String>, @Nullable android.view.Surface, int, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.display.VirtualDisplay.Callback);
method @Deprecated @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@IntRange(from=1) int, @IntRange(from=1) int, @IntRange(from=1) int, @Nullable android.view.Surface, int, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.display.VirtualDisplay.Callback);
method @Nullable public android.hardware.display.VirtualDisplay createVirtualDisplay(@NonNull android.hardware.display.VirtualDisplayConfig, @Nullable java.util.concurrent.Executor, @Nullable android.hardware.display.VirtualDisplay.Callback);
method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualDpad createVirtualDpad(@NonNull android.hardware.input.VirtualDpadConfig);
method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualKeyboard createVirtualKeyboard(@NonNull android.hardware.input.VirtualKeyboardConfig);
method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualKeyboard createVirtualKeyboard(@NonNull android.hardware.display.VirtualDisplay, @NonNull String, int, int);

View File

@@ -89,14 +89,6 @@ public final class VirtualDeviceManager {
private static final String TAG = "VirtualDeviceManager";
private static final int DEFAULT_VIRTUAL_DISPLAY_FLAGS =
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
| DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT
| DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
| DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL
| DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH
| DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_FOCUS;
/**
* The default device ID, which is the ID of the primary (non-virtual) device.
*/
@@ -549,7 +541,11 @@ public final class VirtualDeviceManager {
* not create the virtual display.
*
* @see DisplayManager#createVirtualDisplay
*
* @deprecated use {@link #createVirtualDisplay(VirtualDisplayConfig, Executor,
* VirtualDisplay.Callback)}
*/
@Deprecated
@Nullable
public VirtualDisplay createVirtualDisplay(
@IntRange(from = 1) int width,
@@ -562,30 +558,16 @@ public final class VirtualDeviceManager {
VirtualDisplayConfig config = new VirtualDisplayConfig.Builder(
getVirtualDisplayName(), width, height, densityDpi)
.setSurface(surface)
.setFlags(getVirtualDisplayFlags(flags))
.setFlags(flags)
.build();
return createVirtualDisplayInternal(config, executor, callback);
return createVirtualDisplay(config, executor, callback);
}
/**
* Creates a virtual display for this virtual device. All displays created on the same
* device belongs to the same display group.
*
* @param width The width of the virtual display in pixels, must be greater than 0.
* @param height The height of the virtual display in pixels, must be greater than 0.
* @param densityDpi The density of the virtual display in dpi, must be greater than 0.
* @param displayCategories The categories of the virtual display, indicating the type of
* activities allowed to run on the display. Activities can declare their type using
* {@link android.content.pm.ActivityInfo#requiredDisplayCategory}.
* @param surface The surface to which the content of the virtual display should
* be rendered, or null if there is none initially. The surface can also be set later using
* {@link VirtualDisplay#setSurface(Surface)}.
* @param flags A combination of virtual display flags accepted by
* {@link DisplayManager#createVirtualDisplay}. In addition, the following flags are
* automatically set for all virtual devices:
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC VIRTUAL_DISPLAY_FLAG_PUBLIC} and
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
* VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}.
* @param config The configuration of the display.
* @param executor The executor on which {@code callback} will be invoked. This is ignored
* if {@code callback} is {@code null}. If {@code callback} is specified, this executor must
* not be null.
@@ -597,28 +579,6 @@ public final class VirtualDeviceManager {
*/
@Nullable
public VirtualDisplay createVirtualDisplay(
@IntRange(from = 1) int width,
@IntRange(from = 1) int height,
@IntRange(from = 1) int densityDpi,
@NonNull List<String> displayCategories,
@Nullable Surface surface,
@VirtualDisplayFlag int flags,
@Nullable @CallbackExecutor Executor executor,
@Nullable VirtualDisplay.Callback callback) {
VirtualDisplayConfig config = new VirtualDisplayConfig.Builder(
getVirtualDisplayName(), width, height, densityDpi)
.setDisplayCategories(displayCategories)
.setSurface(surface)
.setFlags(getVirtualDisplayFlags(flags))
.build();
return createVirtualDisplayInternal(config, executor, callback);
}
/**
* @hide
*/
@Nullable
private VirtualDisplay createVirtualDisplayInternal(
@NonNull VirtualDisplayConfig config,
@Nullable @CallbackExecutor Executor executor,
@Nullable VirtualDisplay.Callback callback) {
@@ -907,16 +867,6 @@ public final class VirtualDeviceManager {
}
}
/**
* Returns the display flags that should be added to a particular virtual display.
* Additional device-level flags from {@link
* com.android.server.companion.virtual.VirtualDeviceImpl#getBaseVirtualDisplayFlags()} will
* be added by DisplayManagerService.
*/
private int getVirtualDisplayFlags(int flags) {
return DEFAULT_VIRTUAL_DISPLAY_FLAGS | flags;
}
private String getVirtualDisplayName() {
try {
// Currently this just use the device ID, which means all of the virtual displays

View File

@@ -987,24 +987,6 @@ public final class DisplayManager {
return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null);
}
/**
* Creates a virtual display.
*
* @see #createVirtualDisplay(String, int, int, int, float, Surface, int,
* Handler, VirtualDisplay.Callback)
*/
@Nullable
public VirtualDisplay createVirtualDisplay(@NonNull String name,
@IntRange(from = 1) int width,
@IntRange(from = 1) int height,
@IntRange(from = 1) int densityDpi,
float requestedRefreshRate,
@Nullable Surface surface,
@VirtualDisplayFlag int flags) {
return createVirtualDisplay(name, width, height, densityDpi, requestedRefreshRate,
surface, flags, null, null);
}
/**
* Creates a virtual display.
* <p>
@@ -1056,8 +1038,23 @@ public final class DisplayManager {
@VirtualDisplayFlag int flags,
@Nullable VirtualDisplay.Callback callback,
@Nullable Handler handler) {
return createVirtualDisplay(name, width, height, densityDpi, 0.0f, surface,
flags, handler, callback);
final VirtualDisplayConfig.Builder builder =
new VirtualDisplayConfig.Builder(name, width, height, densityDpi);
builder.setFlags(flags);
if (surface != null) {
builder.setSurface(surface);
}
return createVirtualDisplay(builder.build(), handler, callback);
}
/**
* Creates a virtual display.
*
* @see #createVirtualDisplay(VirtualDisplayConfig, Handler, VirtualDisplay.Callback)
*/
@Nullable
public VirtualDisplay createVirtualDisplay(@NonNull VirtualDisplayConfig config) {
return createVirtualDisplay(config, /*handler=*/null, /*callback=*/null);
}
/**
@@ -1084,21 +1081,7 @@ public final class DisplayManager {
* turning off the screen.
* </p>
*
* @param name The name of the virtual display, must be non-empty.
* @param width The width of the virtual display in pixels, must be greater than 0.
* @param height The height of the virtual display in pixels, must be greater than 0.
* @param densityDpi The density of the virtual display in dpi, must be greater than 0.
* @param requestedRefreshRate The requested refresh rate in frames per second.
* For best results, specify a divisor of the physical refresh rate, e.g., 30 or 60 on
* 120hz display. If an arbitrary refresh rate is specified, the rate will be rounded
* up or down to a divisor of the physical display. If 0 is specified, the virtual
* display is refreshed at the physical display refresh rate.
* @param surface The surface to which the content of the virtual display should
* be rendered, or null if there is none initially.
* @param flags A combination of virtual display flags:
* {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION},
* {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
* or {@link #VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
* @param config The configuration of the virtual display, must be non-null.
* @param handler The handler on which the listener should be invoked, or null
* if the listener should be invoked on the calling thread's looper.
* @param callback Callback to call when the state of the {@link VirtualDisplay} changes
@@ -1106,33 +1089,14 @@ public final class DisplayManager {
* not create the virtual display.
*
* @throws SecurityException if the caller does not have permission to create
* a virtual display with the specified flags.
* a virtual display with flags specified in the configuration.
*/
@Nullable
public VirtualDisplay createVirtualDisplay(@NonNull String name,
@IntRange(from = 1) int width,
@IntRange(from = 1) int height,
@IntRange(from = 1) int densityDpi,
float requestedRefreshRate,
@Nullable Surface surface,
@VirtualDisplayFlag int flags,
public VirtualDisplay createVirtualDisplay(
@NonNull VirtualDisplayConfig config,
@Nullable Handler handler,
@Nullable VirtualDisplay.Callback callback) {
if (!ENABLE_VIRTUAL_DISPLAY_REFRESH_RATE && requestedRefreshRate != 0.0f) {
Slog.e(TAG, "Please turn on ENABLE_VIRTUAL_DISPLAY_REFRESH_RATE to use the new api");
return null;
}
final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(name, width,
height, densityDpi);
builder.setFlags(flags);
if (surface != null) {
builder.setSurface(surface);
}
if (requestedRefreshRate != 0.0f) {
builder.setRequestedRefreshRate(requestedRefreshRate);
}
return createVirtualDisplay(null /* projection */, builder.build(), callback, handler,
return createVirtualDisplay(null /* projection */, config, callback, handler,
null /* windowContext */);
}

View File

@@ -18,121 +18,44 @@ package android.hardware.display;
import static android.view.Display.DEFAULT_DISPLAY;
import android.annotation.FloatRange;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.display.DisplayManager.VirtualDisplayFlag;
import android.media.projection.MediaProjection;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.Display;
import android.view.Surface;
import com.android.internal.util.DataClass;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Holds configuration used to create {@link VirtualDisplay} instances. See
* {@link MediaProjection#createVirtualDisplay} and
* {@link android.companion.virtual.VirtualDeviceManager.VirtualDevice#createVirtualDisplay}.
* Holds configuration used to create {@link VirtualDisplay} instances.
*
* @hide
* @see DisplayManager#createVirtualDisplay(VirtualDisplayConfig, Handler, VirtualDisplay.Callback)
* @see MediaProjection#createVirtualDisplay
*/
@DataClass(genParcelable = true, genAidl = true, genBuilder = true)
public final class VirtualDisplayConfig implements Parcelable {
/**
* The name of the virtual display, must be non-empty.
*/
@NonNull
private String mName;
/**
* The width of the virtual display in pixels. Must be greater than 0.
*/
@IntRange(from = 1)
private int mWidth;
private final String mName;
private final int mWidth;
private final int mHeight;
private final int mDensityDpi;
private final int mFlags;
private final Surface mSurface;
private final String mUniqueId;
private final int mDisplayIdToMirror;
private final boolean mWindowManagerMirroring;
private ArrayList<String> mDisplayCategories = null;
private final float mRequestedRefreshRate;
/**
* The height of the virtual display in pixels. Must be greater than 0.
*/
@IntRange(from = 1)
private int mHeight;
/**
* The density of the virtual display in dpi. Must be greater than 0.
*/
@IntRange(from = 1)
private int mDensityDpi;
/**
* A combination of virtual display flags.
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PRESENTATION},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_SECURE},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
* or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
*/
@VirtualDisplayFlag
private int mFlags = 0;
/**
* The surface to which the content of the virtual display should be rendered, or null if
* there is none initially.
*/
@Nullable
private Surface mSurface = null;
/**
* The unique identifier for the display. Shouldn't be displayed to the user.
* @hide
*/
@Nullable
private String mUniqueId = null;
/**
* The id of the display that the virtual display should mirror, or
* {@link android.view.Display#DEFAULT_DISPLAY} if there is none initially.
*/
private int mDisplayIdToMirror = DEFAULT_DISPLAY;
/**
* Indicates if WindowManager is responsible for mirroring content to this VirtualDisplay, or
* if DisplayManager should record contents instead.
*/
private boolean mWindowManagerMirroring = false;
/**
* The display categories. If set, only corresponding activities from the same category can be
* shown on the display.
*/
@DataClass.PluralOf("displayCategory")
@NonNull private List<String> mDisplayCategories = new ArrayList<>();
/**
* The refresh rate of a virtual display in frames per second.
* If this value is non-zero, this is the requested refresh rate to set.
* If this value is zero, the system chooses a default refresh rate.
*/
private float mRequestedRefreshRate = 0.0f;
// Code below generated by codegen v1.0.23.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/display/VirtualDisplayConfig.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
@DataClass.Generated.Member
/* package-private */ VirtualDisplayConfig(
private VirtualDisplayConfig(
@NonNull String name,
@IntRange(from = 1) int width,
@IntRange(from = 1) int height,
@@ -142,219 +65,200 @@ public final class VirtualDisplayConfig implements Parcelable {
@Nullable String uniqueId,
int displayIdToMirror,
boolean windowManagerMirroring,
@NonNull List<String> displayCategories,
@NonNull ArrayList<String> displayCategories,
float requestedRefreshRate) {
this.mName = name;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mName);
this.mWidth = width;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mWidth,
"from", 1);
this.mHeight = height;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mHeight,
"from", 1);
this.mDensityDpi = densityDpi;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDensityDpi,
"from", 1);
this.mFlags = flags;
com.android.internal.util.AnnotationValidations.validate(
VirtualDisplayFlag.class, null, mFlags);
this.mSurface = surface;
this.mUniqueId = uniqueId;
this.mDisplayIdToMirror = displayIdToMirror;
this.mWindowManagerMirroring = windowManagerMirroring;
this.mDisplayCategories = displayCategories;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mDisplayCategories);
this.mRequestedRefreshRate = requestedRefreshRate;
// onConstructed(); // You can define this method to get a callback
mName = name;
mWidth = width;
mHeight = height;
mDensityDpi = densityDpi;
mFlags = flags;
mSurface = surface;
mUniqueId = uniqueId;
mDisplayIdToMirror = displayIdToMirror;
mWindowManagerMirroring = windowManagerMirroring;
mDisplayCategories = displayCategories;
mRequestedRefreshRate = requestedRefreshRate;
}
/**
* The name of the virtual display, must be non-empty.
* Returns the name of the virtual display.
*/
@DataClass.Generated.Member
public @NonNull String getName() {
@NonNull
public String getName() {
return mName;
}
/**
* The width of the virtual display in pixels. Must be greater than 0.
* Returns the width of the virtual display in pixels.
*/
@DataClass.Generated.Member
public @IntRange(from = 1) int getWidth() {
public int getWidth() {
return mWidth;
}
/**
* The height of the virtual display in pixels. Must be greater than 0.
* Returns the height of the virtual display in pixels.
*/
@DataClass.Generated.Member
public @IntRange(from = 1) int getHeight() {
public int getHeight() {
return mHeight;
}
/**
* The density of the virtual display in dpi. Must be greater than 0.
* Returns the density of the virtual display in dpi.
*/
@DataClass.Generated.Member
public @IntRange(from = 1) int getDensityDpi() {
public int getDensityDpi() {
return mDensityDpi;
}
/**
* A combination of virtual display flags.
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PRESENTATION},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_SECURE},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
* or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
* Returns the virtual display flags.
*
* @see Builder#setFlags
*/
@DataClass.Generated.Member
public @VirtualDisplayFlag int getFlags() {
public int getFlags() {
return mFlags;
}
/**
* The surface to which the content of the virtual display should be rendered, or null if
* there is none initially.
* Returns the surface to which the content of the virtual display should be rendered, if any.
*
* @see Builder#setSurface
*/
@DataClass.Generated.Member
public @Nullable Surface getSurface() {
@Nullable
public Surface getSurface() {
return mSurface;
}
/**
* The unique identifier for the display. Shouldn't be displayed to the user.
*
* Returns the unique identifier for the display. Shouldn't be displayed to the user.
* @hide
*/
@DataClass.Generated.Member
public @Nullable String getUniqueId() {
@Nullable
public String getUniqueId() {
return mUniqueId;
}
/**
* The id of the display that the virtual display should mirror, or
* {@link android.view.Display#DEFAULT_DISPLAY} if there is none initially.
* Returns the id of the display that the virtual display should mirror, or
* {@link android.view.Display#DEFAULT_DISPLAY} if there is none.
* @hide
*/
@DataClass.Generated.Member
public int getDisplayIdToMirror() {
return mDisplayIdToMirror;
}
/**
* Indicates if WindowManager is responsible for mirroring content to this VirtualDisplay, or
* Whether if WindowManager is responsible for mirroring content to this VirtualDisplay, or
* if DisplayManager should record contents instead.
* @hide
*/
@DataClass.Generated.Member
public boolean isWindowManagerMirroring() {
return mWindowManagerMirroring;
}
/**
* The display categories. If set, only corresponding activities from the same category can be
* shown on the display.
* Returns the display categories.
*
* @see Builder#setDisplayCategories
*/
@DataClass.Generated.Member
public @NonNull List<String> getDisplayCategories() {
return mDisplayCategories;
@NonNull
public List<String> getDisplayCategories() {
return Collections.unmodifiableList(mDisplayCategories);
}
/**
* The refresh rate of a virtual display in frames per second.
* If this value is none zero, this is the requested refresh rate to set.
* If this value is zero, the system chooses a default refresh rate.
* Returns the refresh rate of a virtual display in frames per second, or zero if it is using a
* default refresh rate chosen by the system.
*
* @see Builder#setRequestedRefreshRate
*/
@DataClass.Generated.Member
public float getRequestedRefreshRate() {
return mRequestedRefreshRate;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
int flg = 0;
if (mWindowManagerMirroring) flg |= 0x100;
if (mSurface != null) flg |= 0x20;
if (mUniqueId != null) flg |= 0x40;
dest.writeInt(flg);
dest.writeString(mName);
dest.writeString8(mName);
dest.writeInt(mWidth);
dest.writeInt(mHeight);
dest.writeInt(mDensityDpi);
dest.writeInt(mFlags);
if (mSurface != null) dest.writeTypedObject(mSurface, flags);
if (mUniqueId != null) dest.writeString(mUniqueId);
dest.writeTypedObject(mSurface, flags);
dest.writeString8(mUniqueId);
dest.writeInt(mDisplayIdToMirror);
dest.writeBoolean(mWindowManagerMirroring);
dest.writeStringList(mDisplayCategories);
dest.writeFloat(mRequestedRefreshRate);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ VirtualDisplayConfig(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
int flg = in.readInt();
boolean windowManagerMirroring = (flg & 0x100) != 0;
String name = in.readString();
int width = in.readInt();
int height = in.readInt();
int densityDpi = in.readInt();
int flags = in.readInt();
Surface surface = (flg & 0x20) == 0 ? null : (Surface) in.readTypedObject(Surface.CREATOR);
String uniqueId = (flg & 0x40) == 0 ? null : in.readString();
int displayIdToMirror = in.readInt();
List<String> displayCategories = new ArrayList<>();
in.readStringList(displayCategories);
float requestedRefreshRate = in.readFloat();
this.mName = name;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mName);
this.mWidth = width;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mWidth,
"from", 1);
this.mHeight = height;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mHeight,
"from", 1);
this.mDensityDpi = densityDpi;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDensityDpi,
"from", 1);
this.mFlags = flags;
com.android.internal.util.AnnotationValidations.validate(
VirtualDisplayFlag.class, null, mFlags);
this.mSurface = surface;
this.mUniqueId = uniqueId;
this.mDisplayIdToMirror = displayIdToMirror;
this.mWindowManagerMirroring = windowManagerMirroring;
this.mDisplayCategories = displayCategories;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mDisplayCategories);
this.mRequestedRefreshRate = requestedRefreshRate;
// onConstructed(); // You can define this method to get a callback
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof VirtualDisplayConfig)) {
return false;
}
VirtualDisplayConfig that = (VirtualDisplayConfig) o;
return Objects.equals(mName, that.mName)
&& mWidth == that.mWidth
&& mHeight == that.mHeight
&& mDensityDpi == that.mDensityDpi
&& mFlags == that.mFlags
&& Objects.equals(mSurface, that.mSurface)
&& Objects.equals(mUniqueId, that.mUniqueId)
&& mDisplayIdToMirror == that.mDisplayIdToMirror
&& mWindowManagerMirroring == that.mWindowManagerMirroring
&& Objects.equals(mDisplayCategories, that.mDisplayCategories)
&& mRequestedRefreshRate == that.mRequestedRefreshRate;
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<VirtualDisplayConfig> CREATOR
@Override
public int hashCode() {
int hashCode = Objects.hash(
mName, mWidth, mHeight, mDensityDpi, mFlags, mSurface, mUniqueId,
mDisplayIdToMirror, mWindowManagerMirroring, mDisplayCategories,
mRequestedRefreshRate);
return hashCode;
}
@Override
@NonNull
public String toString() {
return "VirtualDisplayConfig("
+ " mName=" + mName
+ " mHeight=" + mHeight
+ " mWidth=" + mWidth
+ " mDensityDpi=" + mDensityDpi
+ " mFlags=" + mFlags
+ " mSurface=" + mSurface
+ " mUniqueId=" + mUniqueId
+ " mDisplayIdToMirror=" + mDisplayIdToMirror
+ " mWindowManagerMirroring=" + mWindowManagerMirroring
+ " mDisplayCategories=" + mDisplayCategories
+ " mRequestedRefreshRate=" + mRequestedRefreshRate
+ ")";
}
private VirtualDisplayConfig(@NonNull Parcel in) {
mName = in.readString8();
mWidth = in.readInt();
mHeight = in.readInt();
mDensityDpi = in.readInt();
mFlags = in.readInt();
mSurface = in.readTypedObject(Surface.CREATOR);
mUniqueId = in.readString8();
mDisplayIdToMirror = in.readInt();
mWindowManagerMirroring = in.readBoolean();
mDisplayCategories = new ArrayList<>();
in.readStringList(mDisplayCategories);
mRequestedRefreshRate = in.readFloat();
}
@NonNull
public static final Parcelable.Creator<VirtualDisplayConfig> CREATOR
= new Parcelable.Creator<VirtualDisplayConfig>() {
@Override
public VirtualDisplayConfig[] newArray(int size) {
@@ -368,229 +272,161 @@ public final class VirtualDisplayConfig implements Parcelable {
};
/**
* A builder for {@link VirtualDisplayConfig}
* A builder for {@link VirtualDisplayConfig}.
*/
@SuppressWarnings("WeakerAccess")
@DataClass.Generated.Member
public static final class Builder {
private @NonNull String mName;
private @IntRange(from = 1) int mWidth;
private @IntRange(from = 1) int mHeight;
private @IntRange(from = 1) int mDensityDpi;
private @VirtualDisplayFlag int mFlags;
private @Nullable Surface mSurface;
private @Nullable String mUniqueId;
private int mDisplayIdToMirror;
private boolean mWindowManagerMirroring;
private @NonNull List<String> mDisplayCategories;
private float mRequestedRefreshRate;
private long mBuilderFieldsSet = 0L;
private final String mName;
private final int mWidth;
private final int mHeight;
private final int mDensityDpi;
private int mFlags = 0;
private Surface mSurface = null;
private String mUniqueId = null;
private int mDisplayIdToMirror = DEFAULT_DISPLAY;
private boolean mWindowManagerMirroring = false;
private ArrayList<String> mDisplayCategories = new ArrayList<>();
private float mRequestedRefreshRate = 0.0f;
/**
* Creates a new Builder.
*
* @param name
* The name of the virtual display, must be non-empty.
* @param width
* The width of the virtual display in pixels. Must be greater than 0.
* @param height
* The height of the virtual display in pixels. Must be greater than 0.
* @param densityDpi
* The density of the virtual display in dpi. Must be greater than 0.
* @param name The name of the virtual display, must be non-empty.
* @param width The width of the virtual display in pixels. Must be greater than 0.
* @param height The height of the virtual display in pixels. Must be greater than 0.
* @param densityDpi The density of the virtual display in dpi. Must be greater than 0.
*/
public Builder(
@NonNull String name,
@IntRange(from = 1) int width,
@IntRange(from = 1) int height,
@IntRange(from = 1) int densityDpi) {
if (name == null) {
throw new IllegalArgumentException("Virtual display name is required");
}
if (width <= 0) {
throw new IllegalArgumentException("Virtual display width must be positive");
}
if (height <= 0) {
throw new IllegalArgumentException("Virtual display height must be positive");
}
if (densityDpi <= 0) {
throw new IllegalArgumentException("Virtual display density must be positive");
}
mName = name;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mName);
mWidth = width;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mWidth,
"from", 1);
mHeight = height;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mHeight,
"from", 1);
mDensityDpi = densityDpi;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDensityDpi,
"from", 1);
}
/**
* The name of the virtual display, must be non-empty.
*/
@DataClass.Generated.Member
public @NonNull Builder setName(@NonNull String value) {
checkNotUsed();
mBuilderFieldsSet |= 0x1;
mName = value;
return this;
}
/**
* The width of the virtual display in pixels. Must be greater than 0.
*/
@DataClass.Generated.Member
public @NonNull Builder setWidth(@IntRange(from = 1) int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x2;
mWidth = value;
return this;
}
/**
* The height of the virtual display in pixels. Must be greater than 0.
*/
@DataClass.Generated.Member
public @NonNull Builder setHeight(@IntRange(from = 1) int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x4;
mHeight = value;
return this;
}
/**
* The density of the virtual display in dpi. Must be greater than 0.
*/
@DataClass.Generated.Member
public @NonNull Builder setDensityDpi(@IntRange(from = 1) int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x8;
mDensityDpi = value;
return this;
}
/**
* A combination of virtual display flags.
* Sets the virtual display flags, a combination of
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PRESENTATION},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_SECURE},
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY},
* or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}.
*/
@DataClass.Generated.Member
public @NonNull Builder setFlags(@VirtualDisplayFlag int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x10;
mFlags = value;
@NonNull
public Builder setFlags(@VirtualDisplayFlag int flags) {
mFlags = flags;
return this;
}
/**
* The surface to which the content of the virtual display should be rendered, or null if
* there is none initially.
*/
@DataClass.Generated.Member
public @NonNull Builder setSurface(@NonNull Surface value) {
checkNotUsed();
mBuilderFieldsSet |= 0x20;
mSurface = value;
return this;
}
/**
* The unique identifier for the display. Shouldn't be displayed to the user.
* Sets the surface to which the content of the virtual display should be rendered.
*
* <p>The surface can also be set after the display creation using
* {@link VirtualDisplay#setSurface(Surface)}.
*/
@NonNull
public Builder setSurface(@Nullable Surface surface) {
mSurface = surface;
return this;
}
/**
* Sets the unique identifier for the display.
* @hide
*/
@DataClass.Generated.Member
public @NonNull Builder setUniqueId(@NonNull String value) {
checkNotUsed();
mBuilderFieldsSet |= 0x40;
mUniqueId = value;
@NonNull
public Builder setUniqueId(@Nullable String uniqueId) {
mUniqueId = uniqueId;
return this;
}
/**
* The id of the display that the virtual display should mirror, or
* {@link android.view.Display#DEFAULT_DISPLAY} if there is none initially.
* Sets the id of the display that the virtual display should mirror.
* @hide
*/
@DataClass.Generated.Member
public @NonNull Builder setDisplayIdToMirror(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x80;
mDisplayIdToMirror = value;
@NonNull
public Builder setDisplayIdToMirror(int displayIdToMirror) {
mDisplayIdToMirror = displayIdToMirror;
return this;
}
/**
* Indicates if WindowManager is responsible for mirroring content to this VirtualDisplay, or
* if DisplayManager should record contents instead.
* Sets whether WindowManager is responsible for mirroring content to this VirtualDisplay.
* If unset or false, DisplayManager should record contents instead.
* @hide
*/
@DataClass.Generated.Member
public @NonNull Builder setWindowManagerMirroring(boolean value) {
checkNotUsed();
mBuilderFieldsSet |= 0x100;
mWindowManagerMirroring = value;
@NonNull
public Builder setWindowManagerMirroring(boolean windowManagerMirroring) {
mWindowManagerMirroring = windowManagerMirroring;
return this;
}
/**
* The display categories. If set, only corresponding activities from the same category can be
* shown on the display.
* Sets the display categories.
*
* <p>The categories of the display indicate the type of activities allowed to run on that
* display. Activities can declare a display category using
* {@link android.content.pm.ActivityInfo#requiredDisplayCategory}.
*/
@DataClass.Generated.Member
public @NonNull Builder setDisplayCategories(@NonNull List<String> value) {
checkNotUsed();
mBuilderFieldsSet |= 0x200;
mDisplayCategories = value;
return this;
}
/** @see #setDisplayCategories */
@DataClass.Generated.Member
public @NonNull Builder addDisplayCategory(@NonNull String value) {
if (mDisplayCategories == null) setDisplayCategories(new ArrayList<>());
mDisplayCategories.add(value);
@NonNull
public Builder setDisplayCategories(@NonNull List<String> displayCategories) {
mDisplayCategories.clear();
mDisplayCategories.addAll(Objects.requireNonNull(displayCategories));
return this;
}
/**
* The refresh rate of a virtual display in frames per second.
* If this value is none zero, this is the requested refresh rate to set.
* If this value is zero, the system chooses a default refresh rate.
* Adds a display category.
*
* @see #setDisplayCategories
*/
@DataClass.Generated.Member
public @NonNull Builder setRequestedRefreshRate(float value) {
checkNotUsed();
mBuilderFieldsSet |= 0x400;
mRequestedRefreshRate = value;
@NonNull
public Builder addDisplayCategory(@NonNull String displayCategory) {
mDisplayCategories.add(Objects.requireNonNull(displayCategory));
return this;
}
/** Builds the instance. This builder should not be touched after calling this! */
public @NonNull VirtualDisplayConfig build() {
checkNotUsed();
mBuilderFieldsSet |= 0x800; // Mark builder used
/**
* Sets the refresh rate of a virtual display in frames per second.
*
* <p>For best results, specify a divisor of the physical refresh rate, e.g., 30 or 60 on
* a 120hz display. If an arbitrary refresh rate is specified, the rate will be rounded up
* down to a divisor of the physical display. If unset or zero, the virtual display will be
* refreshed at the physical display refresh rate.
*
* @see Display#getRefreshRate()
*/
@NonNull
public Builder setRequestedRefreshRate(
@FloatRange(from = 0.0f) float requestedRefreshRate) {
if (requestedRefreshRate < 0.0f) {
throw new IllegalArgumentException(
"Virtual display requested refresh rate must be non-negative");
}
mRequestedRefreshRate = requestedRefreshRate;
return this;
}
if ((mBuilderFieldsSet & 0x10) == 0) {
mFlags = 0;
}
if ((mBuilderFieldsSet & 0x20) == 0) {
mSurface = null;
}
if ((mBuilderFieldsSet & 0x40) == 0) {
mUniqueId = null;
}
if ((mBuilderFieldsSet & 0x80) == 0) {
mDisplayIdToMirror = DEFAULT_DISPLAY;
}
if ((mBuilderFieldsSet & 0x100) == 0) {
mWindowManagerMirroring = false;
}
if ((mBuilderFieldsSet & 0x200) == 0) {
mDisplayCategories = new ArrayList<>();
}
if ((mBuilderFieldsSet & 0x400) == 0) {
mRequestedRefreshRate = 0.0f;
}
VirtualDisplayConfig o = new VirtualDisplayConfig(
/**
* Builds the {@link VirtualDisplayConfig} instance.
*/
@NonNull
public VirtualDisplayConfig build() {
return new VirtualDisplayConfig(
mName,
mWidth,
mHeight,
@@ -602,27 +438,6 @@ public final class VirtualDisplayConfig implements Parcelable {
mWindowManagerMirroring,
mDisplayCategories,
mRequestedRefreshRate);
return o;
}
private void checkNotUsed() {
if ((mBuilderFieldsSet & 0x800) != 0) {
throw new IllegalStateException(
"This Builder should not be reused. Use a new Builder instance instead");
}
}
}
@DataClass.Generated(
time = 1671047069703L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/hardware/display/VirtualDisplayConfig.java",
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\nprivate @com.android.internal.util.DataClass.PluralOf(\"displayCategory\") @android.annotation.NonNull java.util.List<java.lang.String> mDisplayCategories\nprivate float mRequestedRefreshRate\nclass VirtualDisplayConfig extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genParcelable=true, genAidl=true, genBuilder=true)")
@Deprecated
private void __metadata() {}
//@formatter:on
// End of generated code
}

View File

@@ -100,6 +100,14 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
private static final String TAG = "VirtualDeviceImpl";
private static final int DEFAULT_VIRTUAL_DISPLAY_FLAGS =
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
| DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT
| DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
| DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL
| DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH
| DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_FOCUS;
/**
* Timeout until {@link #launchPendingIntent} stops waiting for an activity to be launched.
*/
@@ -272,7 +280,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
* device.
*/
int getBaseVirtualDisplayFlags() {
int flags = 0;
int flags = DEFAULT_VIRTUAL_DISPLAY_FLAGS;
if (mParams.getLockState() == VirtualDeviceParams.LOCK_STATE_ALWAYS_UNLOCKED) {
flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED;
}