summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Songchun Fan <schfan@google.com> 2023-04-06 18:23:49 -0700
committer Song Chun Fan <schfan@google.com> 2023-04-07 01:29:35 +0000
commit98261b47d4761583d6a1689f46353a9d4db94d33 (patch)
treea7cbf023dbf44d804b4ffb9617aaed1f2b4e0980
parent2fad91a2b7e9774a28df801565bc051c656ebc6d (diff)
[MediaProjection] Fix package visibility check
getApplicationInfoAsUser should not be called after clearCallingIdentity, otherwise the package visibility restrictions are not applied. BUG: 276936135 Test: atest com.android.server.pm.test.appenumeration.AppEnumerationInternalTests#mediaProjectionManager_createProjection_cannotSeeTarget Change-Id: I4325bf55aee7a658dbf7d7c86be76fcb443331df Change-Id: I119fb86d0b1f06638e0d55aeebc1b092fd7a7f6b
-rw-r--r--services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java27
1 files changed, 12 insertions, 15 deletions
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 f0e8ede5987d..94d5aabe24e5 100644
--- a/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
+++ b/services/core/java/com/android/server/media/projection/MediaProjectionManagerService.java
@@ -357,12 +357,16 @@ public final class MediaProjectionManagerService extends SystemService
} catch (NameNotFoundException e) {
throw new IllegalArgumentException("No package matching :" + packageName);
}
-
- projection = new MediaProjection(type, uid, packageName, ai.targetSdkVersion,
- ai.isPrivilegedApp());
- if (isPermanentGrant) {
- mAppOps.setMode(AppOpsManager.OP_PROJECT_MEDIA,
- projection.uid, projection.packageName, AppOpsManager.MODE_ALLOWED);
+ final long callingToken = Binder.clearCallingIdentity();
+ try {
+ projection = new MediaProjection(type, uid, packageName, ai.targetSdkVersion,
+ ai.isPrivilegedApp());
+ if (isPermanentGrant) {
+ mAppOps.setMode(AppOpsManager.OP_PROJECT_MEDIA,
+ projection.uid, projection.packageName, AppOpsManager.MODE_ALLOWED);
+ }
+ } finally {
+ Binder.restoreCallingIdentity(callingToken);
}
return projection;
}
@@ -418,16 +422,9 @@ public final class MediaProjectionManagerService extends SystemService
if (packageName == null || packageName.isEmpty()) {
throw new IllegalArgumentException("package name must not be empty");
}
- MediaProjection projection;
final UserHandle callingUser = Binder.getCallingUserHandle();
- final long callingToken = Binder.clearCallingIdentity();
- try {
- projection = createProjectionInternal(uid, packageName, type, isPermanentGrant,
- callingUser, false);
- } finally {
- Binder.restoreCallingIdentity(callingToken);
- }
- return projection;
+ return createProjectionInternal(uid, packageName, type, isPermanentGrant,
+ callingUser, false);
}
@Override // Binder call