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.provider.Settings; 26 import android.util.Log; 27 28 import com.android.cts.verifier.R; 29 import com.android.cts.verifier.location.LocationListenerActivity; 30 import com.android.cts.verifier.managedprovisioning.Utils; 31 32 /** 33 * Profile owner receiver for BYOD flow test. 34 * Setup cross-profile intent filter after successful provisioning. 35 */ 36 public class DeviceAdminTestReceiver extends DeviceAdminReceiver { 37 private static final String TAG = "DeviceAdminTestReceiver"; 38 private static final String DEVICE_OWNER_PKG = 39 "com.android.cts.verifier"; 40 private static final String ADMIN_RECEIVER_TEST_CLASS = 41 DEVICE_OWNER_PKG + ".managedprovisioning.DeviceAdminTestReceiver"; 42 private static final ComponentName RECEIVER_COMPONENT_NAME = new ComponentName( 43 DEVICE_OWNER_PKG, ADMIN_RECEIVER_TEST_CLASS); 44 getReceiverComponentName()45 public static ComponentName getReceiverComponentName() { 46 return RECEIVER_COMPONENT_NAME; 47 } 48 49 @Override onProfileProvisioningComplete(Context context, Intent intent)50 public void onProfileProvisioningComplete(Context context, Intent intent) { 51 Log.d(TAG, "Provisioning complete intent received"); 52 setupProfile(context); 53 } 54 55 @Override onBugreportSharingDeclined(Context context, Intent intent)56 public void onBugreportSharingDeclined(Context context, Intent intent) { 57 Log.i(TAG, "Bugreport sharing declined"); 58 Utils.showBugreportNotification(context, context.getString( 59 R.string.bugreport_sharing_declined), Utils.BUGREPORT_NOTIFICATION_ID); 60 } 61 62 @Override onBugreportShared(Context context, Intent intent, String bugreportFileHash)63 public void onBugreportShared(Context context, Intent intent, String bugreportFileHash) { 64 Log.i(TAG, "Bugreport shared"); 65 Utils.showBugreportNotification(context, context.getString( 66 R.string.bugreport_shared_successfully), Utils.BUGREPORT_NOTIFICATION_ID); 67 } 68 69 @Override onBugreportFailed(Context context, Intent intent, int failureCode)70 public void onBugreportFailed(Context context, Intent intent, int failureCode) { 71 Log.i(TAG, "Bugreport collection operation failed, code: " + failureCode); 72 Utils.showBugreportNotification(context, context.getString( 73 R.string.bugreport_failed_completing), Utils.BUGREPORT_NOTIFICATION_ID); 74 } 75 setupProfile(Context context)76 private void setupProfile(Context context) { 77 DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); 78 dpm.setProfileEnabled(new ComponentName(context.getApplicationContext(), getClass())); 79 80 // Setup cross-profile intent filter to allow communications between the two versions of CtsVerifier 81 // Primary -> work direction 82 IntentFilter filter = new IntentFilter(); 83 filter.addAction(ByodHelperActivity.ACTION_QUERY_PROFILE_OWNER); 84 filter.addAction(ByodHelperActivity.ACTION_REMOVE_MANAGED_PROFILE); 85 filter.addAction(ByodHelperActivity.ACTION_INSTALL_APK); 86 filter.addAction(ByodHelperActivity.ACTION_CHECK_INTENT_FILTERS); 87 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE); 88 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT); 89 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO_WITHOUT_EXTRA_OUTPUT); 90 filter.addAction(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO); 91 filter.addAction(ByodHelperActivity.ACTION_KEYGUARD_DISABLED_FEATURES); 92 filter.addAction(ByodHelperActivity.ACTION_LOCKNOW); 93 filter.addAction(ByodHelperActivity.ACTION_TEST_NFC_BEAM); 94 filter.addAction(ByodHelperActivity.ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG); 95 filter.addAction(ByodHelperActivity.ACTION_TEST_APP_LINKING_DIALOG); 96 filter.addAction(ByodHelperActivity.ACTION_NOTIFICATION); 97 filter.addAction(ByodHelperActivity.ACTION_NOTIFICATION_ON_LOCKSCREEN); 98 filter.addAction(ByodHelperActivity.ACTION_CLEAR_NOTIFICATION); 99 filter.addAction(ByodHelperActivity.ACTION_SET_USER_RESTRICTION); 100 filter.addAction(ByodHelperActivity.ACTION_CLEAR_USER_RESTRICTION); 101 filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_WORK); 102 filter.addAction(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST); 103 filter.addAction(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON); 104 filter.addAction( 105 PermissionLockdownTestActivity.ACTION_MANAGED_PROFILE_CHECK_PERMISSION_LOCKDOWN); 106 filter.addAction(AuthenticationBoundKeyTestActivity.ACTION_AUTH_BOUND_KEY_TEST); 107 filter.addAction(ByodHelperActivity.ACTION_BYOD_SET_LOCATION_AND_CHECK_UPDATES); 108 filter.addAction(VpnTestActivity.ACTION_VPN); 109 filter.addAction(ByodHelperActivity.ACTION_TEST_SELECT_WORK_CHALLENGE); 110 filter.addAction(ByodHelperActivity.ACTION_LAUNCH_CONFIRM_WORK_CREDENTIALS); 111 filter.addAction(ByodHelperActivity.ACTION_SET_ORGANIZATION_INFO); 112 filter.addAction(ByodHelperActivity.ACTION_TEST_PARENT_PROFILE_PASSWORD); 113 filter.addAction(SetSupportMessageActivity.ACTION_SET_SUPPORT_MSG); 114 filter.addAction(CommandReceiverActivity.ACTION_EXECUTE_COMMAND); 115 dpm.addCrossProfileIntentFilter(getWho(context), filter, 116 DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT); 117 118 // Work -> primary direction 119 filter = new IntentFilter(); 120 filter.addAction(ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS); 121 filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_PERSONAL); 122 filter.addAction(LocationListenerActivity.ACTION_SET_LOCATION_AND_CHECK_UPDATES); 123 dpm.addCrossProfileIntentFilter(getWho(context), filter, 124 DevicePolicyManager.FLAG_PARENT_CAN_ACCESS_MANAGED); 125 126 Intent intent = new Intent(context, ByodHelperActivity.class); 127 intent.setAction(ByodHelperActivity.ACTION_PROFILE_PROVISIONED); 128 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 129 context.startActivity(intent); 130 } 131 132 } 133