1 /*
2  * Copyright (C) 2017 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.verifier.managedprovisioning;
18 
19 import android.app.admin.DeviceAdminReceiver;
20 import android.app.admin.DevicePolicyManager;
21 import android.content.ComponentName;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.content.IntentFilter;
25 
26 /**
27  * Profile owner receiver for COMP tests. Sets up cross-profile intent filters that allow the
28  * CtsVerifier running in the primary user to send it commands after successful provisioning.
29  */
30 public class CompDeviceAdminTestReceiver extends DeviceAdminReceiver {
31         private static final ComponentName RECEIVER_COMPONENT_NAME = new ComponentName(
32                 "com.android.cts.verifier", CompDeviceAdminTestReceiver.class.getName());
33 
getReceiverComponentName()34         public static ComponentName getReceiverComponentName() {
35             return RECEIVER_COMPONENT_NAME;
36         }
37 
38         @Override
onProfileProvisioningComplete(Context context, Intent intent)39         public void onProfileProvisioningComplete(Context context, Intent intent) {
40             final DevicePolicyManager dpm =
41                     (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
42             dpm.setProfileEnabled(new ComponentName(context.getApplicationContext(), getClass()));
43 
44             // Set up cross-profile intent filter to allow the CtsVerifier running in the primary
45             // user to send us commands.
46             final IntentFilter filter = new IntentFilter();
47             filter.addAction(CompHelperActivity.ACTION_SET_ALWAYS_ON_VPN);
48             filter.addAction(CompHelperActivity.ACTION_INSTALL_CA_CERT);
49             filter.addAction(CompHelperActivity.ACTION_SET_MAXIMUM_PASSWORD_ATTEMPTS);
50             dpm.addCrossProfileIntentFilter(getWho(context), filter,
51                     DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT);
52         }
53 }
54