1 /* 2 * Copyright (C) 2014 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.managedprofile; 17 18 import android.app.admin.DeviceAdminReceiver; 19 import android.app.admin.DevicePolicyManager; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.test.AndroidTestCase; 23 24 /** 25 * Base class for profile-owner based tests. 26 * 27 * This class handles making sure that the test is the profile owner and that it has an active admin 28 * registered, so that all tests may assume these are done. 29 */ 30 public class BaseManagedProfileTest extends AndroidTestCase { 31 32 public static class BasicAdminReceiver extends DeviceAdminReceiver { 33 } 34 35 public static final ComponentName ADMIN_RECEIVER_COMPONENT = new ComponentName( 36 BasicAdminReceiver.class.getPackage().getName(), BasicAdminReceiver.class.getName()); 37 38 protected DevicePolicyManager mDevicePolicyManager; 39 40 @Override setUp()41 protected void setUp() throws Exception { 42 super.setUp(); 43 44 mDevicePolicyManager = (DevicePolicyManager) 45 mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); 46 assertNotNull(mDevicePolicyManager); 47 48 // TODO: Only check the below if we are running as the profile user. If running under the 49 // user owner, can we check that there is a profile and that the below holds for it? If we 50 // don't want to do these checks every time we could get rid of this class altogether and 51 // just have a single test case running under the profile user that do them. 52 assertTrue(mDevicePolicyManager.isAdminActive(ADMIN_RECEIVER_COMPONENT)); 53 assertTrue(mDevicePolicyManager.isProfileOwnerApp( 54 ADMIN_RECEIVER_COMPONENT.getPackageName())); 55 } 56 } 57