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.util.Log; 26 27 /** 28 * Profile owner receiver for BYOD flow test. 29 * Setup cross-profile intent filter after successful provisioning. 30 */ 31 public class DeviceAdminTestReceiver extends DeviceAdminReceiver { 32 private static final String TAG = "DeviceAdminTestReceiver"; 33 private static final String DEVICE_OWNER_PKG = 34 "com.android.cts.verifier"; 35 private static final String ADMIN_RECEIVER_TEST_CLASS = 36 DEVICE_OWNER_PKG + ".managedprovisioning.DeviceAdminTestReceiver"; 37 private static final ComponentName RECEIVER_COMPONENT_NAME = new ComponentName( 38 DEVICE_OWNER_PKG, ADMIN_RECEIVER_TEST_CLASS); 39 getReceiverComponentName()40 public static ComponentName getReceiverComponentName() { 41 return RECEIVER_COMPONENT_NAME; 42 } 43 44 @Override onProfileProvisioningComplete(Context context, Intent intent)45 public void onProfileProvisioningComplete(Context context, Intent intent) { 46 Log.d(TAG, "Provisioning complete intent received"); 47 setupProfile(context); 48 } 49 setupProfile(Context context)50 private void setupProfile(Context context) { 51 DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); 52 dpm.setProfileEnabled(new ComponentName(context.getApplicationContext(), getClass())); 53 54 // Setup cross-profile intent filter to allow communications between the two versions of CtsVerifier 55 // Primary -> work direction 56 IntentFilter filter = new IntentFilter(); 57 filter.addAction(ByodHelperActivity.ACTION_QUERY_PROFILE_OWNER); 58 filter.addAction(ByodHelperActivity.ACTION_REMOVE_PROFILE_OWNER); 59 filter.addAction(ByodHelperActivity.ACTION_INSTALL_APK); 60 filter.addAction(ByodHelperActivity.ACTION_CHECK_INTENT_FILTERS); 61 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE); 62 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO); 63 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO); 64 filter.addAction(ByodHelperActivity.ACTION_KEYGUARD_DISABLED_FEATURES); 65 filter.addAction(ByodHelperActivity.ACTION_LOCKNOW); 66 filter.addAction(ByodHelperActivity.ACTION_TEST_NFC_BEAM); 67 filter.addAction(ByodHelperActivity.ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG); 68 filter.addAction(ByodHelperActivity.ACTION_TEST_APP_LINKING_DIALOG); 69 filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_WORK); 70 filter.addAction(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION); 71 filter.addAction(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION_ON_LOCKSCREEN); 72 filter.addAction(WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION); 73 filter.addAction(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST); 74 filter.addAction(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON); 75 filter.addAction( 76 PermissionLockdownTestActivity.ACTION_MANAGED_PROFILE_CHECK_PERMISSION_LOCKDOWN); 77 dpm.addCrossProfileIntentFilter(getWho(context), filter, 78 DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT); 79 80 // Work -> primary direction 81 filter = new IntentFilter(); 82 filter.addAction(ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS); 83 filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_PERSONAL); 84 dpm.addCrossProfileIntentFilter(getWho(context), filter, 85 DevicePolicyManager.FLAG_PARENT_CAN_ACCESS_MANAGED); 86 87 Intent intent = new Intent(context, ByodHelperActivity.class); 88 intent.setAction(ByodHelperActivity.ACTION_PROFILE_PROVISIONED); 89 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 90 context.startActivity(intent); 91 } 92 } 93