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

Commit 85514cc4 authored by Adam Bookatz's avatar Adam Bookatz Committed by Android (Google) Code Review
Browse files

Merge "Max users only applies to switchable users" into main

parents 3e95c7ae f3043bf7
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -468,15 +468,23 @@ public class UserInfo implements Parcelable {
            // Don't support switching to pre-created users until they become "real" users.
            return false;
        }
        return isFull() || isSwitchableHeadlessSystemUser();
        return supportsSwitchTo(userType, flags);
    }

    /**
     * @return true if user is of type {@link UserManager#USER_TYPE_SYSTEM_HEADLESS} and
     * Returns whether the given user type, with the given base set of flags, can be switched to.
     * @hide
     */
    public static boolean supportsSwitchTo(String userType, @UserInfoFlag int flags) {
        return ((flags & UserInfo.FLAG_FULL) != 0) || isSwitchableHeadlessSystemUser(userType);
    }

    /**
     * Returns whether the userType is of type {@link UserManager#USER_TYPE_SYSTEM_HEADLESS} and
     * {@link com.android.internal.R.bool#config_canSwitchToHeadlessSystemUser} is true.
     */
    @android.ravenwood.annotation.RavenwoodThrow
    private boolean isSwitchableHeadlessSystemUser() {
    private static boolean isSwitchableHeadlessSystemUser(String userType) {
        return UserManager.USER_TYPE_SYSTEM_HEADLESS.equals(userType) && Resources.getSystem()
                .getBoolean(com.android.internal.R.bool.config_canSwitchToHeadlessSystemUser);
    }
+2 −2
Original line number Diff line number Diff line
@@ -39,9 +39,9 @@ flag {
}

flag {
    name: "consistent_max_users_including_guests"
    name: "decouple_max_users_from_profiles"
    namespace: "multiuser"
    description: "Builds on consistent_max_users, making Guest users included in the max."
    description: "Builds on consistent_max_users, but now config_multiuserMaximumUsers only applies to non-Guest non-Demo switchable users, not profiles."
    bug: "394178333"
}

+37 −22
Original line number Diff line number Diff line
@@ -2501,7 +2501,10 @@ public class UserManager {
    public static final int USER_OPERATION_ERROR_LOW_STORAGE = 5;

    /**
     * Indicates user operation failed because maximum user limit has been reached.
     * Indicates user operation failed because a relevant maximum user limit has been reached.
     *
     * <p>This could include the situation in which limit is 0, such as if a particular type of user
     * is not enabled or is ineligible to be added to the requested parent.
     */
    public static final int USER_OPERATION_ERROR_MAX_USERS = 6;

@@ -2703,14 +2706,14 @@ public class UserManager {
    }

    /**
     * Returns whether this device supports multiple users with their own login and customizable
     * space.
     * Returns whether this device supports multiple switchable users with their own login and
     * customizable space.
     * <p>Note that, even if false, multiple users might still be possible, as long as no login UI
     * is required; e.g., profiles might still be supported, as they do not require a login UI.
     * @return whether the device supports multiple switchable users.
     */
    public static boolean supportsMultipleUsers() {
        return getMaxSupportedUsers() > 1
        return getMaxSwitchableUsers() > 1
                && SystemProperties.getBoolean("fw.show_multiuserui",
                Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI));
    }
@@ -5409,10 +5412,10 @@ public class UserManager {
     * Returns how many users of the given type are currently allowed on the device, including ones
     * that already exist.
     *
     * Takes into account the maximum number of users allowed on the device (of that type, and in
     * general), as well as how many users of other types are already on the device (which thereby
     * already count towards the device maximum). Does not take into account UserRestrictions.
     * It is consistent with {@link #getRemainingCreatableUserCount(String)}.
     * Takes into account whether the user type is supported and maximum user limits, but does not
     * take into account UserRestrictions.
     * It is consistent with {@link #getRemainingCreatableUserCount(String)}, with the following
     * caveat:
     *
     * The value will be no less than the number of users of that type that currently exist (even if
     * that value exceeds the maximum allowed, for whatever reason).
@@ -5429,9 +5432,6 @@ public class UserManager {
            throw new UnsupportedOperationException("This method requires flag consistentMaxUsers");
        }
        try {
            // Note: If we get rid of the overall device max, this should be the same as
            // UMS.getMaxSupportedUsersOfType(). But even then it can still technically differ if
            // the max gets exceeded for any reason.
            return mService.getCurrentAllowedNumberOfUsers(userType);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
@@ -6546,22 +6546,37 @@ public class UserManager {
    }

    /**
     * Returns the maximum number of users (of any type) that can be created on this device.
     * A return value of 1 means that it is a single-user device.
     * @deprecated There is no longer a device-wide maximum number of users that includes all user
     *             types. This will instead return {@link #getMaxSwitchableUsers()}, which is a
     *             special combined limit set for switchable users.
     * @hide
     */
    // TODO(b/394178333): Switch all callers to getMaxSwitchableUsers().
    @Deprecated
    @UnsupportedAppUsage
    public static int getMaxSupportedUsers() {
        return getMaxSwitchableUsers();
    }

    /**
     * Returns the maximum number of (regular) switchable users that can be created on this device.
     * This includes the System user (unless it is a <i>non-interactive</i> headless system user),
     * Secondary users, and Restricted profiles, but excludes Guests and Demo users.
     * It does not include {@link #isProfile() profiles}, since they cannot be switched to.
     *
     * This value is based on the device's limitation of total number of users. This is typically
     * limited by storage considerations, not UX considerations (which depends on user type).
     * Note that this includes all types of users, including profile and guest users
     * (if {@link android.multiuser.Flags#consistentMaxUsersIncludingGuests()} is true).
     * This is typically the maximum possible number of users that can show up in a user switcher
     * (other than Guest users, which typically already occupy a spot even if no Guest is currently
     * on the device).
     *
     * Under very rare circumstances, the number of users on the device can exceed this amount
     * (such as if it were decreased during an OTA but more users had already been created).
     * A return value of 1 means that additional switchable users cannot be created.
     *
     * Under very rare circumstances, the number of switchable users on the device can exceed this
     * amount (such as if it were decreased during an OTA but more users had already been created).
     *
     * @return a value greater than or equal to 1
     * @hide
     */
    @UnsupportedAppUsage
    public static int getMaxSupportedUsers() {
    public static int getMaxSwitchableUsers() {
        return Math.max(1, SystemProperties.getInt("fw.max_users",
                Resources.getSystem().getInteger(R.integer.config_multiuserMaximumUsers)));
    }
@@ -6918,7 +6933,7 @@ public class UserManager {
                aliveUserCount++;
            }
        }
        return aliveUserCount < getMaxSupportedUsers();
        return aliveUserCount < getMaxSwitchableUsers();
    }

    /** Legacy version of {@link #canAddMoreUsers(String)}. Do not use. */
+20 −9
Original line number Diff line number Diff line
@@ -3173,15 +3173,18 @@
    <!-- The default value if the SyncStorageEngine should sync automatically or not -->
    <bool name="config_syncstorageengine_masterSyncAutomatically">true</bool>

    <!--  Maximum number of supported users, including all types of users (profiles, guests, demo,
          etc.).
          Setting to 1 enforces a single-user device.
          For devices that support multiple users, the limit here should be based on overall
          device storage capabilities and therefore could be set very high.
          To limit the number of any particular user type, e.g. for UX considerations, set the
    <!--  Maximum number of supported switchable users (excluding Guests & Demo users).
          Does not include profiles. See {@link UserManager#getMaxSwitchableUsers()} for details.

          Setting to 1 disables multiple switchable users (e.g. secondary users).

          To limit the number of any particular user type (whether switchable or not), set the
          appropriate maximum in {@link com.android.internal.R.xml#config_user_types}.
          Normally, storage shouldn't be the limiting factor, so this value should be at least as
          large as the sum of all individual user type maxima. -->

         Note: If > 1, it is expected that UserManager.USER_TYPE_FULL_SECONDARY users are supported
         on the device (at least for testing purposes, even if in practice the UI really only allows
         other switchable types, such as restricted profiles or guests, to be created).
         -->
    <integer name="config_multiuserMaximumUsers">1</integer>

    <!-- Maximum number of users we allow to be running at a time. -->
@@ -3280,7 +3283,15 @@
    headless system user can run in the foreground even though it is not a full user. -->
    <bool name="config_canSwitchToHeadlessSystemUser">false</bool>

    <!-- Whether UI for multi user should be shown -->
    <!-- Whether UI for multi user should be shown.
         Note: If true, it is expected that secondary users are supported on the device (at least
         for testing purposes, even if in practice the UI really only allows other switchable
         types, such as restricted profiles or guests, to be created).
         @deprecated  Use config_multiuserMaximumUsers instead.
         This config will likely be removed in the future; config_multiuserMaximumUsers, which now
         only applies to full users, not profiles, should be updated accordingly as needed.
         TODO(b/): Remove this since it is now made redundant by config_multiuserMaximumUsers.
         -->
    <bool name="config_enableMultiUserUI">false</bool>

    <!-- Indicates the boot strategy in Headless System User Mode (HSUM)
+4 −4
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ final class GenerationRegistry {
    private static final String DEFAULT_MAP_KEY_FOR_UNSET_SETTINGS = "";

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    // Minimum number of backing stores; supports 3 users
    static final int MIN_NUM_BACKING_STORE = 8;
    // Minimum number of backing stores; supports 7 users
    static final int MIN_NUM_BACKING_STORE = 16;
    // Maximum number of backing stores; supports 18 users
    static final int MAX_NUM_BACKING_STORE = 38;

@@ -81,10 +81,10 @@ final class GenerationRegistry {
    GenerationRegistry(int maxNumUsers) {
        // Add some buffer to maxNumUsers to accommodate corner cases when the actual number of
        // users in the system exceeds the limit
        maxNumUsers = maxNumUsers + 2;
        maxNumUsers = maxNumUsers + 6;
        // Number of backing stores needed for N users is (N + N + 1 + 1) = N * 2 + 2
        // N Secure backing stores and N System backing stores, 1 Config and 1 Global for all users
        // However, we always make sure that at least 3 users and at most 18 users are supported.
        // However, we always make sure that at least 7 users and at most 18 users are supported.
        mMaxNumBackingStore = Math.min(Math.max(maxNumUsers * 2 + 2, MIN_NUM_BACKING_STORE),
                MAX_NUM_BACKING_STORE);
    }
Loading