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

Commit d64181ce authored by Felipe Leme's avatar Felipe Leme
Browse files

Encapsulated access to isMainUserPermanentAdmin.

Currently, there's no API to access that info and its 2 clients
get the value directly from the framework resources, which make it
harder to "emulate" that property.

This CL encapsulates that config into
UserManagerInternal.isMainUserPermanentAdmin() and change the
existing clients to use it; a follow-up CL will change that method so
it can be emulated by a system property.

Test: atest FrameworksServicesTests:com.android.server.locksettings FrameworksServicesTests:UserManagerServiceShellCommandTest
Bug: 396232760
Flag: EXEMPT refactor

Change-Id: If894e769e986b90dce89ec7c69db95badeecfcc4
parent 974719fb
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.pm.UserProperties;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.sqlite.SQLiteDatabase;
import android.hardware.authsecret.IAuthSecret;
@@ -654,11 +653,6 @@ public class LockSettingsService extends ILockSettings.Stub {
        public boolean isHeadlessSystemUserMode() {
            return UserManager.isHeadlessSystemUserMode();
        }

        public boolean isMainUserPermanentAdmin() {
            return Resources.getSystem()
                    .getBoolean(com.android.internal.R.bool.config_isMainUserPermanentAdmin);
        }
    }

    private class SoftwareRateLimiterInjector implements SoftwareRateLimiter.Injector {
@@ -3003,7 +2997,8 @@ public class LockSettingsService extends ILockSettings.Stub {
                return;
            }
            authSecret = sp.deriveVendorAuthSecret();
        } else if (!mInjector.isMainUserPermanentAdmin() || !userInfo.isFull()) {
        } else if (!mInjector.getUserManagerInternal().isMainUserPermanentAdmin()
                || !userInfo.isFull()) {
            // Only full users can receive or pass on the auth secret.
            // If there is no main permanent admin user, we don't try to create or send
            // an auth secret, since there may sometimes be no full users.
+4 −4
Original line number Diff line number Diff line
@@ -78,13 +78,13 @@ public final class HsumBootUserInitializer {
    /** Static factory method for creating a {@link HsumBootUserInitializer} instance. */
    public static @Nullable HsumBootUserInitializer createInstance(UserManagerService ums,
            ActivityManagerService ams, PackageManagerService pms, ContentResolver contentResolver,
            boolean shouldAlwaysHaveMainUser, boolean shouldCreateInitialUser) {
            boolean shouldCreateInitialUser) {

        if (!UserManager.isHeadlessSystemUserMode()) {
            return null;
        }
        return new HsumBootUserInitializer(ums, ams, pms, contentResolver,
                shouldAlwaysHaveMainUser, shouldCreateInitialUser);
                ums.isMainUserPermanentAdmin(), shouldCreateInitialUser);
    }

    @VisibleForTesting
@@ -153,8 +153,8 @@ public final class HsumBootUserInitializer {
     */
    public void init(TimingsTraceAndSlog t) {
        if (DEBUG) {
            Slogf.d(TAG, "init(): shouldAlwaysHaveMainUser=%b, "
                    + "shouldCreateInitialUser=%b, Flags.createInitialUser=%b",
            Slogf.d(TAG, "init(): shouldAlwaysHaveMainUser=%b, shouldCreateInitialUser=%b, "
                    + "Flags.createInitialUser=%b",
                    mShouldAlwaysHaveMainUser, mShouldCreateInitialUser, Flags.createInitialUser());
        } else {
            Slogf.i(TAG, "Initializing");
+8 −0
Original line number Diff line number Diff line
@@ -582,6 +582,14 @@ public abstract class UserManagerInternal {
     */
    public abstract @UserIdInt int getMainUserId();

    /**
     * Returns the value of {@link com.android.internal.R.bool#config_isMainUserPermanentAdmin}.
     *
     * <p>If the main user is a permanent admin user it can't be deleted or downgraded to non-admin
     * status.
     */
    public abstract boolean isMainUserPermanentAdmin();

    /**
     * Returns the id of the user which should be in the foreground after boot completes.
     *
+14 −6
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ import android.util.Xml;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.SetScreenLockDialogActivity;
import com.android.internal.logging.MetricsLogger;
@@ -7944,6 +7945,9 @@ public class UserManagerService extends IUserManager.Stub {
            pw.println("  Can switch to headless system user: " + getSystemResources()
                    .getBoolean(com.android.internal.R.bool.config_canSwitchToHeadlessSystemUser));
        }

        pw.println("  Is main user permanent admin: " + isMainUserPermanentAdmin());

        pw.println("  User version: " + mUserVersion);
        pw.println("  Owner name: " + getOwnerName());
        pw.println("  Guest name: " + getGuestName());
@@ -8616,6 +8620,11 @@ public class UserManagerService extends IUserManager.Stub {
            return getMainUserIdUnchecked();
        }

        @Override
        public boolean isMainUserPermanentAdmin() {
            return UserManagerService.this.isMainUserPermanentAdmin();
        }

        @Override
        public @UserIdInt int getBootUser(boolean waitUntilSet)
                throws UserManager.CheckedUserOperationException {
@@ -8807,13 +8816,12 @@ public class UserManagerService extends IUserManager.Stub {
        return userInfo.isMain() && isMainUserPermanentAdmin();
    }

    /**
     * Returns true if {@link com.android.internal.R.bool#config_isMainUserPermanentAdmin} is true.
     * If the main user is a permanent admin user it can't be deleted
     * or downgraded to non-admin status.
     */
    /** Must be public otherwise can't be mocked. */
    @VisibleForTesting(visibility = Visibility.PACKAGE)
    public boolean isMainUserPermanentAdmin() {
        return getSystemResources().getBoolean(R.bool.config_isMainUserPermanentAdmin);
        boolean defaultValue = getSystemResources()
                .getBoolean(R.bool.config_isMainUserPermanentAdmin);
        return defaultValue;
    }

    /**
+0 −1
Original line number Diff line number Diff line
@@ -3043,7 +3043,6 @@ public final class SystemServer implements Dumpable {
        final HsumBootUserInitializer hsumBootUserInitializer =
                HsumBootUserInitializer.createInstance(mUserManagerService, mActivityManagerService,
                        mPackageManagerService, mContentResolver,
                        context.getResources().getBoolean(R.bool.config_isMainUserPermanentAdmin),
                        context.getResources().getBoolean(R.bool.config_createInitialUser)
                        );
        if (hsumBootUserInitializer != null) {
Loading