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

Commit 316b5149 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Deprecated UserManager.getUsers(excludeDying) / added getAliveUsers()"

parents b0e58545 6dc6d2b9
Loading
Loading
Loading
Loading
+35 −9
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.pm.UserInfo;
import android.content.pm.UserInfo.UserInfoFlag;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -3174,28 +3173,55 @@ 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)}.
     * Returns information for all fully-created users on this device, including ones marked for
     * deletion.
     *
     * <p>To retrieve only users that are not marked for deletion, use {@link #getAliveUsers()}.
     *
     * <p>To retrieve *all* users (including partial and pre-created users), use
     * {@link #getUsers(boolean, boolean, boolean)) getUsers(false, false, false)}.
     *
     * <p>To retrieve a more specific list of users, use
     * {@link #getUsers(boolean, boolean, boolean)}.
     *
     * @return the list of users that were created.
     *
     * @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);
        return getUsers(/*excludePartial= */ true, /* excludeDying= */ false,
                /* excludePreCreated= */ true);
    }

    /**
     * Returns information for all users on this device. Requires
     * {@link android.Manifest.permission#MANAGE_USERS} permission.
     * Returns information for all "usable" users on this device (i.e, it excludes users that are
     * marked for deletion, pre-created users, etc...).
     *
     * <p>To retrieve all fully-created users, use {@link #getUsers()}.
     *
     * <p>To retrieve a more specific list of users, use
     * {@link #getUsers(boolean, boolean, boolean)}.
     *
     * @param excludeDying specify if the list should exclude users being
     *            removed.
     * @return the list of users that were created.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public @NonNull List<UserInfo> getAliveUsers() {
        return getUsers(/*excludePartial= */ true, /* excludeDying= */ true,
                /* excludePreCreated= */ true);
    }

    /**
     * @deprecated use {@link #getAliveUsers()} for {@code getUsers(true)}, or
     * {@link #getUsers()} for @code getUsers(false)}.
     *
     * @hide
     */
    @Deprecated
    @UnsupportedAppUsage
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
        return getUsers(/*excludePartial= */ true, excludeDying,
                /* excludePreCreated= */ true);
+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
            netdPermsUids.put(uid, netdPermsUids.get(uid) | otherNetdPerms);
        }

        List<UserInfo> users = mUserManager.getUsers(true);  // exclude dying users
        List<UserInfo> users = mUserManager.getAliveUsers();
        if (users != null) {
            for (UserInfo user : users) {
                mUsers.add(user.id);
+1 −1
Original line number Diff line number Diff line
@@ -1463,7 +1463,7 @@ public class Vpn {
            final long token = Binder.clearCallingIdentity();
            List<UserInfo> users;
            try {
                users = UserManager.get(mContext).getUsers(true);
                users = UserManager.get(mContext).getAliveUsers();
            } finally {
                Binder.restoreCallingIdentity(token);
            }
+1 −1
Original line number Diff line number Diff line
@@ -1199,7 +1199,7 @@ public class ConnectivityServiceTest {
        MockitoAnnotations.initMocks(this);
        when(mMetricsService.defaultNetworkMetrics()).thenReturn(mDefaultNetworkMetrics);

        when(mUserManager.getUsers(eq(true))).thenReturn(
        when(mUserManager.getAliveUsers()).thenReturn(
                Arrays.asList(new UserInfo[] {
                        new UserInfo(VPN_USER, "", 0),
                }));
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class PermissionMonitorTest {
        MockitoAnnotations.initMocks(this);
        when(mContext.getPackageManager()).thenReturn(mPackageManager);
        when(mContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mUserManager);
        when(mUserManager.getUsers(eq(true))).thenReturn(
        when(mUserManager.getAliveUsers()).thenReturn(
                Arrays.asList(new UserInfo[] {
                        new UserInfo(MOCK_USER1, "", 0),
                        new UserInfo(MOCK_USER2, "", 0),
Loading