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.comp.provisioning;
17 
18 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
19 
20 import android.app.admin.DevicePolicyManager;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.test.AndroidTestCase;
24 
25 import com.android.compatibility.common.util.devicepolicy.provisioning.SilentProvisioningTestManager;
26 import com.android.cts.comp.AdminReceiver;
27 
28 public class ManagedProfileProvisioningTest extends AndroidTestCase {
29     private static final String TAG = "ManagedProfileProvisioningTest";
30 
testProvisioningCorpOwnedManagedProfile()31     public void testProvisioningCorpOwnedManagedProfile() throws Exception {
32         Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE)
33             .putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
34                     AdminReceiver.getComponentName(getContext()))
35             .putExtra(DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION, true)
36             // this flag for Corp owned only
37             .putExtra(DevicePolicyManager.EXTRA_PROVISIONING_SKIP_USER_CONSENT, true);
38 
39         SilentProvisioningTestManager provisioningManager =
40                 new SilentProvisioningTestManager(getContext());
41         assertFalse(provisioningManager.startProvisioningAndWait(intent));
42         assertFalse(isExtraUserPresent(provisioningManager.getReceviedProfileProvisionedIntent()));
43     }
44 
isExtraUserPresent(Intent intent)45     private boolean isExtraUserPresent(Intent intent) {
46         return intent != null && intent.getExtras().containsKey(Intent.EXTRA_USER);
47     }
48 }
49