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

Commit 54888446 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

UserManager.isUserTypeEnabled

Introduce hidden API for Settings to determine whether a given user type
is enabled, so that it knows not to show the option for creating users
of that type.

Bug: 192577100
Test: com.android.settings.users.UserSettingsTest
Change-Id: Ie99b0772dce3bb275aded0f6ef0404466a76b660
parent ac0a1235
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ interface IUserManager {
    List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated);
    List<UserInfo> getProfiles(int userId, boolean enabledOnly);
    int[] getProfileIds(int userId, boolean enabledOnly);
    boolean isUserTypeEnabled(in String userType);
    boolean canAddMoreUsersOfType(in String userType);
    boolean canAddMoreProfilesToUser(in String userType, int userId, boolean allowedToRemoveOne);
    boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne);
+19 −0
Original line number Diff line number Diff line
@@ -3927,6 +3927,25 @@ public class UserManager {
        }
    }

    /**
     * Checks whether this device supports users of the given user type.
     *
     * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_SECONDARY}.
     * @return true if the creation of users of the given user type is enabled on this device.
     * @hide
     */
    @RequiresPermission(anyOf = {
            android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.CREATE_USERS
    })
    public boolean isUserTypeEnabled(@NonNull String userType) {
        try {
            return mService.isUserTypeEnabled(userType);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Returns list of the profiles of userId including userId itself.
     * Note that this returns both enabled and not enabled profiles. See
+8 −0
Original line number Diff line number Diff line
@@ -2404,6 +2404,14 @@ public class UserManagerService extends IUserManager.Stub {
        return userTypeDetails != null && canAddMoreUsersOfType(userTypeDetails);
    }

    /** Returns whether the creation of users of the given user type is enabled on this device. */
    @Override
    public boolean isUserTypeEnabled(String userType) {
        checkManageOrCreateUsersPermission("check if user type is enabled.");
        final UserTypeDetails userTypeDetails = mUserTypes.get(userType);
        return userTypeDetails != null && userTypeDetails.isEnabled();
    }

    @Override
    public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
        return canAddMoreProfilesToUser(UserManager.USER_TYPE_PROFILE_MANAGED, userId,