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

Commit 8fbf9d9f authored by Jessica Hummel's avatar Jessica Hummel Committed by The Android Automerger
Browse files

Add api for getting the parent of a profile.

Change-Id: Ife59665cdf6531a118d74def864c8cfc92c92a42
parent 08e5f4ae
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ interface IUserManager {
    Bitmap getUserIcon(int userHandle);
    List<UserInfo> getUsers(boolean excludeDying);
    List<UserInfo> getProfiles(int userHandle, boolean enabledOnly);
    UserInfo getProfileParent(int userHandle);
    UserInfo getUserInfo(int userHandle);
    boolean isRestricted();
    void setGuestEnabled(boolean enable);
+20 −3
Original line number Diff line number Diff line
@@ -269,7 +269,8 @@ public class UserManager {
    }

    /**
     * Returns the user handle for the user that this application is running for.
     * Returns the user handle for the user that the calling process is running on.
     *
     * @return the user handle of the user making this call.
     * @hide
     */
@@ -585,7 +586,8 @@ public class UserManager {
    }

    /**
     * Returns a list of UserHandles for profiles associated with this user, including this user.
     * Returns a list of UserHandles for profiles associated with the user that the calling process
     * is running on, including the user itself.
     *
     * @return A non-empty list of UserHandles associated with the calling user.
     */
@@ -605,6 +607,21 @@ public class UserManager {
        return profiles;
    }

    /**
     * Returns the parent of the profile which this method is called from
     * or null if called from a user that is not a profile.
     *
     * @hide
     */
    public UserInfo getProfileParent(int userHandle) {
        try {
            return mService.getProfileParent(userHandle);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not get profile parent", re);
            return null;
        }
    }

    /**
     * If the target user is a managed profile of the calling user or the caller
     * is itself a managed profile, then this returns a badged copy of the given
@@ -632,7 +649,7 @@ public class UserManager {

    private int getBadgeResIdForUser(int userHandle) {
        // Return the framework-provided badge.
        List<UserInfo> userProfiles = getProfiles(UserHandle.myUserId());
        List<UserInfo> userProfiles = getProfiles(getUserHandle());
        for (UserInfo user : userProfiles) {
            if (user.id == userHandle
                    && user.isManagedProfile()) {
+24 −21
Original line number Diff line number Diff line
@@ -288,6 +288,20 @@ public class UserManagerService extends IUserManager.Stub {
        return users;
    }

    @Override
    public UserInfo getProfileParent(int userHandle) {
        checkManageUsersPermission("get the profile parent");
        synchronized (mPackagesLock) {
            UserInfo profile = getUserInfoLocked(userHandle);
            int parentUserId = profile.profileGroupId;
            if (parentUserId == UserInfo.NO_PROFILE_GROUP_ID) {
                return null;
            } else {
                return getUserInfoLocked(parentUserId);
            }
        }
    }

    private boolean isProfileOf(UserInfo user, UserInfo profile) {
        return user.id == profile.id ||
                (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID
@@ -1015,17 +1029,6 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    private int getNextProfileGroupIdLocked() {
        int maxGroupId = UserInfo.NO_PROFILE_GROUP_ID;
        for (int i = 0; i < mUsers.size(); i++) {
            UserInfo ui = mUsers.valueAt(i);
            if (maxGroupId < ui.profileGroupId) {
                maxGroupId = ui.profileGroupId;
            }
        }
        return maxGroupId + 1;
    }

    @Override
    public UserInfo createProfileForUser(String name, int flags, int userId) {
        checkManageUsersPermission("Only the system can create users");
@@ -1042,16 +1045,16 @@ public class UserManagerService extends IUserManager.Stub {
        return createUserInternal(name, flags, UserHandle.USER_NULL);
    }

    private UserInfo createUserInternal(String name, int flags, int profileId) {
    private UserInfo createUserInternal(String name, int flags, int parentId) {
        final long ident = Binder.clearCallingIdentity();
        UserInfo userInfo = null;
        try {
            synchronized (mInstallLock) {
                synchronized (mPackagesLock) {
                    UserInfo profile = null;
                    if (profileId != UserHandle.USER_NULL) {
                        profile = getUserInfoLocked(profileId);
                        if (profile == null) return null;
                    UserInfo parent = null;
                    if (parentId != UserHandle.USER_NULL) {
                        parent = getUserInfoLocked(parentId);
                        if (parent == null) return null;
                    }
                    if (isUserLimitReachedLocked()) return null;
                    int userId = getNextAvailableIdLocked();
@@ -1064,12 +1067,12 @@ public class UserManagerService extends IUserManager.Stub {
                    Environment.getUserSystemDirectory(userInfo.id).mkdirs();
                    mUsers.put(userId, userInfo);
                    writeUserListLocked();
                    if (profile != null) {
                        if (profile.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
                            profile.profileGroupId = getNextProfileGroupIdLocked();
                            writeUserLocked(profile);
                    if (parent != null) {
                        if (parent.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
                            parent.profileGroupId = parent.id;
                            writeUserLocked(parent);
                        }
                        userInfo.profileGroupId = profile.profileGroupId;
                        userInfo.profileGroupId = parent.profileGroupId;
                    }
                    writeUserLocked(userInfo);
                    mPm.createNewUserLILPw(userId, userPath);