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

Commit 079e769d authored by Daniel Akinola's avatar Daniel Akinola Committed by Automerger Merge Worker
Browse files

Merge "Stop active MediaProjection callbacks before registering new callbacks"...

Merge "Stop active MediaProjection callbacks before registering new callbacks" into udc-qpr-dev am: 4beb9295

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24678379



Change-Id: Ia2413b85a3ae2d69a127db0123ad4cca56808c93
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b8b2ad02 4beb9295
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -975,9 +975,6 @@ public final class MediaProjectionManagerService extends SystemService
                    throw new SecurityException("Media projections require a foreground service"
                            + " of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION");
                }

                mCallback = callback;
                registerCallback(mCallback);
                try {
                    mToken = callback.asBinder();
                    mDeathEater = () -> {
@@ -1022,6 +1019,11 @@ public final class MediaProjectionManagerService extends SystemService
                    }
                }
                startProjectionLocked(this);

                // Register new callbacks after stop has been dispatched to previous session.
                mCallback = callback;
                registerCallback(mCallback);

                // Mark this token as used when the app gets the MediaProjection instance.
                mCountStarts++;
            }
+21 −0
Original line number Diff line number Diff line
@@ -201,6 +201,24 @@ public class MediaProjectionManagerServiceTest {
        assertThat(secondProjection).isNotEqualTo(projection);
    }

    @Test
    public void testCreateProjection_priorProjectionGrant() throws NameNotFoundException {
        // Create a first projection.
        MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions();
        FakeIMediaProjectionCallback callback1 = new FakeIMediaProjectionCallback();
        projection.start(callback1);

        // Create a second projection.
        MediaProjectionManagerService.MediaProjection secondProjection =
                startProjectionPreconditions();
        FakeIMediaProjectionCallback callback2 = new FakeIMediaProjectionCallback();
        secondProjection.start(callback2);

        // Check that the second projection's callback hasn't been stopped.
        assertThat(callback1.mStopped).isTrue();
        assertThat(callback2.mStopped).isFalse();
    }

    @Test
    public void testCreateProjection_attemptReuse_noPriorProjectionGrant()
            throws NameNotFoundException {
@@ -785,8 +803,11 @@ public class MediaProjectionManagerServiceTest {
    }

    private static class FakeIMediaProjectionCallback extends IMediaProjectionCallback.Stub {
        boolean mStopped = false;

        @Override
        public void onStop() throws RemoteException {
            mStopped = true;
        }

        @Override