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

Commit 7144cbf7 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

isForegroundUserAdmin public API

Introduce an API by which callers can determine whether the foreground
user is an admin (even though the caller may not know who the foreground
user is). Foreground is synonymous with current.

Also adds an additional Flag for future communal development, where this
API is expected to be useful.

Test: atest android.multiuser.cts.UserManagerTest#testIsForegroundUserAdminUser_withAdditionalUser
Test: atest android.multiuser.cts.UserManagerTest#testIsForegroundUserAdminUser_admin
Change-Id: I2f2d74681b302a64991b11b32382558118ba798b
parent ec4ed104
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33378,6 +33378,7 @@ package android.os {
    method public boolean isAdminUser();
    method @FlaggedApi("android.multiuser.support_communal_profile") public boolean isCommunalProfile();
    method public boolean isDemoUser();
    method @FlaggedApi("android.multiuser.support_communal_profile_nextgen") public boolean isForegroundUserAdmin();
    method public static boolean isHeadlessSystemUserMode();
    method public boolean isManagedProfile();
    method public boolean isProfile();
+7 −0
Original line number Diff line number Diff line
@@ -28,3 +28,10 @@ flag {
    description: "Framework support for communal profile."
    bug: "285426179"
}

flag {
    name: "support_communal_profile_nextgen"
    namespace: "multiuser"
    description: "Further framework support for communal profile, beyond the basics, for later releases."
    bug: "285426179"
}
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ interface IUserManager {
    boolean isUserVisible(int userId);
    int[] getVisibleUsers();
    int getMainDisplayIdAssignedToUser();
    boolean isForegroundUserAdmin();
    boolean isUserNameSet(int userId);
    boolean hasRestrictedProfiles(int userId);
    boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target, int flags);
+17 −0
Original line number Diff line number Diff line
@@ -2856,6 +2856,23 @@ public class UserManager {
        return user != null && user.isAdmin();
    }

    /**
     * Used to check if the user currently running in the <b>foreground</b> is an
     * {@link #isAdminUser() admin} user.
     *
     * @return whether the foreground user is an admin user.
     * @see #isAdminUser()
     * @see #isUserForeground()
     */
    @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE_NEXTGEN)
    public boolean isForegroundUserAdmin() {
        try {
            return mService.isForegroundUserAdmin();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Returns whether the context user is of the given user type.
     *
+13 −0
Original line number Diff line number Diff line
@@ -2140,6 +2140,19 @@ public class UserManagerService extends IUserManager.Stub {
        return displayId;
    }

    @Override
    public boolean isForegroundUserAdmin() {
        // No permission requirements for this API.
        synchronized (mUsersLock) {
            final int currentUserId = getCurrentUserId();
            if (currentUserId != UserHandle.USER_NULL) {
                final UserInfo userInfo = getUserInfoLU(currentUserId);
                return userInfo != null && userInfo.isAdmin();
            }
        }
        return false;
    }

    @Override
    public @NonNull String getUserName() {
        final int callingUid = Binder.getCallingUid();