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

Commit 371df46e authored by Vadim Caen's avatar Vadim Caen Committed by Android (Google) Code Review
Browse files

Merge "Dialog to record other displays" into main

parents cf501177 54fef98e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -56,6 +56,13 @@ interface IMediaProjection {
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    int getTaskId();


    /**
     * Returns the displayId identifying the display to record. This only applies to full screen
     * recording.
     */
    int getDisplayId();

    /**
     * Updates the {@link LaunchCookie} identifying the task to record.
     */
+3 −2
Original line number Diff line number Diff line
@@ -46,14 +46,15 @@ interface IMediaProjectionManager {
    boolean hasProjectionPermission(int processUid, String packageName);

    /**
     * Returns a new {@link IMediaProjection} instance associated with the given package.
     * Returns a new {@link IMediaProjection} instance associated with the given package for the
     * given display id.
     *
     * @param processUid the process UID as returned by {@link android.os.Process.myUid()}.
     */
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    IMediaProjection createProjection(int processUid, String packageName, int type,
            boolean permanentGrant);
            boolean permanentGrant, int displayId);

    /**
     * Returns the current {@link IMediaProjection} instance associated with the given
+13 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.media.projection;

import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.media.projection.flags.Flags.mediaProjectionConnectedDisplay;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.compat.CompatChanges;
@@ -85,13 +87,23 @@ public final class MediaProjection {
    public MediaProjection(Context context, IMediaProjection impl, DisplayManager displayManager) {
        mContext = context;
        mImpl = impl;
        mDisplayManager = displayManager;

        try {
            mImpl.start(new MediaProjectionCallback());

            if (mediaProjectionConnectedDisplay()) {
                int displayId = mImpl.getDisplayId();
                if (displayId != DEFAULT_DISPLAY) {
                    mDisplayId = displayId;
                    Log.v(TAG, "Created MediaProjection for display " + mDisplayId);
                    return;
                }
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Content Recording: Failed to start media projection", e);
            throw new RuntimeException("Failed to start media projection", e);
        }
        mDisplayManager = displayManager;

        final UserManager userManager = context.getSystemService(UserManager.class);
        mDisplayId = userManager.isVisibleBackgroundUsersSupported()
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.EnforcePermission;
import android.app.ActivityOptions.LaunchCookie;
import android.os.PermissionEnforcer;
import android.os.RemoteException;
import android.view.Display;

/**
 * The connection between MediaProjection and system server is represented by IMediaProjection;
@@ -32,6 +33,7 @@ public final class FakeIMediaProjection extends IMediaProjection.Stub {
    boolean mIsStarted = false;
    LaunchCookie mLaunchCookie = null;
    IMediaProjectionCallback mIMediaProjectionCallback = null;
    int mDisplayId = Display.DEFAULT_DISPLAY;

    FakeIMediaProjection(PermissionEnforcer enforcer) {
        super(enforcer);
@@ -93,6 +95,10 @@ public final class FakeIMediaProjection extends IMediaProjection.Stub {
        return mTaskId;
    }

    public int getDisplayId() {
        return mDisplayId;
    }

    @Override
    @EnforcePermission(MANAGE_MEDIA_PROJECTION)
    public void setLaunchCookie(LaunchCookie launchCookie) throws RemoteException {
+7 −0
Original line number Diff line number Diff line
@@ -310,6 +310,13 @@ public class RecordingServiceTest extends SysuiTestCase {
        verify(mNotificationManager).cancelAsUser(any(), anyInt(), any());
    }

    @Test
        public void testSecondaryDisplayRecording() throws IOException {
        Intent startIntent =
                RecordingService.getStartIntent(mContext, 0, 0, false, 200, null);
        assertEquals(startIntent.getIntExtra("extra_displayId", -1), 200);
    }

    private void assertUpdateState(boolean state) {
        // Then the state is set to not recording, and we cancel the notification
        // non SYSTEM user doesn't have the reference to the correct controller,
Loading