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

Commit eb6705b8 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Fix native permission helper local call handling

getCallingUid() will return own uid if we're not executing any incoming
transactions. Such calls should pass without any further checks.

Test: cts-tradefed run cts-dev -m DevicePolicyManager --test
com.android.cts.devicepolicy.ManagedProfileTest#testBluetooth
Bug: 69284968
Change-Id: Iebfc53a7243c78b1182889c2f2aaf3393e30b282
parent 58cbe21a
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -48,20 +48,24 @@ Status checkPermission(const char* permission) {
}

bool isCallerActiveUser() {
  IPCThreadState* ipcState = IPCThreadState::self();
  IPCThreadState* ipcState = IPCThreadState::selfOrNull();
  if (!ipcState) return true;  // It's a local call

  uid_t callingUid = ipcState->getCallingUid();
  uid_t callingUser = callingUid / PER_USER_RANGE;
  if (!callingUid) return true;  // It's a local call
  if (callingUid == getuid()) return true;  // It's a local call

  return (foregroundUserId == callingUser) || (systemUiUid == callingUid) ||
         (SYSTEM_UID == callingUid);
}

bool isCallerActiveUserOrManagedProfile() {
  IPCThreadState* ipcState = IPCThreadState::self();
  IPCThreadState* ipcState = IPCThreadState::selfOrNull();
  if (!ipcState) return true;  // It's a local call

  uid_t callingUid = ipcState->getCallingUid();
  uid_t callingUser = callingUid / PER_USER_RANGE;
  // if (!callingUid) return true;  // It's a local call
  if (callingUid == getuid()) return true;  // It's a local call

  if ((foregroundUserId == callingUser) || (systemUiUid == callingUid) ||
      (SYSTEM_UID == callingUid))