From 788462918638f9741c7db881f85cd96e094d9c16 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Thu, 2 May 2024 18:10:19 -0700 Subject: DM: Propagate uniqueID when creating virtual displays This is part of Trunk Stable effort to upstream SF-ARC screen record capabiliy (undiverging http://ag/20003031) which requires mirroring virtual displays to be associated with screen capture sessions using the package name within the unique ID. Creating virtual display with unique ID specified is optional such that it doesn't affect existing consumers who don't need it (i.e. av). Bug: 137375833 Bug: 194863377 Test: atest libsurfaceflinger_unittest Test: atest DisplayServiceTests Change-Id: Ib0b162511b08870aebb6a2229581290d16c47b5b --- .../java/com/android/server/display/DisplayControl.java | 15 ++++++++------- .../com/android/server/display/VirtualDisplayAdapter.java | 15 +++++++++------ .../jni/com_android_server_display_DisplayControl.cpp | 8 +++++--- .../android/server/display/DisplayManagerServiceTest.java | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/display/DisplayControl.java b/services/core/java/com/android/server/display/DisplayControl.java index 22f3bbd80a77..fa8299bd45fd 100644 --- a/services/core/java/com/android/server/display/DisplayControl.java +++ b/services/core/java/com/android/server/display/DisplayControl.java @@ -29,7 +29,7 @@ import java.util.Objects; */ public class DisplayControl { private static native IBinder nativeCreateDisplay(String name, boolean secure, - float requestedRefreshRate); + String uniqueId, float requestedRefreshRate); private static native void nativeDestroyDisplay(IBinder displayToken); private static native void nativeOverrideHdrTypes(IBinder displayToken, int[] modes); private static native long[] nativeGetPhysicalDisplayIds(); @@ -43,20 +43,21 @@ public class DisplayControl { /** * Create a display in SurfaceFlinger. * - * @param name The name of the display + * @param name The name of the display. * @param secure Whether this display is secure. * @return The token reference for the display in SurfaceFlinger. */ public static IBinder createDisplay(String name, boolean secure) { Objects.requireNonNull(name, "name must not be null"); - return nativeCreateDisplay(name, secure, 0.0f); + return nativeCreateDisplay(name, secure, "", 0.0f); } /** * Create a display in SurfaceFlinger. * - * @param name The name of the display + * @param name The name of the display. * @param secure Whether this display is secure. + * @param uniqueId The unique ID for the display. * @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 @@ -65,9 +66,10 @@ public class DisplayControl { * @return The token reference for the display in SurfaceFlinger. */ public static IBinder createDisplay(String name, boolean secure, - float requestedRefreshRate) { + String uniqueId, float requestedRefreshRate) { Objects.requireNonNull(name, "name must not be null"); - return nativeCreateDisplay(name, secure, requestedRefreshRate); + Objects.requireNonNull(uniqueId, "uniqueId must not be null"); + return nativeCreateDisplay(name, secure, uniqueId, requestedRefreshRate); } /** @@ -79,7 +81,6 @@ public class DisplayControl { if (displayToken == null) { throw new IllegalArgumentException("displayToken must not be null"); } - nativeDestroyDisplay(displayToken); } diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java index bcdb442c3ad3..a29e8523952d 100644 --- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java +++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java @@ -92,8 +92,9 @@ public class VirtualDisplayAdapter extends DisplayAdapter { Context context, Handler handler, Listener listener, DisplayManagerFlags featureFlags) { this(syncRoot, context, handler, listener, new SurfaceControlDisplayFactory() { @Override - public IBinder createDisplay(String name, boolean secure, float requestedRefreshRate) { - return DisplayControl.createDisplay(name, secure, requestedRefreshRate); + public IBinder createDisplay(String name, boolean secure, String uniqueId, + float requestedRefreshRate) { + return DisplayControl.createDisplay(name, secure, uniqueId, requestedRefreshRate); } @Override @@ -126,7 +127,7 @@ public class VirtualDisplayAdapter extends DisplayAdapter { String name = virtualDisplayConfig.getName(); boolean secure = (flags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0; - IBinder displayToken = mSurfaceControlDisplayFactory.createDisplay(name, secure, + IBinder displayToken = mSurfaceControlDisplayFactory.createDisplay(name, secure, uniqueId, virtualDisplayConfig.getRequestedRefreshRate()); MediaProjectionCallback mediaProjectionCallback = null; if (projection != null) { @@ -653,8 +654,9 @@ public class VirtualDisplayAdapter extends DisplayAdapter { /** * Create a virtual display in SurfaceFlinger. * - * @param name The name of the display + * @param name The name of the display. * @param secure Whether this display is secure. + * @param uniqueId The unique ID for the display. * @param requestedRefreshRate * The refresh rate, frames per second, to request on the virtual display. * It should be a divisor of refresh rate of the leader physical display @@ -663,8 +665,9 @@ public class VirtualDisplayAdapter extends DisplayAdapter { * the refresh rate of the leader physical display. * @return The token reference for the display in SurfaceFlinger. */ - IBinder createDisplay(String name, boolean secure, float requestedRefreshRate); - + IBinder createDisplay(String name, boolean secure, String uniqueId, + float requestedRefreshRate); + /** * Destroy a display in SurfaceFlinger. * diff --git a/services/core/jni/com_android_server_display_DisplayControl.cpp b/services/core/jni/com_android_server_display_DisplayControl.cpp index e65b9030195a..22c0f730ad7d 100644 --- a/services/core/jni/com_android_server_display_DisplayControl.cpp +++ b/services/core/jni/com_android_server_display_DisplayControl.cpp @@ -24,9 +24,11 @@ namespace android { static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, jboolean secure, - jfloat requestedRefreshRate) { - ScopedUtfChars name(env, nameObj); + jstring uniqueIdStr, jfloat requestedRefreshRate) { + const ScopedUtfChars name(env, nameObj); + const ScopedUtfChars uniqueId(env, uniqueIdStr); sp token(SurfaceComposerClient::createDisplay(String8(name.c_str()), bool(secure), + std::string(uniqueId.c_str()), requestedRefreshRate)); return javaObjectForIBinder(env, token); } @@ -178,7 +180,7 @@ static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong ph static const JNINativeMethod sDisplayMethods[] = { // clang-format off - {"nativeCreateDisplay", "(Ljava/lang/String;ZF)Landroid/os/IBinder;", + {"nativeCreateDisplay", "(Ljava/lang/String;ZLjava/lang/String;F)Landroid/os/IBinder;", (void*)nativeCreateDisplay }, {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V", (void*)nativeDestroyDisplay }, diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java index 869cec8d733d..7b1eaea13e34 100644 --- a/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java +++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java @@ -272,7 +272,7 @@ public class DisplayManagerServiceTest { return new VirtualDisplayAdapter(syncRoot, context, handler, displayAdapterListener, new VirtualDisplayAdapter.SurfaceControlDisplayFactory() { @Override - public IBinder createDisplay(String name, boolean secure, + public IBinder createDisplay(String name, boolean secure, String uniqueId, float requestedRefreshRate) { return mMockDisplayToken; } -- cgit v1.2.3-59-g8ed1b