From 89e8322fd122919efd033f6b8499f07dcef4c1cd Mon Sep 17 00:00:00 2001 From: Naomi Musgrave Date: Wed, 29 Mar 2023 12:54:37 +0000 Subject: [PATCH] (1/N)[MediaProjection] Throw exception if token re-used Validate if the IMediaProjection token (representing the user's consent) is used to get more than one MediaProjection instance, or if client app is trying to invoke MediaProjection#createVirtualDisplay more than once. Throw an exception for target SDK U+. Follow-on CLs will: * Re-show the permission dialog for re-used consent, when the target SDk is below U. * Black out recording when waiting for consent Bug: 242833866 Test: atest FrameworksServicesTests:MediaProjectionManagerServiceTest Test: atest FrameworksServicesTests:DisplayManagerServiceTest Change-Id: I1fc7c9afde63ea1fc849015932a66b9321879fd9 --- .../media/projection/IMediaProjection.aidl | 22 + .../projection/IMediaProjectionManager.aidl | 27 +- .../media/projection/MediaProjection.java | 25 +- .../projection/MediaProjectionManager.java | 2 + .../projection/FakeIMediaProjection.java | 12 +- .../server/display/DisplayManagerService.java | 51 ++- .../MediaProjectionManagerService.java | 272 +++++++++-- .../android/server/wm/ContentRecorder.java | 3 + services/tests/servicestests/Android.bp | 1 + .../display/DisplayManagerServiceTest.java | 155 +++++-- .../MediaProjectionManagerServiceTest.java | 427 ++++++++++++++++++ 11 files changed, 887 insertions(+), 110 deletions(-) create mode 100644 services/tests/servicestests/src/com/android/server/media/projection/MediaProjectionManagerServiceTest.java diff --git a/media/java/android/media/projection/IMediaProjection.aidl b/media/java/android/media/projection/IMediaProjection.aidl index 5f7d636fdd1eb..e3829e6a30210 100644 --- a/media/java/android/media/projection/IMediaProjection.aidl +++ b/media/java/android/media/projection/IMediaProjection.aidl @@ -51,4 +51,26 @@ interface IMediaProjection { @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" + ".permission.MANAGE_MEDIA_PROJECTION)") void setLaunchCookie(in IBinder launchCookie); + + /** + * Returns {@code true} if this token is still valid. A token is valid as long as the token + * hasn't timed out before it was used, and the token is only used once. + * + *

If the {@link IMediaProjection} is not valid, then either throws an exception if the + * target SDK is at least {@code U}, or returns {@code false} for target SDK below {@code U}. + * + * @throws IllegalStateException If the caller's target SDK is at least {@code U} and the + * projection is not valid. + */ + @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" + + ".permission.MANAGE_MEDIA_PROJECTION)") + boolean isValid(); + + /** + * Sets that {@link MediaProjection#createVirtualDisplay} has been invoked with this token (it + * should only be called once). + */ + @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest" + + ".permission.MANAGE_MEDIA_PROJECTION)") + void notifyVirtualDisplayCreated(int displayId); } diff --git a/media/java/android/media/projection/IMediaProjectionManager.aidl b/media/java/android/media/projection/IMediaProjectionManager.aidl index c97265d4939dd..835e4c3ee4f60 100644 --- a/media/java/android/media/projection/IMediaProjectionManager.aidl +++ b/media/java/android/media/projection/IMediaProjectionManager.aidl @@ -44,6 +44,22 @@ interface IMediaProjectionManager { + ".permission.MANAGE_MEDIA_PROJECTION)") boolean isCurrentProjection(IMediaProjection projection); + /** + * Reshows the permisison dialog for the user to review consent they've already granted in + * the given projection instance. + * + *

Preconditions: + *