diff options
9 files changed, 47 insertions, 109 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index f462ccc57df3..81f210a1aafe 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -203,7 +203,6 @@ package android { field public static final String MANAGE_HOTWORD_DETECTION = "android.permission.MANAGE_HOTWORD_DETECTION"; field public static final String MANAGE_IPSEC_TUNNELS = "android.permission.MANAGE_IPSEC_TUNNELS"; field public static final String MANAGE_LOW_POWER_STANDBY = "android.permission.MANAGE_LOW_POWER_STANDBY"; - field @FlaggedApi("com.android.media.flags.limit_manage_media_projection") public static final String MANAGE_MEDIA_PROJECTION = "android.permission.MANAGE_MEDIA_PROJECTION"; field public static final String MANAGE_MUSIC_RECOGNITION = "android.permission.MANAGE_MUSIC_RECOGNITION"; field public static final String MANAGE_NOTIFICATION_LISTENERS = "android.permission.MANAGE_NOTIFICATION_LISTENERS"; field public static final String MANAGE_ONE_TIME_PERMISSION_SESSIONS = "android.permission.MANAGE_ONE_TIME_PERMISSION_SESSIONS"; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index cbe8307b6000..8c28753077c5 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -6902,13 +6902,10 @@ <permission android:name="android.permission.ACCESS_DRM_CERTIFICATES" android:protectionLevel="signature|privileged" /> - <!-- Allows an application to manage media projection sessions, by showing the permission dialog - to the user and creating a new token for each capture session. - @FlaggedApi("com.android.media.flags.limit_manage_media_projection") - @SystemApi Only granted to apps holding role SYSTEM_UI. + <!-- Api Allows an application to manage media projection sessions. @hide This is not a third-party API (intended for system apps). --> <permission android:name="android.permission.MANAGE_MEDIA_PROJECTION" - android:protectionLevel="internal|role" /> + android:protectionLevel="signature" /> <!-- @SystemApi Allows an application to read install sessions @hide This is not a third-party API (intended for system apps). --> diff --git a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java index 1546895e8df9..bbb19e351b5d 100644 --- a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java +++ b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java @@ -550,8 +550,8 @@ public final class MediaProjectionManagerService extends SystemService break; case RECORD_CONTENT_TASK: IBinder taskWindowContainerToken = - mProjectionGrant.getLaunchCookieInternal() == null ? null - : mProjectionGrant.getLaunchCookieInternal().binder; + mProjectionGrant.getLaunchCookie() == null ? null + : mProjectionGrant.getLaunchCookie().binder; setReviewedConsentSessionLocked( ContentRecordingSession.createTaskSession(taskWindowContainerToken)); break; @@ -603,17 +603,6 @@ public final class MediaProjectionManagerService extends SystemService return projection; } - /** - * Test API mirroring the types in the aidl interface for access outside the projection - * package. - */ - @VisibleForTesting - public IMediaProjection createProjectionInternal(int processUid, String packageName, int type, - boolean isPermanentGrant) { - return createProjectionInternal(processUid, packageName, type, isPermanentGrant, - Binder.getCallingUserHandle()); - } - // TODO(b/261563516): Remove internal method and test aidl directly, here and elsewhere. @VisibleForTesting MediaProjection getProjectionInternal(int uid, String packageName) { @@ -1203,10 +1192,6 @@ public final class MediaProjectionManagerService extends SystemService @Override // Binder call public void setLaunchCookie(LaunchCookie launchCookie) { setLaunchCookie_enforcePermission(); - setLaunchCookieInternal(launchCookie); - } - - @VisibleForTesting void setLaunchCookieInternal(LaunchCookie launchCookie) { mLaunchCookie = launchCookie; } @@ -1214,10 +1199,6 @@ public final class MediaProjectionManagerService extends SystemService @Override // Binder call public LaunchCookie getLaunchCookie() { getLaunchCookie_enforcePermission(); - return getLaunchCookieInternal(); - } - - @VisibleForTesting LaunchCookie getLaunchCookieInternal() { return mLaunchCookie; } @@ -1225,11 +1206,6 @@ public final class MediaProjectionManagerService extends SystemService @Override public boolean isValid() { isValid_enforcePermission(); - return isValidInternal(); - } - - @VisibleForTesting - boolean isValidInternal() { synchronized (mLock) { final long curMs = mClock.uptimeMillis(); final boolean hasTimedOut = curMs - mCreateTimeMs > mTimeoutMs; @@ -1260,11 +1236,6 @@ public final class MediaProjectionManagerService extends SystemService @Override public void notifyVirtualDisplayCreated(int displayId) { notifyVirtualDisplayCreated_enforcePermission(); - notifyVirtualDisplayCreatedInternal(displayId); - } - - @VisibleForTesting - void notifyVirtualDisplayCreatedInternal(int displayId) { synchronized (mLock) { mVirtualDisplayId = displayId; diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 25a5fca1432c..e7431723789d 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -6783,14 +6783,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp return mSandboxDisplayApis; } - /** - * For testing only; inject a ContentRecorder instance. - */ - @VisibleForTesting - void setContentRecorder(ContentRecorder contentRecorder) { - mContentRecorder = contentRecorder; - } - private ContentRecorder getContentRecorder() { if (mContentRecorder == null) { mContentRecorder = new ContentRecorder(this); diff --git a/services/tests/PackageManagerServiceTests/appenumeration/Android.bp b/services/tests/PackageManagerServiceTests/appenumeration/Android.bp index bd86fe22f8d0..f15e533fee2b 100644 --- a/services/tests/PackageManagerServiceTests/appenumeration/Android.bp +++ b/services/tests/PackageManagerServiceTests/appenumeration/Android.bp @@ -32,8 +32,6 @@ android_test { "androidx.test.runner", "truth", "Harrier", - "frameworks-base-testutils", - "services.core", ], platform_apis: true, certificate: "platform", diff --git a/services/tests/PackageManagerServiceTests/appenumeration/src/com/android/server/pm/test/appenumeration/AppEnumerationInternalTests.java b/services/tests/PackageManagerServiceTests/appenumeration/src/com/android/server/pm/test/appenumeration/AppEnumerationInternalTests.java index c615823f25aa..4012d8e4af96 100644 --- a/services/tests/PackageManagerServiceTests/appenumeration/src/com/android/server/pm/test/appenumeration/AppEnumerationInternalTests.java +++ b/services/tests/PackageManagerServiceTests/appenumeration/src/com/android/server/pm/test/appenumeration/AppEnumerationInternalTests.java @@ -16,36 +16,32 @@ package com.android.server.pm.test.appenumeration; +import static android.content.Context.MEDIA_PROJECTION_SERVICE; + import static com.android.compatibility.common.util.ShellUtils.runShellCommand; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.MockitoAnnotations.initMocks; - -import android.app.ActivityManagerInternal; import android.app.AppGlobals; import android.app.PendingIntent; import android.content.Context; import android.content.IntentSender; import android.content.pm.IPackageManager; import android.content.pm.ProviderInfo; +import android.media.projection.IMediaProjectionManager; import android.media.projection.MediaProjectionManager; import android.os.Process; +import android.os.ServiceManager; import android.os.UserHandle; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; -import com.android.internal.util.test.LocalServiceKeeperRule; -import com.android.server.media.projection.MediaProjectionManagerService; - import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import java.util.ArrayList; import java.util.List; @@ -77,17 +73,9 @@ public class AppEnumerationInternalTests { private IPackageManager mIPackageManager; - @Rule - public LocalServiceKeeperRule mLocalServiceKeeperRule = new LocalServiceKeeperRule(); - - @Mock private ActivityManagerInternal mActivityManagerInternal; - @Before public void setup() { - initMocks(this); mIPackageManager = AppGlobals.getPackageManager(); - mLocalServiceKeeperRule.overrideLocalService(ActivityManagerInternal.class, - mActivityManagerInternal); } @After @@ -181,11 +169,11 @@ public class AppEnumerationInternalTests { public void mediaProjectionManager_createProjection_canSeeForceQueryable() throws Exception { installPackage(SHARED_USER_APK_PATH, true /* forceQueryable */); - final Context context = InstrumentationRegistry.getInstrumentation().getContext(); - final MediaProjectionManagerService mediaProjectionManager = - new MediaProjectionManagerService(context); + final IMediaProjectionManager mediaProjectionManager = + IMediaProjectionManager.Stub.asInterface( + ServiceManager.getService(MEDIA_PROJECTION_SERVICE)); - assertThat(mediaProjectionManager.createProjectionInternal(0 /* uid */, TARGET_SHARED_USER, + assertThat(mediaProjectionManager.createProjection(0 /* uid */, TARGET_SHARED_USER, MediaProjectionManager.TYPE_SCREEN_CAPTURE, false /* permanentGrant */)) .isNotNull(); } @@ -193,13 +181,12 @@ public class AppEnumerationInternalTests { @Test public void mediaProjectionManager_createProjection_cannotSeeTarget() { installPackage(SHARED_USER_APK_PATH, false /* forceQueryable */); - final Context context = InstrumentationRegistry.getInstrumentation().getContext(); - final MediaProjectionManagerService mediaProjectionManager = - new MediaProjectionManagerService(context); + final IMediaProjectionManager mediaProjectionManager = + IMediaProjectionManager.Stub.asInterface( + ServiceManager.getService(MEDIA_PROJECTION_SERVICE)); Assert.assertThrows(IllegalArgumentException.class, - () -> mediaProjectionManager.createProjectionInternal(0 /* uid */, - TARGET_SHARED_USER, + () -> mediaProjectionManager.createProjection(0 /* uid */, TARGET_SHARED_USER, MediaProjectionManager.TYPE_SCREEN_CAPTURE, false /* permanentGrant */)); } diff --git a/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java index aefa6de9184a..abd3abee82fb 100644 --- a/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java @@ -75,12 +75,12 @@ import androidx.test.filters.FlakyTest; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; -import com.android.internal.util.test.LocalServiceKeeperRule; +import com.android.server.LocalServices; import com.android.server.testutils.OffsettableClock; import com.android.server.wm.WindowManagerInternal; +import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -164,17 +164,15 @@ public class MediaProjectionManagerServiceTest { @Captor private ArgumentCaptor<ContentRecordingSession> mSessionCaptor; - @Rule - public LocalServiceKeeperRule mLocalServiceKeeperRule = new LocalServiceKeeperRule(); - @Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); when(mWatcherCallback.asBinder()).thenReturn(new Binder()); - mLocalServiceKeeperRule.overrideLocalService(ActivityManagerInternal.class, mAmInternal); - mLocalServiceKeeperRule.overrideLocalService(WindowManagerInternal.class, - mWindowManagerInternal); + LocalServices.removeServiceForTest(ActivityManagerInternal.class); + LocalServices.addService(ActivityManagerInternal.class, mAmInternal); + LocalServices.removeServiceForTest(WindowManagerInternal.class); + LocalServices.addService(WindowManagerInternal.class, mWindowManagerInternal); mContext = spy(new ContextWrapper( InstrumentationRegistry.getInstrumentation().getTargetContext())); @@ -189,6 +187,12 @@ public class MediaProjectionManagerServiceTest { mService = new MediaProjectionManagerService(mContext); } + @After + public void tearDown() { + LocalServices.removeServiceForTest(ActivityManagerInternal.class); + LocalServices.removeServiceForTest(WindowManagerInternal.class); + } + @Test public void testGetActiveProjectionInfoInternal() throws NameNotFoundException { assertThat(mService.getActiveProjectionInfo()).isNull(); @@ -384,16 +388,16 @@ public class MediaProjectionManagerServiceTest { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions( service); // No starts yet, and not timed out yet - so still valid. - assertThat(projection.isValidInternal()).isTrue(); + assertThat(projection.isValid()).isTrue(); // Only one start - so still valid. projection.start(mIMediaProjectionCallback); - assertThat(projection.isValidInternal()).isTrue(); + assertThat(projection.isValid()).isTrue(); // Second start - technically allowed to start again, without stopping in between. // Token should no longer be valid. projection.start(mIMediaProjectionCallback); - assertThat(projection.isValidInternal()).isFalse(); + assertThat(projection.isValid()).isFalse(); } @Test @@ -403,17 +407,17 @@ public class MediaProjectionManagerServiceTest { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions( service); // No starts yet, and not timed out yet - so still valid. - assertThat(projection.isValidInternal()).isTrue(); + assertThat(projection.isValid()).isTrue(); // Only one start - so still valid. projection.start(mIMediaProjectionCallback); - assertThat(projection.isValidInternal()).isTrue(); + assertThat(projection.isValid()).isTrue(); projection.stop(); // Second start - so not valid. projection.start(mIMediaProjectionCallback); - assertThat(projection.isValidInternal()).isFalse(); + assertThat(projection.isValid()).isFalse(); } @Test @@ -438,7 +442,7 @@ public class MediaProjectionManagerServiceTest { mClock.fastForward(projection.mDefaultTimeoutMs + 10); // Immediate timeout - so no longer valid. - assertThat(projection.isValidInternal()).isFalse(); + assertThat(projection.isValid()).isFalse(); } @Test @@ -448,10 +452,10 @@ public class MediaProjectionManagerServiceTest { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions( service); // Simulate MediaProjection#createVirtualDisplay being invoked previously. - projection.notifyVirtualDisplayCreatedInternal(10); + projection.notifyVirtualDisplayCreated(10); // Trying to re-use token on another MediaProjection#createVirtualDisplay - no longer valid. - assertThat(projection.isValidInternal()).isFalse(); + assertThat(projection.isValid()).isFalse(); } // TODO(269273190): Test flag using compat annotations instead. @@ -467,7 +471,7 @@ public class MediaProjectionManagerServiceTest { // Second start - so not valid. projection.start(mIMediaProjectionCallback); - assertThrows(SecurityException.class, projection::isValidInternal); + assertThrows(SecurityException.class, projection::isValid); } // TODO(269273190): Test flag using compat annotations instead. @@ -484,7 +488,7 @@ public class MediaProjectionManagerServiceTest { // Second start - so not valid. projection.start(mIMediaProjectionCallback); - assertThat(projection.isValidInternal()).isFalse(); + assertThat(projection.isValid()).isFalse(); } @Test @@ -623,7 +627,7 @@ public class MediaProjectionManagerServiceTest { mService.setUserReviewGrantedConsentResult(RECORD_CONTENT_DISPLAY, projection); // Virtual Display is finally created. - projection.notifyVirtualDisplayCreatedInternal(10); + projection.notifyVirtualDisplayCreated(10); verifySetSessionWithContent(ContentRecordingSession.RECORD_CONTENT_DISPLAY); } @@ -726,7 +730,7 @@ public class MediaProjectionManagerServiceTest { throws Exception { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions(); projection.start(mIMediaProjectionCallback); - projection.notifyVirtualDisplayCreatedInternal(10); + projection.notifyVirtualDisplayCreated(10); // Waiting for user to review consent. assertThat(mService.isCurrentProjection(projection)).isTrue(); doReturn(true).when(mWindowManagerInternal).setContentRecordingSession( @@ -781,9 +785,9 @@ public class MediaProjectionManagerServiceTest { @RecordContent int recordedContent) throws NameNotFoundException { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions(); - projection.setLaunchCookieInternal(new LaunchCookie()); + projection.setLaunchCookie(new LaunchCookie()); projection.start(mIMediaProjectionCallback); - projection.notifyVirtualDisplayCreatedInternal(10); + projection.notifyVirtualDisplayCreated(10); // Waiting for user to review consent. doReturn(true).when(mWindowManagerInternal).setContentRecordingSession( any(ContentRecordingSession.class)); @@ -804,7 +808,7 @@ public class MediaProjectionManagerServiceTest { throws NameNotFoundException { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions(); projection.start(mIMediaProjectionCallback); - projection.notifyVirtualDisplayCreatedInternal(10); + projection.notifyVirtualDisplayCreated(10); // Waiting for user to review consent. doReturn(true).when(mWindowManagerInternal).setContentRecordingSession( eq(mWaitingDisplaySession)); @@ -822,7 +826,7 @@ public class MediaProjectionManagerServiceTest { public void testSetUserReviewGrantedConsentResult_displayMirroring_noPriorSession() throws NameNotFoundException { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions(); - projection.setLaunchCookieInternal(new LaunchCookie()); + projection.setLaunchCookie(new LaunchCookie()); projection.start(mIMediaProjectionCallback); // Skip setting the prior session details. @@ -841,7 +845,7 @@ public class MediaProjectionManagerServiceTest { public void testSetUserReviewGrantedConsentResult_displayMirroring_sessionNotWaiting() throws NameNotFoundException { MediaProjectionManagerService.MediaProjection projection = startProjectionPreconditions(); - projection.setLaunchCookieInternal(new LaunchCookie()); + projection.setLaunchCookie(new LaunchCookie()); projection.start(mIMediaProjectionCallback); // Session is not waiting for user's consent. doReturn(true).when(mWindowManagerInternal).setContentRecordingSession( diff --git a/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java b/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java index 60dfe6f01817..887e5ee0c58a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ContentRecorderTests.java @@ -811,7 +811,7 @@ public class ContentRecorderTests extends WindowTestsBase { @Test public void testDisplayContentUpdatesRecording_withSurface() { - createContentRecorder(createDefaultDisplayInfo()); + defaultInit(); // GIVEN MediaProjection has already initialized the WindowToken of the DisplayArea to // mirror. setUpDefaultTaskDisplayAreaWindowToken(); @@ -820,7 +820,6 @@ public class ContentRecorderTests extends WindowTestsBase { // getDisplaySurfaceDefaultSize (done by surfaceControlMirrors in setUp). final DisplayContent virtualDisplay = mRootWindowContainer.getDisplayContent(mDisplaySession.getVirtualDisplayId()); - virtualDisplay.setContentRecorder(mContentRecorder); mWm.mContentRecordingController.setContentRecordingSessionLocked(mDisplaySession, mWm); virtualDisplay.updateRecording(); @@ -845,7 +844,6 @@ public class ContentRecorderTests extends WindowTestsBase { // WHEN getting the DisplayContent for the new virtual display. final DisplayContent virtualDisplay = mRootWindowContainer.getDisplayContent(mDisplaySession.getVirtualDisplayId()); - virtualDisplay.setContentRecorder(mContentRecorder); // Return the default display as the value to mirror to ensure the VD with flag mirroring // creates a ContentRecordingSession automatically. doReturn(DEFAULT_DISPLAY).when(mWm.mDisplayManagerInternal).getDisplayIdToMirror(anyInt()); diff --git a/services/tests/wmtests/src/com/android/server/wm/ContentRecordingControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/ContentRecordingControllerTests.java index 42004c365ba5..c84fe0871d3f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ContentRecordingControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ContentRecordingControllerTests.java @@ -24,7 +24,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import android.platform.test.annotations.Presubmit; @@ -32,8 +31,6 @@ import android.view.ContentRecordingSession; import androidx.test.filters.SmallTest; -import com.android.server.wm.ContentRecorder.MediaProjectionManagerWrapper; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -71,11 +68,6 @@ public class ContentRecordingControllerTests extends WindowTestsBase { mVirtualDisplayId = mVirtualDisplayContent.getDisplayId(); mWm.mRoot.onDisplayAdded(mVirtualDisplayId); spyOn(mVirtualDisplayContent); - final MediaProjectionManagerWrapper - mediaProjectionManagerWrapper = mock(MediaProjectionManagerWrapper.class); - final ContentRecorder contentRecorder = new ContentRecorder(mVirtualDisplayContent, - mediaProjectionManagerWrapper, /* correctForAnisotropicPixels= */ false); - mVirtualDisplayContent.setContentRecorder(contentRecorder); mDefaultSession.setVirtualDisplayId(mVirtualDisplayId); mWaitingDisplaySession.setVirtualDisplayId(mVirtualDisplayId); |