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 
17 package com.android.cts.devicepolicy;
18 
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
21 
22 import android.platform.test.annotations.FlakyTest;
23 import android.platform.test.annotations.LargeTest;
24 
25 import com.android.cts.devicepolicy.DeviceAdminFeaturesCheckerRule.RequiresProfileOwnerSupport;
26 import com.android.tradefed.log.LogUtil.CLog;
27 
28 import org.junit.Ignore;
29 import org.junit.Test;
30 
31 /**
32  * Set of tests for pure (non-managed) profile owner use cases that also apply to device owners.
33  * Tests that should be run identically in both cases are added in DeviceAndProfileOwnerTest.
34  */
35 @RequiresProfileOwnerSupport
36 public final class MixedProfileOwnerTest extends DeviceAndProfileOwnerTest {
37 
38     @Override
setUp()39     public void setUp() throws Exception {
40         super.setUp();
41 
42         mUserId = mPrimaryUserId;
43 
44         CLog.i("%s.setUp(): mUserId=%d, mPrimaryUserId=%d, mInitialUserId=%d, "
45                 + "mDeviceOwnerUserId=%d", getClass(), mUserId, mPrimaryUserId, mInitialUserId,
46                 mDeviceOwnerUserId);
47 
48         installAppAsUser(DEVICE_ADMIN_APK, mUserId);
49         if (!setProfileOwner(
50                 DEVICE_ADMIN_PKG + "/" + ADMIN_RECEIVER_TEST_CLASS, mUserId,
51                 /*expectFailure*/ false)) {
52             removeAdmin(DEVICE_ADMIN_PKG + "/" + ADMIN_RECEIVER_TEST_CLASS, mUserId);
53             getDevice().uninstallPackage(DEVICE_ADMIN_PKG);
54             fail("Failed to set profile owner");
55         }
56     }
57 
58     @Override
tearDown()59     public void tearDown() throws Exception {
60         assertTrue("Failed to remove profile owner.",
61                     removeAdmin(DEVICE_ADMIN_PKG + "/" + ADMIN_RECEIVER_TEST_CLASS, mUserId));
62 
63         super.tearDown();
64     }
65 
66     @Override
67     @LargeTest
68     @Test
testPackageInstallUserRestrictions()69     public void testPackageInstallUserRestrictions() throws Exception {
70         super.testPackageInstallUserRestrictions();
71     }
72 
73     @Override
74     @FlakyTest(bugId = 140932104)
75     @Ignore("Ignored while migrating to new infrastructure b/175377361")
76     @Test
testLockTaskAfterReboot()77     public void testLockTaskAfterReboot() throws Exception {
78         super.testLockTaskAfterReboot();
79     }
80 
81     @Override
82     @FlakyTest(bugId = 140932104)
83     @Ignore("Ignored while migrating to new infrastructure b/175377361")
84     @Test
testLockTaskAfterReboot_tryOpeningSettings()85     public void testLockTaskAfterReboot_tryOpeningSettings() throws Exception {
86         super.testLockTaskAfterReboot_tryOpeningSettings();
87     }
88 }
89