Merge changes I76457a6f,I35c8a9c6

* changes:
  Add logic to use system server UID for noteOp call
  Catch exception when using noteOp in Context Hub Service
This commit is contained in:
TreeHugger Robot
2021-09-17 01:08:37 +00:00
committed by Android (Google) Code Review

View File

@@ -605,9 +605,20 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
for (String permission : permissions) {
int opCode = mAppOpsManager.permissionToOpCode(permission);
if (opCode != AppOpsManager.OP_NONE) {
if (mAppOpsManager.noteOp(opCode, mUid, mPackage, mAttributionTag, noteMessage)
!= AppOpsManager.MODE_ALLOWED) {
// 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) {
return false;
}
} catch (SecurityException e) {
Log.e(TAG, "SecurityException: noteOp for pkg " + mPackage + " opcode "
+ opCode + ": " + e.getMessage());
return false;
} finally {
Binder.restoreCallingWorkSource(token);
}
}
}