1 /* 2 * Copyright (C) 2015 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 com.android.ddmlib.Log.LogLevel; 20 import com.android.tradefed.device.DeviceNotAvailableException; 21 import com.android.tradefed.log.LogUtil.CLog; 22 23 import junit.framework.AssertionFailedError; 24 25 /** 26 * Set of tests for profile owner use cases that also apply to device owners. 27 * Tests that should be run identically in both cases are added in DeviceAndProfileOwnerTest. 28 */ 29 public class MixedProfileOwnerTest extends DeviceAndProfileOwnerTest { 30 31 @Override setUp()32 protected void setUp() throws Exception { 33 super.setUp(); 34 35 // We need managed users to be supported in order to create a profile of the user owner. 36 mHasFeature &= hasDeviceFeature("android.software.managed_users"); 37 38 if (mHasFeature) { 39 removeTestUsers(); 40 mUserId = createManagedProfile(); 41 42 installAppAsUser(DEVICE_ADMIN_APK, mUserId); 43 setProfileOwnerOrFail(DEVICE_ADMIN_PKG + "/" + ADMIN_RECEIVER_TEST_CLASS, mUserId); 44 startUser(mUserId); 45 } 46 } 47 48 @Override tearDown()49 protected void tearDown() throws Exception { 50 if (mHasFeature) { 51 removeUser(mUserId); 52 } 53 super.tearDown(); 54 } 55 56 // Most tests for this class are defined in DeviceAndProfileOwnerTest 57 58 /** 59 * Verify that screenshots are still possible for activities in the primary user when the policy 60 * is set on the profile owner. 61 */ testScreenCaptureDisabled_allowedPrimaryUser()62 public void testScreenCaptureDisabled_allowedPrimaryUser() throws Exception { 63 if (!mHasFeature) { 64 return; 65 } 66 executeDeviceTestMethod(".ScreenCaptureDisabledTest", "testSetScreenCaptureDisabled_true"); 67 // start the ScreenCaptureDisabledActivity in the primary user 68 installAppAsUser(DEVICE_ADMIN_APK, USER_OWNER); 69 String command = "am start -W --user 0 " + DEVICE_ADMIN_PKG + "/" 70 + DEVICE_ADMIN_PKG + ".ScreenCaptureDisabledActivity"; 71 getDevice().executeShellCommand(command); 72 executeDeviceTestMethod(".ScreenCaptureDisabledTest", "testScreenCapturePossible"); 73 } 74 } 75