• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.deviceandprofileowner;
17 
18 import android.app.admin.DevicePolicyManager;
19 import android.content.ComponentName;
20 import android.content.Context;
21 
22 import junit.framework.Assert;
23 
24 public class Utils {
Utils()25     private Utils() {
26     }
27 
removeActiveAdmin(Context context, ComponentName cn)28     public static void removeActiveAdmin(Context context, ComponentName cn) throws Exception {
29         final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
30         if (dpm.isAdminActive(cn)) {
31             dpm.removeActiveAdmin(cn);
32             assertNotActiveAdmin(context, cn);
33         }
34     }
35 
assertNotActiveAdmin(Context context, ComponentName cn)36     public static void assertNotActiveAdmin(Context context, ComponentName cn) throws Exception {
37         final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
38 
39         for (int i = 0; i < 1000 && dpm.isAdminActive(cn); i++) {
40             Thread.sleep(100);
41         }
42         Assert.assertFalse(dpm.isAdminActive(cn));
43     }
44 }
45