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.deviceowner; 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 device-owner based tests. 26 * 27 * This class handles making sure that the test is the device owner 28 * and that it has an active admin registered, so that all tests may 29 * assume these are done. The admin component can be accessed through 30 * {@link #getWho()}. 31 */ 32 public class BaseDeviceOwnerTest extends AndroidTestCase { 33 34 public static class BasicAdminReceiver extends DeviceAdminReceiver { 35 } 36 37 public static final String PACKAGE_NAME = BaseDeviceOwnerTest.class.getPackage().getName(); 38 39 protected DevicePolicyManager mDevicePolicyManager; 40 41 @Override setUp()42 protected void setUp() throws Exception { 43 super.setUp(); 44 45 mDevicePolicyManager = (DevicePolicyManager) 46 mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); 47 assertTrue(mDevicePolicyManager.isAdminActive(getWho())); 48 assertTrue(mDevicePolicyManager.isDeviceOwnerApp(PACKAGE_NAME)); 49 } 50 getWho()51 public static ComponentName getWho() { 52 return new ComponentName(PACKAGE_NAME, BasicAdminReceiver.class.getName()); 53 } 54 }