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

Commit 742e559d authored by Daniel Akinola's avatar Daniel Akinola Committed by Android (Google) Code Review
Browse files

Merge "Stop active callbacks from being stopped on starting new projection...

Merge "Stop active callbacks from being stopped on starting new projection session" into udc-qpr-dev
parents b6c7f91c 9c037fb1
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -976,9 +976,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 = () -> {
@@ -1023,6 +1020,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++;
            }
+28 −0
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Tests for the {@link MediaProjectionManagerService} class.
 *
@@ -201,6 +204,29 @@ public class MediaProjectionManagerServiceTest {
        assertThat(secondProjection).isNotEqualTo(projection);
    }

    @Test
    public void testCreateProjection_priorProjectionGrant() throws
            NameNotFoundException, InterruptedException {
        // 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 first projection get stopped, but not the second projection.
        final int timeout = 5;
        boolean stoppedCallback1 = callback1.mLatch.await(timeout, TimeUnit.SECONDS);
        boolean stoppedCallback2 = callback2.mLatch.await(timeout, TimeUnit.SECONDS);

        assertThat(stoppedCallback1).isTrue();
        assertThat(stoppedCallback2).isFalse();
    }

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

    private static class FakeIMediaProjectionCallback extends IMediaProjectionCallback.Stub {
        CountDownLatch mLatch = new CountDownLatch(1);
        @Override
        public void onStop() throws RemoteException {
            mLatch.countDown();
        }

        @Override