Home | History | Annotate | Download | only in provisioning
      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 
     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         assertTrue(provisioningManager.startProvisioningAndWait(intent));
     42         assertTrue(isExtraUserPresent(provisioningManager.getReceviedProfileProvisionedIntent()));
     43     }
     44 
     45     // This is only necessary if the profile is created via managed provisioning flow.
     46     public void testEnableProfile() {
     47         DevicePolicyManager dpm = (DevicePolicyManager)
     48                 getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
     49         dpm.setProfileEnabled(AdminReceiver.getComponentName(getContext()));
     50     }
     51 
     52     private boolean isExtraUserPresent(Intent intent) {
     53         return intent != null && intent.getExtras().containsKey(Intent.EXTRA_USER);
     54     }
     55 }
     56