• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 package android.host.multiuser;
17 
18 import static com.google.common.truth.Truth.assertWithMessage;
19 
20 import android.host.multiuser.BaseMultiUserTest.SupportsMultiUserRule;
21 
22 import com.android.compatibility.common.util.CddTest;
23 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
24 
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 @RunWith(DeviceJUnit4ClassRunner.class)
30 public final class CreateUsersPermissionTest extends BaseMultiUserTest {
31 
32     @Rule
33     public final SupportsMultiUserRule mSupportsMultiUserRule = new SupportsMultiUserRule(this);
34 
35     @Test
testCanCreateGuestUser()36     public void testCanCreateGuestUser() throws Exception {
37         // The device may already have a guest present if it is configured with
38         // config_guestUserAutoCreated. If so, skip the test.
39         assumeGuestDoesNotExist();
40 
41         createGuestUser();
42     }
43 
44     @Test
testCanCreateEphemeralUser()45     public void testCanCreateEphemeralUser() throws Exception {
46         getDevice().createUser(
47                 "TestUser_" + System.currentTimeMillis() /* name */,
48                 false /* guest */,
49                 true /* ephemeral */);
50     }
51 
52     @Test
testCanCreateRestrictedUser()53     public void testCanCreateRestrictedUser() throws Exception {
54         createRestrictedProfile(mPrimaryUserId);
55     }
56 
57     @CddTest(requirement="9.5/A-1-3")
58     @Test
testCanCreateGuestUserWhenUserLimitReached()59     public void testCanCreateGuestUserWhenUserLimitReached() throws Exception {
60         assumeIsAutomotive();
61 
62         // Remove existing guest user
63         int guestUserId = getGuestUser();
64         if (guestUserId != -1) {
65             getDevice().removeUser(guestUserId);
66         }
67         // Add new users until user limit reached
68         int maxUsers = getDevice().getMaxNumberOfUsersSupported();
69         int userCount = getDevice().listUsers().size();
70         int numUsersToCreate = maxUsers - userCount;
71         for (int i = 0; i < numUsersToCreate; i++) {
72             // tearDown will removed non-fixed users
73             getDevice().createUser(
74                     "TestUser_" + System.currentTimeMillis() /* name */,
75                     false /* guest */,
76                     false /* ephemeral */);
77         }
78         createGuestUser();
79         userCount = getDevice().listUsers().size();
80         assertWithMessage("User count should be greater than max users due to added guest user")
81                 .that(userCount).isGreaterThan(maxUsers);
82     }
83 }
84