Add logic to use system server UID for noteOp call

Bug: 194285834
Test: Verify CHQTS pass on AIDL HAL
Change-Id: I76457a6f6108e4bd8f3b1bf49fdd7ef9e8611641
This commit is contained in:
Arthur Ishiguro
2021-09-16 09:08:22 -07:00
parent 72c5e35c1c
commit 5ef2bae3a4

View File

@@ -605,6 +605,9 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
for (String permission : permissions) {
int opCode = mAppOpsManager.permissionToOpCode(permission);
if (opCode != AppOpsManager.OP_NONE) {
// The noteOp call may check for required permissions. Use the below logic to ensure
// that the system server permission is enforced at the call.
long token = Binder.setCallingWorkSourceUid(android.os.Process.myUid());
try {
if (mAppOpsManager.noteOp(opCode, mUid, mPackage, mAttributionTag, noteMessage)
!= AppOpsManager.MODE_ALLOWED) {
@@ -614,6 +617,8 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
Log.e(TAG, "SecurityException: noteOp for pkg " + mPackage + " opcode "
+ opCode + ": " + e.getMessage());
return false;
} finally {
Binder.restoreCallingWorkSource(token);
}
}
}