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

Commit 11731b96 authored by Jared Duke's avatar Jared Duke
Browse files

Short-circuit PIC permission checks for system_server

While the PIC-based permission checks are relatively cheap when there's
a hit, they are unnecessary for checks against system_server. Hoist the
system_server permission bypass out of the cache, avoiding locks or
small temporary objects in the cache query for such cases.

Bug: 414189094
Bug: 416218069
Test: presubmit
Flag: EXEMPT trivial performance fix
Change-Id: I06f2ffb2a0cb552e9f5541432465c527d77d8b24
parent 67d95616
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -1701,10 +1701,6 @@ public final class PermissionManager {

    private static int checkPermissionUncached(@Nullable String permission, int pid, int uid,
            int deviceId) {
        final int appId = UserHandle.getAppId(uid);
        if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
            return PackageManager.PERMISSION_GRANTED;
        }
        final IActivityManager am = ActivityManager.getService();
        if (am == null) {
            // We don't have an active ActivityManager instance and the calling UID is not root or
@@ -1884,6 +1880,12 @@ public final class PermissionManager {

    /** @hide */
    public static int checkPermission(@Nullable String permission, int pid, int uid, int deviceId) {
        // Short-circuit the cache for unconditionally granted permissions. This was previously
        // behind the cache, but placing here avoids marginal cache query overhead in system server.
        final int appId = UserHandle.getAppId(uid);
        if (appId == Process.SYSTEM_UID || appId == Process.ROOT_UID) {
            return PackageManager.PERMISSION_GRANTED;
        }
        return sPermissionCache.query(new PermissionQuery(permission, pid, uid, deviceId));
    }