From 66e13bad4243bd0343d5e6051b62bb856824807b Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Fri, 4 Dec 2020 20:11:01 +0000 Subject: [PATCH] Use per-user Shell UID for adoptShellPermissionIdentity(). Previously we were delegating the per-user Shell's permission state and primary user Shell's app op state to the instrumentation, which is inconsistent. We should always delegate the per-user Shell's state. Bug: 170742504 Change-Id: I3773c2fe34f337f5790ba7d85647501a0f86522f Test: presubmit (cherry picked from commit e6fe4bc8c5e64627670c9cb1a8d3d53762098243) --- .../android/server/am/ActivityManagerService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 7acb1bf47e784..3f4878e380291 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -20195,10 +20195,11 @@ public class ActivityManagerService extends IActivityManager.Stub public int checkOperation(int code, int uid, String packageName, boolean raw, QuadFunction superImpl) { if (uid == mTargetUid && isTargetOp(code)) { + final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid), + Process.SHELL_UID); final long identity = Binder.clearCallingIdentity(); try { - return superImpl.apply(code, Process.SHELL_UID, - "com.android.shell", raw); + return superImpl.apply(code, shellUid, "com.android.shell", raw); } finally { Binder.restoreCallingIdentity(identity); } @@ -20210,10 +20211,11 @@ public class ActivityManagerService extends IActivityManager.Stub public int checkAudioOperation(int code, int usage, int uid, String packageName, QuadFunction superImpl) { if (uid == mTargetUid && isTargetOp(code)) { + final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid), + Process.SHELL_UID); final long identity = Binder.clearCallingIdentity(); try { - return superImpl.apply(code, usage, Process.SHELL_UID, - "com.android.shell"); + return superImpl.apply(code, usage, shellUid, "com.android.shell"); } finally { Binder.restoreCallingIdentity(identity); } @@ -20228,9 +20230,11 @@ public class ActivityManagerService extends IActivityManager.Stub @NonNull HeptFunction superImpl) { if (uid == mTargetUid && isTargetOp(code)) { + final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid), + Process.SHELL_UID); final long identity = Binder.clearCallingIdentity(); try { - return superImpl.apply(code, Process.SHELL_UID, "com.android.shell", featureId, + return superImpl.apply(code, shellUid, "com.android.shell", featureId, shouldCollectAsyncNotedOp, message, shouldCollectMessage); } finally { Binder.restoreCallingIdentity(identity);