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

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

Merge "Exposed canSwitchUsers() and added an API in UserManager for SUW."

parents 9be59f96 e38c678d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4333,6 +4333,7 @@ package android.os {
  }

  public class UserManager {
    method public boolean canSwitchUsers();
    method public void clearSeedAccountData();
    method public android.os.UserHandle getProfileParent(android.os.UserHandle);
    method public java.lang.String getSeedAccountName();
@@ -4348,6 +4349,7 @@ package android.os {
    method public boolean isManagedProfile(int);
    method public boolean isPrimaryUser();
    method public boolean isRestrictedProfile();
    method public boolean removeUser(android.os.UserHandle);
    field public static final java.lang.String ACTION_USER_RESTRICTIONS_CHANGED = "android.os.action.USER_RESTRICTIONS_CHANGED";
    field public static final deprecated java.lang.String DISALLOW_OEM_UNLOCK = "no_oem_unlock";
    field public static final java.lang.String DISALLOW_RUN_IN_BACKGROUND = "no_run_in_background";
+16 −0
Original line number Diff line number Diff line
@@ -1225,6 +1225,9 @@ public class UserManager {
     * system user hasn't been unlocked yet, or {@link #DISALLOW_USER_SWITCH} is set.
     * @hide
     */
    @SystemApi
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
    public boolean canSwitchUsers() {
        boolean allowUserSwitchingWhenSystemUserLocked = Settings.Global.getInt(
                mContext.getContentResolver(),
@@ -2645,6 +2648,19 @@ public class UserManager {
        }
    }

    /**
     * Removes a user and all associated data.
     *
     * @param user the user that needs to be removed.
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
    public boolean removeUser(UserHandle user) {
        return removeUser(user.getIdentifier());
    }


    /**
     * Similar to {@link #removeUser(int)} except bypassing the checking of
     * {@link UserManager#DISALLOW_REMOVE_USER}
+24 −1
Original line number Diff line number Diff line
@@ -16,13 +16,13 @@

package com.android.server.pm;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.app.ActivityManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -161,6 +161,29 @@ public class UserManagerTest extends AndroidTestCase {
        assertFalse(findUser(userInfo.id));
    }

    @MediumTest
    public void testRemoveUserByHandle() {
        UserInfo userInfo = createUser("Guest 1", UserInfo.FLAG_GUEST);
        final UserHandle user = userInfo.getUserHandle();
        synchronized (mUserRemoveLock) {
            mUserManager.removeUser(user);
            long time = System.currentTimeMillis();
            while (mUserManager.getUserInfo(user.getIdentifier()) != null) {
                try {
                    mUserRemoveLock.wait(REMOVE_CHECK_INTERVAL_MILLIS);
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                    return;
                }
                if (System.currentTimeMillis() - time > REMOVE_TIMEOUT_MILLIS) {
                    fail("Timeout waiting for removeUser. userId = " + user.getIdentifier());
                }
            }
        }

        assertFalse(findUser(userInfo.id));
    }

    @MediumTest
    public void testAddGuest() throws Exception {
        UserInfo userInfo1 = createUser("Guest 1", UserInfo.FLAG_GUEST);