Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78846291 authored by Alan Ding's avatar Alan Ding
Browse files

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
parent 12e8651b
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -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);
    }

+9 −6
Original line number Diff line number Diff line
@@ -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,7 +665,8 @@ 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.
+5 −3
Original line number Diff line number Diff line
@@ -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<IBinder> 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 },
+1 −1
Original line number Diff line number Diff line
@@ -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;
                        }