Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02591181 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I76457a6f,I35c8a9c6

* changes:
  Add logic to use system server UID for noteOp call
  Catch exception when using noteOp in Context Hub Service
parents af659b46 5ef2bae3
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -605,10 +605,21 @@ 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) {
                        return false;
                    }
                } catch (SecurityException e) {
                    Log.e(TAG, "SecurityException: noteOp for pkg " + mPackage + " opcode "
                            + opCode + ": " + e.getMessage());
                    return false;
                } finally {
                    Binder.restoreCallingWorkSource(token);
                }
            }
        }