Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.pm; |
| 18 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 19 | import android.content.BroadcastReceiver; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 24 | import android.content.pm.UserInfo; |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 26 | import android.os.Bundle; |
Amith Yamasani | 20949a7 | 2013-02-11 15:47:30 -0800 | [diff] [blame] | 27 | import android.os.UserHandle; |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 28 | import android.os.UserManager; |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 29 | import android.provider.Settings; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 30 | import android.test.AndroidTestCase; |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 31 | import android.test.suitebuilder.annotation.LargeTest; |
Sudheer Shanka | c32abe8 | 2016-05-24 13:21:43 -0700 | [diff] [blame] | 32 | import android.test.suitebuilder.annotation.MediumTest; |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 33 | import android.test.suitebuilder.annotation.SmallTest; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 34 | |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 35 | import com.android.internal.util.ArrayUtils; |
| 36 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 37 | import java.util.ArrayList; |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 38 | import java.util.Arrays; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 39 | import java.util.List; |
Fyodor Kupolov | 6e99d3f | 2016-11-01 17:18:41 -0700 | [diff] [blame] | 40 | import java.util.concurrent.ExecutorService; |
| 41 | import java.util.concurrent.Executors; |
| 42 | import java.util.concurrent.TimeUnit; |
| 43 | import java.util.concurrent.atomic.AtomicInteger; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 44 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 45 | /** Test {@link UserManager} functionality. */ |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 46 | public class UserManagerTest extends AndroidTestCase { |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 47 | // Taken from UserManagerService |
| 48 | private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // 30 years |
| 49 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 50 | private static final int REMOVE_CHECK_INTERVAL_MILLIS = 500; // 0.5 seconds |
| 51 | private static final int REMOVE_TIMEOUT_MILLIS = 60 * 1000; // 60 seconds |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 52 | private static final int SWITCH_USER_TIMEOUT_MILLIS = 40 * 1000; // 40 seconds |
| 53 | |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 54 | // Packages which are used during tests. |
| 55 | private static final String[] PACKAGES = new String[] { |
Christine Franks | 8bcd61b | 2017-06-27 16:46:26 -0700 | [diff] [blame] | 56 | "com.android.egg" |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 59 | private final Object mUserRemoveLock = new Object(); |
| 60 | private final Object mUserSwitchLock = new Object(); |
| 61 | |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 62 | private UserManager mUserManager = null; |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 63 | private PackageManager mPackageManager; |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 64 | private List<Integer> usersToRemove; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 65 | |
| 66 | @Override |
| 67 | public void setUp() throws Exception { |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 68 | super.setUp(); |
| 69 | mUserManager = UserManager.get(getContext()); |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 70 | mPackageManager = getContext().getPackageManager(); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 71 | |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 72 | IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 73 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 74 | getContext().registerReceiver(new BroadcastReceiver() { |
| 75 | @Override |
| 76 | public void onReceive(Context context, Intent intent) { |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 77 | switch (intent.getAction()) { |
| 78 | case Intent.ACTION_USER_REMOVED: |
| 79 | synchronized (mUserRemoveLock) { |
| 80 | mUserRemoveLock.notifyAll(); |
| 81 | } |
| 82 | break; |
| 83 | case Intent.ACTION_USER_SWITCHED: |
| 84 | synchronized (mUserSwitchLock) { |
| 85 | mUserSwitchLock.notifyAll(); |
| 86 | } |
| 87 | break; |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | }, filter); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 91 | |
| 92 | removeExistingUsers(); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 93 | usersToRemove = new ArrayList<>(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | protected void tearDown() throws Exception { |
| 98 | for (Integer userId : usersToRemove) { |
| 99 | removeUser(userId); |
| 100 | } |
| 101 | super.tearDown(); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | private void removeExistingUsers() { |
| 105 | List<UserInfo> list = mUserManager.getUsers(); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 106 | for (UserInfo user : list) { |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 107 | // Keep system and primary user. |
| 108 | // We do not have to keep primary user, but in split system user mode, we need it |
| 109 | // until http://b/22976637 is fixed. Right now in split system user mode, you need to |
| 110 | // switch to primary user and run tests under primary user. |
| 111 | if (user.id != UserHandle.USER_SYSTEM && !user.isPrimary()) { |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 112 | removeUser(user.id); |
| 113 | } |
| 114 | } |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 117 | @SmallTest |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 118 | public void testHasSystemUser() throws Exception { |
| 119 | assertTrue(findUser(UserHandle.USER_SYSTEM)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 122 | @MediumTest |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 123 | public void testAddUser() throws Exception { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 124 | UserInfo userInfo = createUser("Guest 1", UserInfo.FLAG_GUEST); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 125 | assertTrue(userInfo != null); |
| 126 | |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 127 | List<UserInfo> list = mUserManager.getUsers(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 128 | boolean found = false; |
| 129 | for (UserInfo user : list) { |
| 130 | if (user.id == userInfo.id && user.name.equals("Guest 1") |
| 131 | && user.isGuest() |
| 132 | && !user.isAdmin() |
| 133 | && !user.isPrimary()) { |
| 134 | found = true; |
Maggie Benthall | 6794458 | 2013-02-22 14:58:27 -0500 | [diff] [blame] | 135 | Bundle restrictions = mUserManager.getUserRestrictions(user.getUserHandle()); |
Sudheer Shanka | c32abe8 | 2016-05-24 13:21:43 -0700 | [diff] [blame] | 136 | assertTrue("Guest user should have DISALLOW_CONFIG_WIFI=true by default", |
Amith Yamasani | 0519105 | 2013-03-26 15:32:29 -0700 | [diff] [blame] | 137 | restrictions.getBoolean(UserManager.DISALLOW_CONFIG_WIFI)); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | assertTrue(found); |
| 141 | } |
| 142 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 143 | @MediumTest |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 144 | public void testAdd2Users() throws Exception { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 145 | UserInfo user1 = createUser("Guest 1", UserInfo.FLAG_GUEST); |
| 146 | UserInfo user2 = createUser("User 2", UserInfo.FLAG_ADMIN); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 147 | |
| 148 | assertTrue(user1 != null); |
| 149 | assertTrue(user2 != null); |
| 150 | |
| 151 | assertTrue(findUser(0)); |
| 152 | assertTrue(findUser(user1.id)); |
| 153 | assertTrue(findUser(user2.id)); |
| 154 | } |
| 155 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 156 | @MediumTest |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 157 | public void testRemoveUser() throws Exception { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 158 | UserInfo userInfo = createUser("Guest 1", UserInfo.FLAG_GUEST); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 159 | removeUser(userInfo.id); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 160 | |
| 161 | assertFalse(findUser(userInfo.id)); |
| 162 | } |
| 163 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 164 | @MediumTest |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 165 | public void testAddGuest() throws Exception { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 166 | UserInfo userInfo1 = createUser("Guest 1", UserInfo.FLAG_GUEST); |
| 167 | UserInfo userInfo2 = createUser("Guest 2", UserInfo.FLAG_GUEST); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 168 | assertNotNull(userInfo1); |
| 169 | assertNull(userInfo2); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 172 | @MediumTest |
jovanak | f24ad49 | 2018-05-18 12:15:59 -0700 | [diff] [blame] | 173 | public void testSetUserAdmin() throws Exception { |
| 174 | UserInfo userInfo = createUser("SecondaryUser", /*flags=*/ 0); |
| 175 | |
| 176 | // Assert user is not admin and has SMS and calls restrictions. |
| 177 | assertFalse(userInfo.isAdmin()); |
| 178 | assertTrue(mUserManager.hasUserRestriction(UserManager.DISALLOW_SMS, |
| 179 | userInfo.getUserHandle())); |
| 180 | assertTrue(mUserManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, |
| 181 | userInfo.getUserHandle())); |
| 182 | |
| 183 | // Assign admin privileges. |
| 184 | mUserManager.setUserAdmin(userInfo.id); |
| 185 | |
| 186 | // Refresh. |
| 187 | userInfo = mUserManager.getUserInfo(userInfo.id); |
| 188 | |
| 189 | // Verify user became admin and SMS and call restrictions are lifted. |
| 190 | assertTrue(userInfo.isAdmin()); |
| 191 | assertFalse(mUserManager.hasUserRestriction(UserManager.DISALLOW_SMS, |
| 192 | userInfo.getUserHandle())); |
| 193 | assertFalse(mUserManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, |
| 194 | userInfo.getUserHandle())); |
| 195 | } |
| 196 | |
| 197 | @MediumTest |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 198 | public void testGetProfileParent() throws Exception { |
| 199 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 200 | |
| 201 | UserInfo userInfo = createProfileForUser("Profile", |
| 202 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
| 203 | assertNotNull(userInfo); |
Amith Yamasani | 801e342 | 2017-01-25 11:35:44 -0800 | [diff] [blame] | 204 | assertNull(mUserManager.getProfileParent(primaryUserId)); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 205 | UserInfo parentProfileInfo = mUserManager.getProfileParent(userInfo.id); |
| 206 | assertNotNull(parentProfileInfo); |
| 207 | assertEquals(parentProfileInfo.id, primaryUserId); |
Amith Yamasani | 801e342 | 2017-01-25 11:35:44 -0800 | [diff] [blame] | 208 | removeUser(userInfo.id); |
| 209 | assertNull(mUserManager.getProfileParent(primaryUserId)); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 212 | // Make sure only one managed profile can be created |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 213 | @MediumTest |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 214 | public void testAddManagedProfile() throws Exception { |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 215 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 216 | UserInfo userInfo1 = createProfileForUser("Managed 1", |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 217 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 218 | UserInfo userInfo2 = createProfileForUser("Managed 2", |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 219 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 220 | |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 221 | assertNotNull(userInfo1); |
| 222 | assertNull(userInfo2); |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 223 | // Verify that current user is not a managed profile |
| 224 | assertFalse(mUserManager.isManagedProfile()); |
Amith Yamasani | 95ab784 | 2014-08-11 17:09:26 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 227 | // Verify that disallowed packages are not installed in the managed profile. |
| 228 | @MediumTest |
| 229 | public void testAddManagedProfile_withDisallowedPackages() throws Exception { |
| 230 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 231 | UserInfo userInfo1 = createProfileForUser("Managed1", |
| 232 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
| 233 | // Verify that the packagesToVerify are installed by default. |
| 234 | for (String pkg : PACKAGES) { |
| 235 | assertTrue("Package should be installed in managed profile: " + pkg, |
| 236 | isPackageInstalledForUser(pkg, userInfo1.id)); |
| 237 | } |
| 238 | removeUser(userInfo1.id); |
| 239 | |
| 240 | UserInfo userInfo2 = createProfileForUser("Managed2", |
| 241 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId, PACKAGES); |
| 242 | // Verify that the packagesToVerify are not installed by default. |
| 243 | for (String pkg : PACKAGES) { |
| 244 | assertFalse("Package should not be installed in managed profile when disallowed: " |
| 245 | + pkg, isPackageInstalledForUser(pkg, userInfo2.id)); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // Verify that if any packages are disallowed to install during creation of managed profile can |
| 250 | // still be installed later. |
| 251 | @MediumTest |
| 252 | public void testAddManagedProfile_disallowedPackagesInstalledLater() throws Exception { |
| 253 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 254 | UserInfo userInfo = createProfileForUser("Managed", |
| 255 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId, PACKAGES); |
| 256 | // Verify that the packagesToVerify are not installed by default. |
| 257 | for (String pkg : PACKAGES) { |
| 258 | assertFalse("Package should not be installed in managed profile when disallowed: " |
| 259 | + pkg, isPackageInstalledForUser(pkg, userInfo.id)); |
| 260 | } |
| 261 | |
| 262 | // Verify that the disallowed packages during profile creation can be installed now. |
| 263 | for (String pkg : PACKAGES) { |
| 264 | assertEquals("Package could not be installed: " + pkg, |
| 265 | PackageManager.INSTALL_SUCCEEDED, |
| 266 | mPackageManager.installExistingPackageAsUser(pkg, userInfo.id)); |
| 267 | } |
| 268 | } |
| 269 | |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 270 | // Make sure createUser would fail if we have DISALLOW_ADD_USER. |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 271 | @MediumTest |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 272 | public void testCreateUser_disallowAddUser() throws Exception { |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 273 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 274 | final UserHandle primaryUserHandle = new UserHandle(primaryUserId); |
| 275 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_USER, true, primaryUserHandle); |
| 276 | try { |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 277 | UserInfo userInfo = createUser("SecondaryUser", /*flags=*/ 0); |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 278 | assertNull(userInfo); |
| 279 | } finally { |
| 280 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_USER, false, |
| 281 | primaryUserHandle); |
| 282 | } |
| 283 | } |
| 284 | |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 285 | // Make sure createProfile would fail if we have DISALLOW_ADD_MANAGED_PROFILE. |
| 286 | @MediumTest |
| 287 | public void testCreateProfileForUser_disallowAddManagedProfile() throws Exception { |
| 288 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 289 | final UserHandle primaryUserHandle = new UserHandle(primaryUserId); |
| 290 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_MANAGED_PROFILE, true, |
| 291 | primaryUserHandle); |
| 292 | try { |
| 293 | UserInfo userInfo = createProfileForUser("Managed", |
| 294 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
| 295 | assertNull(userInfo); |
| 296 | } finally { |
| 297 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_MANAGED_PROFILE, false, |
| 298 | primaryUserHandle); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | // Make sure createProfileEvenWhenDisallowedForUser bypass DISALLOW_ADD_MANAGED_PROFILE. |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 303 | @MediumTest |
| 304 | public void testCreateProfileForUserEvenWhenDisallowed() throws Exception { |
| 305 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 306 | final UserHandle primaryUserHandle = new UserHandle(primaryUserId); |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 307 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_MANAGED_PROFILE, true, |
| 308 | primaryUserHandle); |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 309 | try { |
| 310 | UserInfo userInfo = createProfileEvenWhenDisallowedForUser("Managed", |
| 311 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
| 312 | assertNotNull(userInfo); |
| 313 | } finally { |
Esteban Talavera | 6c9116a | 2016-11-24 16:12:44 +0000 | [diff] [blame] | 314 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_MANAGED_PROFILE, false, |
| 315 | primaryUserHandle); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // createProfile succeeds even if DISALLOW_ADD_USER is set |
| 320 | @MediumTest |
| 321 | public void testCreateProfileForUser_disallowAddUser() throws Exception { |
| 322 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
| 323 | final UserHandle primaryUserHandle = new UserHandle(primaryUserId); |
| 324 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_USER, true, primaryUserHandle); |
| 325 | try { |
| 326 | UserInfo userInfo = createProfileForUser("Managed", |
| 327 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
| 328 | assertNotNull(userInfo); |
| 329 | } finally { |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 330 | mUserManager.setUserRestriction(UserManager.DISALLOW_ADD_USER, false, |
| 331 | primaryUserHandle); |
| 332 | } |
| 333 | } |
| 334 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 335 | @MediumTest |
| 336 | public void testAddRestrictedProfile() throws Exception { |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 337 | assertFalse("There should be no associated restricted profiles before the test", |
| 338 | mUserManager.hasRestrictedProfiles()); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 339 | UserInfo userInfo = createRestrictedProfile("Profile"); |
| 340 | assertNotNull(userInfo); |
| 341 | |
| 342 | Bundle restrictions = mUserManager.getUserRestrictions(UserHandle.of(userInfo.id)); |
| 343 | assertTrue("Restricted profile should have DISALLOW_MODIFY_ACCOUNTS restriction by default", |
| 344 | restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS)); |
| 345 | assertTrue("Restricted profile should have DISALLOW_SHARE_LOCATION restriction by default", |
| 346 | restrictions.getBoolean(UserManager.DISALLOW_SHARE_LOCATION)); |
| 347 | |
| 348 | int locationMode = Settings.Secure.getIntForUser(getContext().getContentResolver(), |
| 349 | Settings.Secure.LOCATION_MODE, |
| 350 | Settings.Secure.LOCATION_MODE_HIGH_ACCURACY, |
| 351 | userInfo.id); |
| 352 | assertEquals("Restricted profile should have setting LOCATION_MODE set to " |
| 353 | + "LOCATION_MODE_OFF by default", locationMode, Settings.Secure.LOCATION_MODE_OFF); |
Fyodor Kupolov | ca17756 | 2017-11-09 17:43:01 -0800 | [diff] [blame] | 354 | |
| 355 | assertTrue("Newly created profile should be associated with the current user", |
| 356 | mUserManager.hasRestrictedProfiles()); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | @MediumTest |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 360 | public void testGetUserCreationTime() throws Exception { |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 361 | final int primaryUserId = mUserManager.getPrimaryUser().id; |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 362 | final long startTime = System.currentTimeMillis(); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 363 | UserInfo profile = createProfileForUser("Managed 1", |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 364 | UserInfo.FLAG_MANAGED_PROFILE, primaryUserId); |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 365 | final long endTime = System.currentTimeMillis(); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 366 | assertNotNull(profile); |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 367 | if (System.currentTimeMillis() > EPOCH_PLUS_30_YEARS) { |
| 368 | assertTrue("creationTime must be set when the profile is created", |
| 369 | profile.creationTime >= startTime && profile.creationTime <= endTime); |
| 370 | } else { |
| 371 | assertTrue("creationTime must be 0 if the time is not > EPOCH_PLUS_30_years", |
| 372 | profile.creationTime == 0); |
| 373 | } |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 374 | assertEquals(profile.creationTime, mUserManager.getUserCreationTime( |
| 375 | new UserHandle(profile.id))); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 376 | |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 377 | long ownerCreationTime = mUserManager.getUserInfo(primaryUserId).creationTime; |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 378 | assertEquals(ownerCreationTime, mUserManager.getUserCreationTime( |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 379 | new UserHandle(primaryUserId))); |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 380 | } |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 381 | |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 382 | @SmallTest |
| 383 | public void testGetUserCreationTime_nonExistentUser() throws Exception { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 384 | try { |
| 385 | int noSuchUserId = 100500; |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 386 | mUserManager.getUserCreationTime(new UserHandle(noSuchUserId)); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 387 | fail("SecurityException should be thrown for nonexistent user"); |
| 388 | } catch (Exception e) { |
| 389 | assertTrue("SecurityException should be thrown for nonexistent user, but was: " + e, |
| 390 | e instanceof SecurityException); |
| 391 | } |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 392 | } |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 393 | |
Sudheer Shanka | 133c627 | 2016-08-24 10:49:33 -0700 | [diff] [blame] | 394 | @SmallTest |
| 395 | public void testGetUserCreationTime_otherUser() throws Exception { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 396 | UserInfo user = createUser("User 1", 0); |
| 397 | try { |
Fyodor Kupolov | 385de62 | 2015-04-10 18:00:19 -0700 | [diff] [blame] | 398 | mUserManager.getUserCreationTime(new UserHandle(user.id)); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 399 | fail("SecurityException should be thrown for other user"); |
| 400 | } catch (Exception e) { |
| 401 | assertTrue("SecurityException should be thrown for other user, but was: " + e, |
| 402 | e instanceof SecurityException); |
| 403 | } |
| 404 | } |
| 405 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 406 | private boolean findUser(int id) { |
Amith Yamasani | 0b28549 | 2011-04-14 17:35:23 -0700 | [diff] [blame] | 407 | List<UserInfo> list = mUserManager.getUsers(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 408 | |
| 409 | for (UserInfo user : list) { |
| 410 | if (user.id == id) { |
| 411 | return true; |
| 412 | } |
| 413 | } |
| 414 | return false; |
| 415 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 416 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 417 | @MediumTest |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 418 | public void testSerialNumber() { |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 419 | UserInfo user1 = createUser("User 1", 0); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 420 | int serialNumber1 = user1.serialNumber; |
| 421 | assertEquals(serialNumber1, mUserManager.getUserSerialNumber(user1.id)); |
| 422 | assertEquals(user1.id, mUserManager.getUserHandle(serialNumber1)); |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 423 | UserInfo user2 = createUser("User 2", 0); |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 424 | int serialNumber2 = user2.serialNumber; |
| 425 | assertFalse(serialNumber1 == serialNumber2); |
| 426 | assertEquals(serialNumber2, mUserManager.getUserSerialNumber(user2.id)); |
| 427 | assertEquals(user2.id, mUserManager.getUserHandle(serialNumber2)); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 430 | @MediumTest |
Fyodor Kupolov | 940e857 | 2016-01-26 12:03:51 -0800 | [diff] [blame] | 431 | public void testGetSerialNumbersOfUsers() { |
| 432 | UserInfo user1 = createUser("User 1", 0); |
| 433 | UserInfo user2 = createUser("User 2", 0); |
| 434 | long[] serialNumbersOfUsers = mUserManager.getSerialNumbersOfUsers(false); |
| 435 | String errMsg = "Array " + Arrays.toString(serialNumbersOfUsers) + " should contain "; |
| 436 | assertTrue(errMsg + user1.serialNumber, |
| 437 | ArrayUtils.contains(serialNumbersOfUsers, user1.serialNumber)); |
| 438 | assertTrue(errMsg + user2.serialNumber, |
| 439 | ArrayUtils.contains(serialNumbersOfUsers, user2.serialNumber)); |
| 440 | } |
| 441 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 442 | @MediumTest |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 443 | public void testMaxUsers() { |
| 444 | int N = UserManager.getMaxSupportedUsers(); |
| 445 | int count = mUserManager.getUsers().size(); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 446 | // Create as many users as permitted and make sure creation passes |
| 447 | while (count < N) { |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 448 | UserInfo ui = createUser("User " + count, 0); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 449 | assertNotNull(ui); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 450 | count++; |
| 451 | } |
| 452 | // Try to create one more user and make sure it fails |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 453 | UserInfo extra = createUser("One more", 0); |
| 454 | assertNull(extra); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 457 | @MediumTest |
| 458 | public void testGetUserCount() { |
| 459 | int count = mUserManager.getUsers().size(); |
| 460 | UserInfo user1 = createUser("User 1", 0); |
| 461 | assertNotNull(user1); |
| 462 | UserInfo user2 = createUser("User 2", 0); |
| 463 | assertNotNull(user2); |
| 464 | assertEquals(count + 2, mUserManager.getUserCount()); |
| 465 | } |
| 466 | |
| 467 | @MediumTest |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 468 | public void testRestrictions() { |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 469 | UserInfo testUser = createUser("User 1", 0); |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 470 | |
| 471 | mUserManager.setUserRestriction( |
| 472 | UserManager.DISALLOW_INSTALL_APPS, true, new UserHandle(testUser.id)); |
| 473 | mUserManager.setUserRestriction( |
| 474 | UserManager.DISALLOW_CONFIG_WIFI, false, new UserHandle(testUser.id)); |
| 475 | |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 476 | Bundle stored = mUserManager.getUserRestrictions(new UserHandle(testUser.id)); |
Makoto Onuki | 068c54a | 2015-10-13 14:34:03 -0700 | [diff] [blame] | 477 | // Note this will fail if DO already sets those restrictions. |
Xiaohui Chen | 72d9c02 | 2015-08-21 09:23:23 -0700 | [diff] [blame] | 478 | assertEquals(stored.getBoolean(UserManager.DISALLOW_CONFIG_WIFI), false); |
| 479 | assertEquals(stored.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS), false); |
| 480 | assertEquals(stored.getBoolean(UserManager.DISALLOW_INSTALL_APPS), true); |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 483 | @MediumTest |
| 484 | public void testSetDefaultGuestRestrictions() { |
| 485 | final Bundle origGuestRestrictions = mUserManager.getDefaultGuestRestrictions(); |
| 486 | Bundle restrictions = new Bundle(); |
| 487 | restrictions.putBoolean(UserManager.DISALLOW_FUN, true); |
| 488 | mUserManager.setDefaultGuestRestrictions(restrictions); |
| 489 | |
| 490 | try { |
| 491 | UserInfo guest = createUser("Guest", UserInfo.FLAG_GUEST); |
| 492 | assertNotNull(guest); |
| 493 | assertTrue(mUserManager.hasUserRestriction(UserManager.DISALLOW_FUN, |
| 494 | guest.getUserHandle())); |
| 495 | } finally { |
| 496 | mUserManager.setDefaultGuestRestrictions(origGuestRestrictions); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | @LargeTest |
| 501 | public void testSwitchUser() { |
| 502 | ActivityManager am = getContext().getSystemService(ActivityManager.class); |
| 503 | final int startUser = am.getCurrentUser(); |
| 504 | UserInfo user = createUser("User", 0); |
| 505 | assertNotNull(user); |
| 506 | // Switch to the user just created. |
| 507 | switchUser(user.id); |
| 508 | // Switch back to the starting user. |
| 509 | switchUser(startUser); |
| 510 | } |
| 511 | |
Fyodor Kupolov | 6e99d3f | 2016-11-01 17:18:41 -0700 | [diff] [blame] | 512 | @MediumTest |
| 513 | public void testConcurrentUserCreate() throws Exception { |
| 514 | int userCount = mUserManager.getUserCount(); |
| 515 | int maxSupportedUsers = UserManager.getMaxSupportedUsers(); |
| 516 | int canBeCreatedCount = maxSupportedUsers - userCount; |
| 517 | // Test exceeding the limit while running in parallel |
| 518 | int createUsersCount = canBeCreatedCount + 5; |
| 519 | ExecutorService es = Executors.newCachedThreadPool(); |
| 520 | AtomicInteger created = new AtomicInteger(); |
| 521 | for (int i = 0; i < createUsersCount; i++) { |
| 522 | final String userName = "testConcUser" + i; |
| 523 | es.submit(() -> { |
| 524 | UserInfo user = mUserManager.createUser(userName, 0); |
| 525 | if (user != null) { |
| 526 | created.incrementAndGet(); |
| 527 | synchronized (mUserRemoveLock) { |
| 528 | usersToRemove.add(user.id); |
| 529 | } |
| 530 | } |
| 531 | }); |
| 532 | } |
| 533 | es.shutdown(); |
| 534 | es.awaitTermination(20, TimeUnit.SECONDS); |
| 535 | assertEquals(maxSupportedUsers, mUserManager.getUserCount()); |
| 536 | assertEquals(canBeCreatedCount, created.get()); |
| 537 | } |
| 538 | |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 539 | private boolean isPackageInstalledForUser(String packageName, int userId) { |
| 540 | try { |
| 541 | return mPackageManager.getPackageInfoAsUser(packageName, 0, userId) != null; |
| 542 | } catch (PackageManager.NameNotFoundException e) { |
| 543 | return false; |
| 544 | } |
| 545 | } |
| 546 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 547 | private void switchUser(int userId) { |
| 548 | synchronized (mUserSwitchLock) { |
| 549 | ActivityManager am = getContext().getSystemService(ActivityManager.class); |
| 550 | am.switchUser(userId); |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 551 | long time = System.currentTimeMillis(); |
Sudheer Shanka | 66f73a8 | 2016-08-23 16:28:56 -0700 | [diff] [blame] | 552 | try { |
| 553 | mUserSwitchLock.wait(SWITCH_USER_TIMEOUT_MILLIS); |
| 554 | } catch (InterruptedException ie) { |
| 555 | Thread.currentThread().interrupt(); |
| 556 | return; |
| 557 | } |
| 558 | if (System.currentTimeMillis() - time > SWITCH_USER_TIMEOUT_MILLIS) { |
| 559 | fail("Timeout waiting for the user switch to u" + userId); |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | private void removeUser(int userId) { |
| 565 | synchronized (mUserRemoveLock) { |
| 566 | mUserManager.removeUser(userId); |
| 567 | long time = System.currentTimeMillis(); |
| 568 | while (mUserManager.getUserInfo(userId) != null) { |
| 569 | try { |
| 570 | mUserRemoveLock.wait(REMOVE_CHECK_INTERVAL_MILLIS); |
| 571 | } catch (InterruptedException ie) { |
| 572 | Thread.currentThread().interrupt(); |
| 573 | return; |
| 574 | } |
| 575 | if (System.currentTimeMillis() - time > REMOVE_TIMEOUT_MILLIS) { |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 576 | fail("Timeout waiting for removeUser. userId = " + userId); |
Amith Yamasani | db6a14c | 2012-10-17 21:16:52 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | } |
Amith Yamasani | 2a00329 | 2012-08-14 18:25:45 -0700 | [diff] [blame] | 580 | } |
Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 581 | |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 582 | private UserInfo createUser(String name, int flags) { |
| 583 | UserInfo user = mUserManager.createUser(name, flags); |
| 584 | if (user != null) { |
| 585 | usersToRemove.add(user.id); |
| 586 | } |
| 587 | return user; |
| 588 | } |
| 589 | |
| 590 | private UserInfo createProfileForUser(String name, int flags, int userHandle) { |
Sudheer Shanka | 7cb54a3 | 2016-09-16 12:59:05 -0700 | [diff] [blame] | 591 | return createProfileForUser(name, flags, userHandle, null); |
| 592 | } |
| 593 | |
| 594 | private UserInfo createProfileForUser(String name, int flags, int userHandle, |
| 595 | String[] disallowedPackages) { |
| 596 | UserInfo profile = mUserManager.createProfileForUser( |
| 597 | name, flags, userHandle, disallowedPackages); |
Fyodor Kupolov | ff7233e | 2015-04-08 11:28:52 -0700 | [diff] [blame] | 598 | if (profile != null) { |
| 599 | usersToRemove.add(profile.id); |
| 600 | } |
| 601 | return profile; |
| 602 | } |
| 603 | |
Tony Mak | 6dc428f | 2016-10-10 15:48:27 +0100 | [diff] [blame] | 604 | private UserInfo createProfileEvenWhenDisallowedForUser(String name, int flags, |
| 605 | int userHandle) { |
| 606 | UserInfo profile = mUserManager.createProfileForUserEvenWhenDisallowed( |
| 607 | name, flags, userHandle, null); |
| 608 | if (profile != null) { |
| 609 | usersToRemove.add(profile.id); |
| 610 | } |
| 611 | return profile; |
| 612 | } |
| 613 | |
Sudheer Shanka | 37906f7 | 2016-05-25 15:40:10 -0700 | [diff] [blame] | 614 | private UserInfo createRestrictedProfile(String name) { |
| 615 | UserInfo profile = mUserManager.createRestrictedProfile(name); |
| 616 | if (profile != null) { |
| 617 | usersToRemove.add(profile.id); |
| 618 | } |
| 619 | return profile; |
| 620 | } |
Fyodor Kupolov | 6e99d3f | 2016-11-01 17:18:41 -0700 | [diff] [blame] | 621 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 622 | } |