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

Commit ab1a7193 authored by Kevin Jeon's avatar Kevin Jeon
Browse files

Move permission-by-UID check earlier

StartPackageManager during boot has a short flurry of binder activity,
which is caused by a per-package call to ActivityManager.getService().
ActivityManager.getService() only returns null at this stage in boot, so
moving up the root/system UID check to occur before getService() saves
some time.

Test: build, boot, verify boot time improvement
Bug: 383159377
Change-Id: I3f873e09f291c385d6844be87f4c211eab657dbe
parent 340592dd
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -1716,20 +1716,14 @@ public final class PermissionManager {

    private static int checkPermissionUncached(@Nullable String permission, int pid, int uid,
            int deviceId) {
        final IActivityManager am = ActivityManager.getService();
        if (am == null) {
            // Well this is super awkward; we somehow don't have an active ActivityManager
            // instance. If we're testing a root or system UID, then they totally have whatever
            // permission this is.
        final int appId = UserHandle.getAppId(uid);
        if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
                if (sShouldWarnMissingActivityManager) {
                    Slog.w(LOG_TAG, "Missing ActivityManager; assuming " + uid + " holds "
                            + permission);
                    sShouldWarnMissingActivityManager = false;
                }
            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
            // system, so we don't grant this permission.
            Slog.w(LOG_TAG, "Missing ActivityManager; assuming " + uid + " does not hold "
                    + permission);
            return PackageManager.PERMISSION_DENIED;