1 /*
2  * Copyright (C) 2021 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.delegate;
17 
18 import android.app.admin.DevicePolicyManager;
19 import android.content.Context;
20 import android.support.test.uiautomator.UiDevice;
21 import android.util.Log;
22 
23 import androidx.test.InstrumentationRegistry;
24 import androidx.test.runner.AndroidJUnit4;
25 
26 import com.android.bedstead.dpmwrapper.IpcBroadcastReceiver;
27 import com.android.bedstead.dpmwrapper.TestAppSystemServiceFactory;
28 
29 import org.junit.Before;
30 import org.junit.runner.RunWith;
31 
32 @RunWith(AndroidJUnit4.class)
33 abstract class BaseTestCase {
34 
35     private static final String TAG = BaseTestCase.class.getSimpleName();
36 
37     protected UiDevice mDevice;
38     protected Context mContext;
39     protected DevicePolicyManager mDpm;
40 
41     @Before
setBaseFixtures()42     public final void setBaseFixtures() throws Exception {
43         mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
44         mContext = InstrumentationRegistry.getContext();
45         mDpm = getDpm(mContext);
46         Log.d(TAG, getClass().getName() + ".setup(): dpm=" + mDpm);
47     }
48 
getDpm(Context context)49     static DevicePolicyManager getDpm(Context context) {
50         return TestAppSystemServiceFactory.getDevicePolicyManager(context,
51                 IpcBroadcastReceiver.class);
52     }
53 }
54