1 /* 2 * Copyright (C) 2012 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 import android.content.pm.PackageManager; 26 import android.util.Log; 27 import android.widget.Toast; 28 29 /** 30 * Profile owner receiver for BYOD flow test. 31 * Setup cross-profile intent filter after successful provisioning. 32 */ 33 public class DeviceAdminTestReceiver extends DeviceAdminReceiver { 34 private static final String TAG = "DeviceAdminTestReceiver"; 35 36 @Override 37 public void onProfileProvisioningComplete(Context context, Intent intent) { 38 Log.d(TAG, "Provisioning complete intent received"); 39 setupProfile(context); 40 } 41 42 private void setupProfile(Context context) { 43 DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); 44 dpm.setProfileEnabled(new ComponentName(context.getApplicationContext(), getClass())); 45 46 // Setup cross-profile intent filter to allow communications between the two versions of CtsVerifier 47 // Primary -> work direction 48 IntentFilter filter = new IntentFilter(); 49 filter.addAction(ByodHelperActivity.ACTION_QUERY_PROFILE_OWNER); 50 filter.addAction(ByodHelperActivity.ACTION_REMOVE_PROFILE_OWNER); 51 filter.addAction(ByodHelperActivity.ACTION_INSTALL_APK); 52 filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE); 53 filter.addAction(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION); 54 filter.addAction(WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION); 55 dpm.addCrossProfileIntentFilter(getWho(context), filter, 56 DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT); 57 58 // Work -> primary direction 59 filter = new IntentFilter(); 60 filter.addAction(ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS); 61 dpm.addCrossProfileIntentFilter(getWho(context), filter, 62 DevicePolicyManager.FLAG_PARENT_CAN_ACCESS_MANAGED); 63 64 Intent intent = new Intent(context, ByodHelperActivity.class); 65 intent.setAction(ByodHelperActivity.ACTION_PROFILE_PROVISIONED); 66 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 67 context.startActivity(intent); 68 } 69 } 70