diff options
| author | Maurice Lam <yukl@google.com> | 2022-02-11 04:00:38 +0000 |
|---|---|---|
| committer | Shubham Dubey <dubeyshubham@google.com> | 2022-02-11 04:10:16 +0000 |
| commit | a343cdb58e1f1407c1eb014d9970c29cbb8a830b (patch) | |
| tree | 4a3c74d89c050c4059d79d5b285532bc84e196d8 /core/java/android | |
| parent | 1feb56be880a130cda191058b534c499e7d7f7bb (diff) | |
Revert "Add parameter annotations to createVirtualDisplay"
Revert "Update usage of VirtualDevice.createVirtualDisplay"
Revert submission 16788542-vdm-api-review
Reason for revert: Broke build
BUG: 218953698
Reverted Changes:
Iea9be6d6d:Update usage of VirtualDevice.createVirtualDisplay...
I3ff9fe54c:Update usage of VirtualDevice.createVirtualDisplay...
I3321927b3:Add parameter annotations to createVirtualDisplay
Change-Id: I22a345200d0dce57acdced1fc102e4631e659a44
Diffstat (limited to 'core/java/android')
4 files changed, 69 insertions, 100 deletions
diff --git a/core/java/android/companion/virtual/VirtualDeviceManager.java b/core/java/android/companion/virtual/VirtualDeviceManager.java index f1abb056da56..fdff27fb29f2 100644 --- a/core/java/android/companion/virtual/VirtualDeviceManager.java +++ b/core/java/android/companion/virtual/VirtualDeviceManager.java @@ -16,11 +16,10 @@ package android.companion.virtual; -import android.annotation.CallbackExecutor; -import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.SystemService; import android.app.Activity; @@ -32,7 +31,6 @@ import android.content.ComponentName; import android.content.Context; import android.graphics.Point; import android.hardware.display.DisplayManager; -import android.hardware.display.DisplayManager.VirtualDisplayFlag; import android.hardware.display.VirtualDisplay; import android.hardware.display.VirtualDisplayConfig; import android.hardware.input.VirtualKeyboard; @@ -48,7 +46,6 @@ import android.os.ResultReceiver; import android.util.ArrayMap; import android.view.Surface; -import java.util.Objects; import java.util.concurrent.Executor; /** @@ -213,22 +210,25 @@ public final class VirtualDeviceManager { * {@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 executor The executor on which {@code callback} will be invoked. This is ignored - * if {@code callback} is {@code null}. * @param callback Callback to call when the state of the {@link VirtualDisplay} changes + * @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. * @return The newly created virtual display, or {@code null} if the application could * not create the virtual display. * * @see DisplayManager#createVirtualDisplay */ + // Suppress "ExecutorRegistration" because DisplayManager.createVirtualDisplay takes a + // handler + @SuppressLint("ExecutorRegistration") @Nullable public VirtualDisplay createVirtualDisplay( - @IntRange(from = 1) int width, - @IntRange(from = 1) int height, - @IntRange(from = 1) int densityDpi, + int width, + int height, + int densityDpi, @Nullable Surface surface, - @VirtualDisplayFlag int flags, - @NonNull @CallbackExecutor Executor executor, + int flags, + @Nullable Handler handler, @Nullable VirtualDisplay.Callback callback) { // TODO(b/205343547): Handle display groups properly instead of creating a new display // group for every new virtual display created using this API. @@ -244,7 +244,7 @@ public final class VirtualDeviceManager { .setFlags(getVirtualDisplayFlags(flags)) .build(), callback, - Objects.requireNonNull(executor)); + handler); } /** diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java index 971b61bacd97..623f38e3f48b 100644 --- a/core/java/android/hardware/display/DisplayManager.java +++ b/core/java/android/hardware/display/DisplayManager.java @@ -22,7 +22,6 @@ import static android.view.Display.HdrCapabilities.HdrType; import android.Manifest; import android.annotation.FloatRange; import android.annotation.IntDef; -import android.annotation.IntRange; import android.annotation.LongDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -39,8 +38,6 @@ import android.graphics.Point; import android.media.projection.MediaProjection; import android.os.Build; import android.os.Handler; -import android.os.HandlerExecutor; -import android.os.Looper; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; @@ -51,7 +48,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executor; /** @@ -108,25 +104,6 @@ public final class DisplayManager { public static final String DISPLAY_CATEGORY_PRESENTATION = "android.hardware.display.category.PRESENTATION"; - /** @hide **/ - @IntDef(prefix = "VIRTUAL_DISPLAY_FLAG_", flag = true, value = { - VIRTUAL_DISPLAY_FLAG_PUBLIC, - VIRTUAL_DISPLAY_FLAG_PRESENTATION, - VIRTUAL_DISPLAY_FLAG_SECURE, - VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY, - VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, - VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD, - VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH, - VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT, - VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL, - VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS, - VIRTUAL_DISPLAY_FLAG_TRUSTED, - VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP, - VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED - }) - @Retention(RetentionPolicy.SOURCE) - public @interface VirtualDisplayFlag {} - /** * Virtual display flag: Create a public display. * @@ -843,11 +820,7 @@ public final class DisplayManager { * VirtualDisplay.Callback, Handler) */ public VirtualDisplay createVirtualDisplay(@NonNull String name, - @IntRange(from = 1) int width, - @IntRange(from = 1) int height, - @IntRange(from = 1) int densityDpi, - @Nullable Surface surface, - @VirtualDisplayFlag int flags) { + int width, int height, int densityDpi, @Nullable Surface surface, int flags) { return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null); } @@ -895,13 +868,8 @@ public final class DisplayManager { * a virtual display with the specified flags. */ public VirtualDisplay createVirtualDisplay(@NonNull String name, - @IntRange(from = 1) int width, - @IntRange(from = 1) int height, - @IntRange(from = 1) int densityDpi, - @Nullable Surface surface, - @VirtualDisplayFlag int flags, - @Nullable VirtualDisplay.Callback callback, - @Nullable Handler handler) { + int width, int height, int densityDpi, @Nullable Surface surface, int flags, + @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) { final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(name, width, height, densityDpi); builder.setFlags(flags); @@ -914,16 +882,9 @@ public final class DisplayManager { // TODO : Remove this hidden API after remove all callers. (Refer to MultiDisplayService) /** @hide */ - public VirtualDisplay createVirtualDisplay( - @Nullable MediaProjection projection, - @NonNull String name, - @IntRange(from = 1) int width, - @IntRange(from = 1) int height, - @IntRange(from = 1) int densityDpi, - @Nullable Surface surface, - @VirtualDisplayFlag int flags, - @Nullable VirtualDisplay.Callback callback, - @Nullable Handler handler, + public VirtualDisplay createVirtualDisplay(@Nullable MediaProjection projection, + @NonNull String name, int width, int height, int densityDpi, @Nullable Surface surface, + int flags, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler, @Nullable String uniqueId) { final VirtualDisplayConfig.Builder builder = new VirtualDisplayConfig.Builder(name, width, height, densityDpi); @@ -943,24 +904,16 @@ public final class DisplayManager { @NonNull VirtualDisplayConfig virtualDisplayConfig, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler, @Nullable Context windowContext) { - Executor executor = null; - // If callback is null, the executor will not be used. Avoid creating the handler and the - // handler executor. - if (callback != null) { - executor = new HandlerExecutor( - Handler.createAsync(handler != null ? handler.getLooper() : Looper.myLooper())); - } return mGlobal.createVirtualDisplay(mContext, projection, null /* virtualDevice */, - virtualDisplayConfig, callback, executor, windowContext); + virtualDisplayConfig, callback, handler, windowContext); } /** @hide */ public VirtualDisplay createVirtualDisplay(@Nullable IVirtualDevice virtualDevice, @NonNull VirtualDisplayConfig virtualDisplayConfig, - @Nullable VirtualDisplay.Callback callback, - @NonNull Executor executor) { + @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) { return mGlobal.createVirtualDisplay(mContext, null /* projection */, virtualDevice, - virtualDisplayConfig, callback, executor, null); + virtualDisplayConfig, callback, handler, null); } /** diff --git a/core/java/android/hardware/display/DisplayManagerGlobal.java b/core/java/android/hardware/display/DisplayManagerGlobal.java index 889100d0f242..7e7a64803dd9 100644 --- a/core/java/android/hardware/display/DisplayManagerGlobal.java +++ b/core/java/android/hardware/display/DisplayManagerGlobal.java @@ -56,8 +56,6 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.concurrent.Executor; /** * Manager communication with the display manager service on behalf of @@ -587,9 +585,8 @@ public final class DisplayManagerGlobal { public VirtualDisplay createVirtualDisplay(@NonNull Context context, MediaProjection projection, IVirtualDevice virtualDevice, @NonNull VirtualDisplayConfig virtualDisplayConfig, - VirtualDisplay.Callback callback, @Nullable Executor executor, - @Nullable Context windowContext) { - VirtualDisplayCallback callbackWrapper = new VirtualDisplayCallback(callback, executor); + VirtualDisplay.Callback callback, Handler handler, @Nullable Context windowContext) { + VirtualDisplayCallback callbackWrapper = new VirtualDisplayCallback(callback, handler); IMediaProjection projectionToken = projection != null ? projection.getProjection() : null; int displayId; try { @@ -1051,36 +1048,61 @@ public final class DisplayManagerGlobal { } private final static class VirtualDisplayCallback extends IVirtualDisplayCallback.Stub { - @Nullable private final VirtualDisplay.Callback mCallback; - @Nullable private final Executor mExecutor; + private VirtualDisplayCallbackDelegate mDelegate; - VirtualDisplayCallback(VirtualDisplay.Callback callback, Executor executor) { - mCallback = callback; - mExecutor = mCallback != null ? Objects.requireNonNull(executor) : null; + public VirtualDisplayCallback(VirtualDisplay.Callback callback, Handler handler) { + if (callback != null) { + mDelegate = new VirtualDisplayCallbackDelegate(callback, handler); + } } - // These methods are called from the binder thread, but the AIDL is oneway, so it should be - // safe to call the callback on arbitrary executors directly without risking blocking - // the system. - @Override // Binder call public void onPaused() { - if (mCallback != null) { - mExecutor.execute(mCallback::onPaused); + if (mDelegate != null) { + mDelegate.sendEmptyMessage(VirtualDisplayCallbackDelegate.MSG_DISPLAY_PAUSED); } } @Override // Binder call public void onResumed() { - if (mCallback != null) { - mExecutor.execute(mCallback::onResumed); + if (mDelegate != null) { + mDelegate.sendEmptyMessage(VirtualDisplayCallbackDelegate.MSG_DISPLAY_RESUMED); } } @Override // Binder call public void onStopped() { - if (mCallback != null) { - mExecutor.execute(mCallback::onStopped); + if (mDelegate != null) { + mDelegate.sendEmptyMessage(VirtualDisplayCallbackDelegate.MSG_DISPLAY_STOPPED); + } + } + } + + private final static class VirtualDisplayCallbackDelegate extends Handler { + public static final int MSG_DISPLAY_PAUSED = 0; + public static final int MSG_DISPLAY_RESUMED = 1; + public static final int MSG_DISPLAY_STOPPED = 2; + + private final VirtualDisplay.Callback mCallback; + + public VirtualDisplayCallbackDelegate(VirtualDisplay.Callback callback, + Handler handler) { + super(handler != null ? handler.getLooper() : Looper.myLooper(), null, true /*async*/); + mCallback = callback; + } + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_DISPLAY_PAUSED: + mCallback.onPaused(); + break; + case MSG_DISPLAY_RESUMED: + mCallback.onResumed(); + break; + case MSG_DISPLAY_STOPPED: + mCallback.onStopped(); + break; } } } diff --git a/core/java/android/hardware/display/VirtualDisplayConfig.java b/core/java/android/hardware/display/VirtualDisplayConfig.java index e292394c36ff..0e86f43207aa 100644 --- a/core/java/android/hardware/display/VirtualDisplayConfig.java +++ b/core/java/android/hardware/display/VirtualDisplayConfig.java @@ -21,7 +21,6 @@ import static android.view.Display.DEFAULT_DISPLAY; 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.IBinder; @@ -71,7 +70,6 @@ public final class VirtualDisplayConfig implements Parcelable { * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}, * or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. */ - @VirtualDisplayFlag private int mFlags = 0; /** @@ -122,7 +120,7 @@ public final class VirtualDisplayConfig implements Parcelable { @IntRange(from = 1) int width, @IntRange(from = 1) int height, @IntRange(from = 1) int densityDpi, - @VirtualDisplayFlag int flags, + int flags, @Nullable Surface surface, @Nullable String uniqueId, int displayIdToMirror, @@ -143,8 +141,6 @@ public final class VirtualDisplayConfig implements Parcelable { 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; @@ -194,7 +190,7 @@ public final class VirtualDisplayConfig implements Parcelable { * or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. */ @DataClass.Generated.Member - public @VirtualDisplayFlag int getFlags() { + public int getFlags() { return mFlags; } @@ -295,8 +291,6 @@ public final class VirtualDisplayConfig implements Parcelable { 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; @@ -330,7 +324,7 @@ public final class VirtualDisplayConfig implements Parcelable { private @IntRange(from = 1) int mWidth; private @IntRange(from = 1) int mHeight; private @IntRange(from = 1) int mDensityDpi; - private @VirtualDisplayFlag int mFlags; + private int mFlags; private @Nullable Surface mSurface; private @Nullable String mUniqueId; private int mDisplayIdToMirror; @@ -425,7 +419,7 @@ public final class VirtualDisplayConfig implements Parcelable { * or {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR}. */ @DataClass.Generated.Member - public @NonNull Builder setFlags(@VirtualDisplayFlag int value) { + public @NonNull Builder setFlags(int value) { checkNotUsed(); mBuilderFieldsSet |= 0x10; mFlags = value; @@ -523,10 +517,10 @@ public final class VirtualDisplayConfig implements Parcelable { } @DataClass.Generated( - time = 1643938791506L, + time = 1620657851981L, 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 @android.annotation.Nullable android.os.IBinder mWindowTokenClientToMirror\nclass VirtualDisplayConfig extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genParcelable=true, genAidl=true, genBuilder=true)") + 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 int mFlags\nprivate @android.annotation.Nullable android.view.Surface mSurface\nprivate @android.annotation.Nullable java.lang.String mUniqueId\nprivate int mDisplayIdToMirror\nprivate @android.annotation.Nullable android.os.IBinder mWindowTokenClientToMirror\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() {} |
