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 com.android.cts.devicepolicy; 17 18 import com.android.tradefed.device.DeviceNotAvailableException; 19 20 public class CustomManagedProfileTest extends BaseDevicePolicyTest { 21 22 private static final String MANAGED_PROFILE_PKG = "com.android.cts.managedprofile"; 23 private static final String MANAGED_PROFILE_APK = "CtsManagedProfileApp.apk"; 24 25 @Override 26 protected void setUp() throws Exception { 27 super.setUp(); 28 29 // We need multi user to be supported in order to create a profile of the user owner. 30 mHasFeature = mHasFeature && hasDeviceFeature("android.software.managed_users"); 31 } 32 33 public void testIsProvisioningAllowed() throws Exception { 34 final int primaryUserId = getPrimaryUser(); 35 // Must install the apk since the test runs in the ManagedProfile apk. 36 installAppAsUser(MANAGED_PROFILE_APK, mPrimaryUserId); 37 try { 38 if (mHasFeature) { 39 // Since we assume, in ManagedProfileTest, provisioning has to be successful, 40 // DevicePolicyManager.isProvisioningAllowed must return true 41 assertIsProvisioningAllowed(true, primaryUserId); 42 } else { 43 // Test the case when feature flag is off 44 assertIsProvisioningAllowed(false, primaryUserId); 45 } 46 } finally { 47 getDevice().uninstallPackage(MANAGED_PROFILE_PKG); 48 } 49 } 50 51 private void assertIsProvisioningAllowed(boolean expected, int userId) 52 throws DeviceNotAvailableException { 53 final String testName = expected ? "testIsProvisioningAllowedTrue" 54 : "testIsProvisioningAllowedFalse"; 55 runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".PreManagedProfileTest", testName, userId); 56 } 57 } 58