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

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

Public isCommunalProfile() API

Introduces a public API for whether the context user is running in a
communal profile. This can be called without permission requirements,
provided that the context user is the caller.

Bug: 297103765
Test: atest android.multiuser.cts.UserManagerTest
Change-Id: I0fe47c107e114fb45ceeba672ef41dd4dcbdedb0
parent 57b127f7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33376,6 +33376,7 @@ package android.os {
    method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public android.os.Bundle getUserRestrictions(android.os.UserHandle);
    method public boolean hasUserRestriction(String);
    method public boolean isAdminUser();
    method @FlaggedApi("android.multiuser.support_communal_profile") public boolean isCommunalProfile();
    method public boolean isDemoUser();
    method public static boolean isHeadlessSystemUserMode();
    method public boolean isManagedProfile();
+1 −0
Original line number Diff line number Diff line
@@ -2356,6 +2356,7 @@ package android.os {
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.content.pm.UserInfo createUser(@Nullable String, @NonNull String, int);
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.content.pm.UserInfo> getAliveUsers();
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.os.UserHandle getBootUser();
    method @FlaggedApi("android.multiuser.support_communal_profile") @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public android.os.UserHandle getCommunalProfile();
    method public int getMainDisplayIdAssignedToUser();
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.Set<java.lang.String> getPreInstallableSystemPackages(@NonNull String);
    method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public String getUserType();
+31 −11
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.Manifest;
import android.accounts.AccountManager;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -2771,6 +2772,8 @@ public class UserManager {
     * Returns the designated "communal profile" of the device, or {@code null} if there is none.
     * @hide
     */
    @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE)
    @TestApi
    @RequiresPermission(anyOf = {
            Manifest.permission.MANAGE_USERS,
            Manifest.permission.CREATE_USERS,
@@ -2787,17 +2790,34 @@ public class UserManager {
        }
    }

    /**
     * Checks if the context user is running in a communal profile.
     *
     * A communal profile is a {@link #isProfile() profile}, but instead of being associated with a
     * particular parent user, it is communal to the device.
     *
     * @return whether the context user is a communal profile.
     */
    @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE)
    @UserHandleAware(
            requiresAnyOfPermissionsIfNotCallerProfileGroup = {
                    android.Manifest.permission.MANAGE_USERS,
                    android.Manifest.permission.QUERY_USERS,
                    android.Manifest.permission.INTERACT_ACROSS_USERS})
    public boolean isCommunalProfile() {
        return isCommunalProfile(mUserId);
    }

    /**
     * Returns {@code true} if the given user is the designated "communal profile" of the device.
     * @hide
     */
    @RequiresPermission(anyOf = {
            Manifest.permission.MANAGE_USERS,
            Manifest.permission.CREATE_USERS,
            Manifest.permission.QUERY_USERS})
    public boolean isCommunalProfile(@UserIdInt int userId) {
        final UserInfo user = getUserInfo(userId);
        return user != null && user.isCommunalProfile();
            android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.QUERY_USERS,
            android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
    private boolean isCommunalProfile(@UserIdInt int userId) {
        return isUserTypeCommunalProfile(getProfileType(userId));
    }

    /**
@@ -2994,7 +3014,7 @@ public class UserManager {
    }

    /**
     * Checks if the calling context user can have a restricted profile.
     * Checks if the context user can have a restricted profile.
     * @return whether the context user can have a restricted profile.
     * @hide
     */
@@ -3098,11 +3118,11 @@ public class UserManager {
    }

    /**
     * Checks if the calling context user is running in a profile. A profile is a user that
     * Checks if the context user is running in a profile. A profile is a user that
     * typically has its own separate data but shares its UI with some parent user. For example, a
     * {@link #isManagedProfile() managed profile} is a type of profile.
     *
     * @return whether the caller is in a profile.
     * @return whether the context user is in a profile.
     */
    @UserHandleAware(
            requiresAnyOfPermissionsIfNotCallerProfileGroup = {
@@ -5242,7 +5262,7 @@ public class UserManager {

    /**
     * Returns the parent of the profile which this method is called from
     * or null if called from a user that is not a profile.
     * or null if it has no parent (e.g. if it is not a profile).
     *
     * @hide
     */
@@ -5264,7 +5284,7 @@ public class UserManager {
     *
     * @param user the handle of the user profile
     *
     * @return the parent of the user or {@code null} if the user is not profile
     * @return the parent of the user or {@code null} if the user has no parent
     *
     * @hide
     */