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

Commit 6eba5bb7 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Adding internal version of getUsers without permission check.

It's up to system-server to make sure it's doing the right thing.
-50ms create time for PM

Bug: 157191740
Test: adb reboot; adb logcat | grep -e PackageManagerTiming
Change-Id: I8b64164464fcc6447871cfb94475af7379b72c16
parent ec5a7038
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.server.pm.RestrictionsSet;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
 * @hide Only for use within the system server.
@@ -218,6 +219,13 @@ public abstract class UserManagerInternal {
     */
    public abstract int[] getUserIds();

    /**
     * Internal implementation of getUsers does not check permissions.
     * This improves performance for calls from inside system server which already have permissions
     * checked.
     */
    public abstract @NonNull List<UserInfo> getUsers(boolean excludeDying);

    /**
     * Checks if the {@code callingUserId} and {@code targetUserId} are same or in same group
     * and that the {@code callingUserId} is not a profile and {@code targetUserId} is enabled.
+3 −3
Original line number Diff line number Diff line
@@ -2988,7 +2988,7 @@ public class PackageManagerService extends IPackageManager.Stub
            t.traceEnd();
            t.traceBegin("read user settings");
            mFirstBoot = !mSettings.readLPw(mUserManager.getUsers(false));
            mFirstBoot = !mSettings.readLPw(mInjector.getUserManagerInternal().getUsers(false));
            t.traceEnd();
            // Clean up orphaned packages for which the code path doesn't exist
@@ -3431,7 +3431,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // boot, then we need to initialize the default preferred apps across
            // all defined users.
            if (!mOnlyCore && (mPromoteSystemApps || mFirstBoot)) {
                for (UserInfo user : mUserManager.getUsers(true)) {
                for (UserInfo user : mInjector.getUserManagerInternal().getUsers(true)) {
                    mSettings.applyDefaultPreferredAppsLPw(user.id);
                    primeDomainVerificationsLPw(user.id);
                }
@@ -22141,7 +22141,7 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        for (String packageName : apkList) {
            setSystemAppHiddenUntilInstalled(packageName, true);
            for (UserInfo user : mUserManager.getUsers(false)) {
            for (UserInfo user : mInjector.getUserManagerInternal().getUsers(false)) {
                setSystemAppInstallState(packageName, false, user.id);
            }
        }
+13 −1
Original line number Diff line number Diff line
@@ -751,13 +751,19 @@ public class UserManagerService extends IUserManager.Stub {
    }

    public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
        return getUsers(/*excludePartial= */ true, excludeDying, /* excludePreCreated= */ true);
        return getUsers(/*excludePartial= */ true, excludeDying, /* excludePreCreated= */
                true);
    }

    @Override
    public @NonNull List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying,
            boolean excludePreCreated) {
        checkManageOrCreateUsersPermission("query users");
        return getUsersInternal(excludePartial, excludeDying, excludePreCreated);
    }

    private @NonNull List<UserInfo> getUsersInternal(boolean excludePartial, boolean excludeDying,
            boolean excludePreCreated) {
        synchronized (mUsersLock) {
            ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size());
            final int userSize = mUsers.size();
@@ -5041,6 +5047,12 @@ public class UserManagerService extends IUserManager.Stub {
            return UserManagerService.this.getUserIds();
        }

        @Override
        public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
            return UserManagerService.this.getUsersInternal(/*excludePartial= */ true,
                    excludeDying, /* excludePreCreated= */ true);
        }

        @Override
        public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
            int state;