• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package com.android.cts.deviceandprofileowner;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static com.android.cts.deviceandprofileowner.BaseDeviceAdminTest.ADMIN_RECEIVER_COMPONENT;
21 
22 import android.app.admin.DevicePolicyManager;
23 import android.content.Context;
24 import android.test.InstrumentationTestCase;
25 
26 public class AccountManagementParentTest extends InstrumentationTestCase {
27     private static final String SOME_ACCOUNT_TYPE = "com.example.account.type";
28 
29     private DevicePolicyManager mDevicePolicyManager;
30     private Context mContext;
31 
32     @Override
setUp()33     protected void setUp() throws Exception {
34         super.setUp();
35         mContext = getInstrumentation().getContext();
36 
37         mDevicePolicyManager = mContext.getSystemService(DevicePolicyManager.class);
38         assertNotNull(mDevicePolicyManager);
39     }
40 
testSetAccountManagementDisabledOnParent()41     public void testSetAccountManagementDisabledOnParent() {
42         DevicePolicyManager parentDevicePolicyManager = getParentInstance();
43 
44         parentDevicePolicyManager.setAccountManagementDisabled(ADMIN_RECEIVER_COMPONENT,
45                 SOME_ACCOUNT_TYPE, true);
46         assertThat(
47                 parentDevicePolicyManager.getAccountTypesWithManagementDisabled()).asList()
48                 .containsExactly(SOME_ACCOUNT_TYPE);
49         // Ensure that account management is not restricted on the managed profile itself.
50         assertThat(mDevicePolicyManager.getAccountTypesWithManagementDisabled()).isEmpty();
51     }
52 
testAccountManagementDisabled()53     public void testAccountManagementDisabled() {
54         assertThat(
55                 mDevicePolicyManager.getAccountTypesWithManagementDisabled()).asList()
56                 .containsExactly(SOME_ACCOUNT_TYPE);
57     }
58 
testEnableAccountManagement()59     public void testEnableAccountManagement() {
60         DevicePolicyManager parentDevicePolicyManager = getParentInstance();
61 
62         parentDevicePolicyManager.setAccountManagementDisabled(ADMIN_RECEIVER_COMPONENT,
63                 SOME_ACCOUNT_TYPE, false);
64         assertThat(parentDevicePolicyManager.getAccountTypesWithManagementDisabled()).isEmpty();
65     }
66 
getParentInstance()67     private DevicePolicyManager getParentInstance() {
68         assertThat(mDevicePolicyManager.isAdminActive(ADMIN_RECEIVER_COMPONENT)).isTrue();
69         assertThat(mDevicePolicyManager.isProfileOwnerApp(
70                 ADMIN_RECEIVER_COMPONENT.getPackageName())).isTrue();
71         assertThat(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).isTrue();
72 
73         DevicePolicyManager parentDevicePolicyManager =
74                 mDevicePolicyManager.getParentProfileInstance(ADMIN_RECEIVER_COMPONENT);
75         assertThat(parentDevicePolicyManager).isNotNull();
76 
77         return parentDevicePolicyManager;
78     }
79 }
80