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

Commit 09a7f2df authored by Felipe Leme's avatar Felipe Leme
Browse files

Added new (hidden) UserManager API to get all users, including pre-created ones.

Bug: 140750212
Test: manual verification

Change-Id: Iaef9db6216a7b18bf6f1f3e19f4a7428ec99f1da
parent 16660951
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ interface IUserManager {
    void setUserIcon(int userHandle, in Bitmap icon);
    ParcelFileDescriptor getUserIcon(int userHandle);
    UserInfo getPrimaryUser();
    List<UserInfo> getUsers(boolean excludeDying);
    List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated);
    List<UserInfo> getProfiles(int userHandle, boolean enabledOnly);
    int[] getProfileIds(int userId, boolean enabledOnly);
    boolean canAddMoreManagedProfiles(int userHandle, boolean allowedToRemoveOne);
+21 −17
Original line number Diff line number Diff line
@@ -2389,15 +2389,26 @@ public class UserManager {
    /**
     * Returns information for all users on this device, including ones marked for deletion.
     * To retrieve only users that are alive, use {@link #getUsers(boolean)}.
     * <p>
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     *
     * @return the list of users that exist on the device.
     * @hide
     */
    @UnsupportedAppUsage
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public List<UserInfo> getUsers() {
        return getUsers(/* excludeDying= */ false);
    }

    /**
     * Returns information for all users on this device, based on the filtering parameters.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying,
            boolean excludePreCreated) {
        try {
            return mService.getUsers(false);
            return mService.getUsers(excludePartial, excludeDying, excludePreCreated);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
@@ -2413,16 +2424,12 @@ public class UserManager {
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public long[] getSerialNumbersOfUsers(boolean excludeDying) {
        try {
            List<UserInfo> users = mService.getUsers(excludeDying);
        List<UserInfo> users = getUsers(excludeDying);
        long[] result = new long[users.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = users.get(i).serialNumber;
        }
        return result;
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
@@ -2806,11 +2813,8 @@ public class UserManager {
     */
    @UnsupportedAppUsage
    public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
        try {
            return mService.getUsers(excludeDying);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
        return getUsers(/*excludePartial= */ true, excludeDying,
                /* excludePreCreated= */ true);
    }

    /**
+4 −2
Original line number Diff line number Diff line
@@ -663,12 +663,12 @@ public class UserManagerService extends IUserManager.Stub {
        return null;
    }

    @Override
    public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
        return getUsers(/*excludePartial= */ true, excludeDying, /* excludePreCreated= */ true);
    }

    private @NonNull List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying,
    @Override
    public @NonNull List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying,
            boolean excludePreCreated) {
        checkManageOrCreateUsersPermission("query users");
        synchronized (mUsersLock) {
@@ -2739,6 +2739,8 @@ public class UserManagerService extends IUserManager.Stub {
        Preconditions.checkArgument(!UserInfo.isManagedProfile(flags),
                "cannot pre-create managed profiles");

        Slog.i(LOG_TAG, "Pre-creating user with flags " + UserInfo.flagsToString(flags));

        return createUserInternalUnchecked(/* name= */ null, flags,
                /* parentId= */ UserHandle.USER_NULL, /* preCreate= */ true,
                /* disallowedPackages= */ null);