Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 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 | |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 19 | import android.app.admin.DevicePolicyManager; |
| 20 | import android.content.ActivityNotFoundException; |
| 21 | import android.content.ComponentName; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 22 | import android.content.Intent; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
| 24 | import android.os.Bundle; |
| 25 | import android.provider.Settings; |
| 26 | import android.util.Log; |
| 27 | import android.view.View; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 28 | import android.view.View.OnClickListener; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 29 | import android.widget.Toast; |
| 30 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 31 | import com.android.cts.verifier.ArrayTestListAdapter; |
| 32 | import com.android.cts.verifier.DialogTestListActivity; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 33 | import com.android.cts.verifier.R; |
| 34 | import com.android.cts.verifier.TestListActivity; |
Zoltan Szatmary-Ban | 46b5ceb | 2015-07-24 12:28:19 +0100 | [diff] [blame] | 35 | import com.android.cts.verifier.TestListAdapter.TestListItem; |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 36 | import com.android.cts.verifier.TestResult; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * CTS verifier test for BYOD managed provisioning flow. |
| 40 | * This activity is responsible for starting the managed provisioning flow and verify the outcome of provisioning. |
| 41 | * It performs the following verifications: |
| 42 | * Full disk encryption is enabled. |
| 43 | * Profile owner is correctly installed. |
| 44 | * Profile owner shows up in the Settings app. |
| 45 | * Badged work apps show up in launcher. |
| 46 | * The first two verifications are performed automatically, by interacting with profile owner using |
| 47 | * cross-profile intents, while the last two are carried out manually by the user. |
| 48 | */ |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 49 | public class ByodFlowTestActivity extends DialogTestListActivity { |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 50 | |
| 51 | private final String TAG = "ByodFlowTestActivity"; |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 52 | private static final int REQUEST_MANAGED_PROVISIONING = 0; |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 53 | private static final int REQUEST_PROFILE_OWNER_STATUS = 1; |
| 54 | private static final int REQUEST_INTENT_FILTERS_STATUS = 2; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 55 | |
| 56 | private ComponentName mAdminReceiverComponent; |
| 57 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 58 | private DialogTestListItem mProfileOwnerInstalled; |
| 59 | private DialogTestListItem mProfileAccountVisibleTest; |
| 60 | private DialogTestListItem mDeviceAdminVisibleTest; |
| 61 | private DialogTestListItem mWorkAppVisibleTest; |
| 62 | private DialogTestListItem mCrossProfileIntentFiltersTest; |
| 63 | private DialogTestListItem mDisableNonMarketTest; |
| 64 | private DialogTestListItem mEnableNonMarketTest; |
| 65 | private DialogTestListItem mWorkNotificationBadgedTest; |
| 66 | private DialogTestListItem mWorkStatusBarIconTest; |
| 67 | private DialogTestListItem mWorkStatusBarToastTest; |
| 68 | private DialogTestListItem mAppSettingsVisibleTest; |
| 69 | private DialogTestListItem mLocationSettingsVisibleTest; |
Michal Karpinski | bb5c533 | 2015-08-12 16:15:31 +0100 | [diff] [blame^] | 70 | private DialogTestListItem mBatterySettingsVisibleTest; |
| 71 | private DialogTestListItem mDataUsageSettingsVisibleTest; |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 72 | private DialogTestListItem mCredSettingsVisibleTest; |
| 73 | private DialogTestListItem mPrintSettingsVisibleTest; |
| 74 | private DialogTestListItem mIntentFiltersTest; |
Sudheer Shanka | 72ba56a | 2015-07-17 18:30:44 +0100 | [diff] [blame] | 75 | private DialogTestListItem mPermissionLockdownTest; |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 76 | private DialogTestListItem mCrossProfileImageCaptureSupportTest; |
| 77 | private DialogTestListItem mCrossProfileVideoCaptureSupportTest; |
| 78 | private DialogTestListItem mCrossProfileAudioCaptureSupportTest; |
Zoltan Szatmary-Ban | 46b5ceb | 2015-07-24 12:28:19 +0100 | [diff] [blame] | 79 | private TestListItem mKeyguardDisabledFeaturesTest; |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 80 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 81 | public ByodFlowTestActivity() { |
| 82 | super(R.layout.provisioning_byod, |
| 83 | R.string.provisioning_byod, R.string.provisioning_byod_info, |
| 84 | R.string.provisioning_byod_instructions); |
| 85 | } |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 86 | |
| 87 | @Override |
| 88 | protected void onCreate(Bundle savedInstanceState) { |
| 89 | super.onCreate(savedInstanceState); |
| 90 | mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName()); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 91 | |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 92 | disableComponent(); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 93 | mPrepareTestButton.setText(R.string.provisioning_byod_start); |
| 94 | mPrepareTestButton.setOnClickListener(new OnClickListener() { |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 95 | @Override |
| 96 | public void onClick(View v) { |
| 97 | startByodProvisioning(); |
| 98 | } |
| 99 | }); |
| 100 | |
| 101 | // If we are started by managed provisioning (fresh managed provisioning after encryption |
| 102 | // reboot), redirect the user back to the main test list. This is because the test result |
| 103 | // is only saved by the parent TestListActivity, and if we did allow the user to proceed |
| 104 | // here, the test result would be lost when this activity finishes. |
| 105 | if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(getIntent().getAction())) { |
| 106 | startActivity(new Intent(this, TestListActivity.class)); |
| 107 | // Calling super.finish() because we delete managed profile in our overridden of finish(), |
| 108 | // which is not what we want to do here. |
| 109 | super.finish(); |
| 110 | } else { |
| 111 | queryProfileOwner(false); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | protected void onNewIntent(Intent intent) { |
| 117 | // This is called when managed provisioning completes successfully without reboot. |
| 118 | super.onNewIntent(intent); |
| 119 | if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(intent.getAction())) { |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 120 | handleStatusUpdate(RESULT_OK, intent); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | @Override |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 125 | protected void handleActivityResult(int requestCode, int resultCode, Intent data) { |
| 126 | switch (requestCode) { |
| 127 | case REQUEST_MANAGED_PROVISIONING: |
| 128 | return; |
| 129 | case REQUEST_PROFILE_OWNER_STATUS: { |
| 130 | // Called after queryProfileOwner() |
| 131 | handleStatusUpdate(resultCode, data); |
| 132 | } break; |
| 133 | case REQUEST_INTENT_FILTERS_STATUS: { |
| 134 | // Called after checkIntentFilters() |
| 135 | handleIntentFiltersStatus(resultCode); |
| 136 | } break; |
| 137 | default: { |
| 138 | super.handleActivityResult(requestCode, resultCode, data); |
| 139 | } |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 143 | private void handleStatusUpdate(int resultCode, Intent data) { |
| 144 | boolean provisioned = data != null && |
| 145 | data.getBooleanExtra(ByodHelperActivity.EXTRA_PROVISIONED, false); |
| 146 | setTestResult(mProfileOwnerInstalled, (provisioned && resultCode == RESULT_OK) ? |
| 147 | TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void finish() { |
| 152 | // Pass and fail buttons are known to call finish() when clicked, and this is when we want to |
| 153 | // clean up the provisioned profile. |
| 154 | requestDeleteProfileOwner(); |
| 155 | super.finish(); |
| 156 | } |
| 157 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 158 | @Override |
| 159 | protected void setupTests(ArrayTestListAdapter adapter) { |
| 160 | mProfileOwnerInstalled = new DialogTestListItem(this, |
| 161 | R.string.provisioning_byod_profileowner, |
| 162 | "BYOD_ProfileOwnerInstalled") { |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 163 | @Override |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 164 | public void performTest(DialogTestListActivity activity) { |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 165 | queryProfileOwner(true); |
| 166 | } |
| 167 | }; |
| 168 | |
Alexandra Gherghina | 9c1c5a5 | 2014-12-09 12:55:23 +0000 | [diff] [blame] | 169 | /* |
| 170 | * To keep the image in this test up to date, use the instructions in |
| 171 | * {@link ByodIconSamplerActivity}. |
| 172 | */ |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 173 | mWorkAppVisibleTest = new DialogTestListItemWithIcon(this, |
Alexandra Gherghina | 2c672b7 | 2015-01-22 11:20:23 +0000 | [diff] [blame] | 174 | R.string.provisioning_byod_workapps_visible, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 175 | "BYOD_WorkAppVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 176 | R.string.provisioning_byod_workapps_visible_instruction, |
Alexandra Gherghina | 2c672b7 | 2015-01-22 11:20:23 +0000 | [diff] [blame] | 177 | new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), |
| 178 | R.drawable.badged_icon); |
| 179 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 180 | mWorkNotificationBadgedTest = new DialogTestListItemWithIcon(this, |
Alexandra Gherghina | 2c672b7 | 2015-01-22 11:20:23 +0000 | [diff] [blame] | 181 | R.string.provisioning_byod_work_notification, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 182 | "BYOD_WorkNotificationBadgedTest", |
Alexandra Gherghina | 2c672b7 | 2015-01-22 11:20:23 +0000 | [diff] [blame] | 183 | R.string.provisioning_byod_work_notification_instruction, |
| 184 | new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION), |
| 185 | R.drawable.ic_corp_icon); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 186 | |
Kenny Guy | 68e7df9 | 2015-05-29 15:26:28 +0100 | [diff] [blame] | 187 | Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON); |
| 188 | workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 189 | mWorkStatusBarIconTest = new DialogTestListItemWithIcon(this, |
Kenny Guy | 68e7df9 | 2015-05-29 15:26:28 +0100 | [diff] [blame] | 190 | R.string.provisioning_byod_work_status_icon, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 191 | "BYOD_WorkStatusBarIconTest", |
Kenny Guy | 68e7df9 | 2015-05-29 15:26:28 +0100 | [diff] [blame] | 192 | R.string.provisioning_byod_work_status_icon_instruction, |
| 193 | workStatusIcon, |
| 194 | R.drawable.stat_sys_managed_profile_status); |
| 195 | |
| 196 | Intent workStatusToast = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST); |
| 197 | workStatusToast.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 198 | mWorkStatusBarToastTest = new DialogTestListItem(this, |
Kenny Guy | 68e7df9 | 2015-05-29 15:26:28 +0100 | [diff] [blame] | 199 | R.string.provisioning_byod_work_status_toast, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 200 | "BYOD_WorkStatusBarToastTest", |
Kenny Guy | 68e7df9 | 2015-05-29 15:26:28 +0100 | [diff] [blame] | 201 | R.string.provisioning_byod_work_status_toast_instruction, |
| 202 | workStatusToast); |
| 203 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 204 | mDisableNonMarketTest = new DialogTestListItem(this, |
| 205 | R.string.provisioning_byod_nonmarket_deny, |
| 206 | "BYOD_DisableNonMarketTest", |
Robin Lee | 020f185 | 2015-01-15 11:56:05 +0000 | [diff] [blame] | 207 | R.string.provisioning_byod_nonmarket_deny_info, |
| 208 | new Intent(ByodHelperActivity.ACTION_INSTALL_APK) |
| 209 | .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, false)); |
| 210 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 211 | mEnableNonMarketTest = new DialogTestListItem(this, |
| 212 | R.string.provisioning_byod_nonmarket_allow, |
| 213 | "BYOD_EnableNonMarketTest", |
Robin Lee | 020f185 | 2015-01-15 11:56:05 +0000 | [diff] [blame] | 214 | R.string.provisioning_byod_nonmarket_allow_info, |
| 215 | new Intent(ByodHelperActivity.ACTION_INSTALL_APK) |
| 216 | .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, true)); |
| 217 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 218 | mProfileAccountVisibleTest = new DialogTestListItem(this, |
| 219 | R.string.provisioning_byod_profile_visible, |
| 220 | "BYOD_ProfileAccountVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 221 | R.string.provisioning_byod_profile_visible_instruction, |
| 222 | new Intent(Settings.ACTION_SETTINGS)); |
| 223 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 224 | mAppSettingsVisibleTest = new DialogTestListItem(this, |
| 225 | R.string.provisioning_byod_app_settings, |
| 226 | "BYOD_AppSettingsVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 227 | R.string.provisioning_byod_app_settings_instruction, |
| 228 | new Intent(Settings.ACTION_APPLICATION_SETTINGS)); |
| 229 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 230 | mDeviceAdminVisibleTest = new DialogTestListItem(this, |
| 231 | R.string.provisioning_byod_admin_visible, |
| 232 | "BYOD_DeviceAdminVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 233 | R.string.provisioning_byod_admin_visible_instruction, |
| 234 | new Intent(Settings.ACTION_SECURITY_SETTINGS)); |
| 235 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 236 | mCredSettingsVisibleTest = new DialogTestListItem(this, |
| 237 | R.string.provisioning_byod_cred_settings, |
| 238 | "BYOD_CredSettingsVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 239 | R.string.provisioning_byod_cred_settings_instruction, |
| 240 | new Intent(Settings.ACTION_SECURITY_SETTINGS)); |
| 241 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 242 | mLocationSettingsVisibleTest = new DialogTestListItem(this, |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 243 | R.string.provisioning_byod_location_settings, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 244 | "BYOD_LocationSettingsVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 245 | R.string.provisioning_byod_location_settings_instruction, |
| 246 | new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); |
| 247 | |
Michal Karpinski | bb5c533 | 2015-08-12 16:15:31 +0100 | [diff] [blame^] | 248 | mBatterySettingsVisibleTest = new DialogTestListItem(this, |
| 249 | R.string.provisioning_byod_battery_settings, |
| 250 | "BYOD_BatterySettingsVisibleTest", |
| 251 | R.string.provisioning_byod_battery_settings_instruction, |
| 252 | new Intent(Intent.ACTION_POWER_USAGE_SUMMARY)); |
| 253 | |
| 254 | mDataUsageSettingsVisibleTest = new DialogTestListItem(this, |
| 255 | R.string.provisioning_byod_data_usage_settings, |
| 256 | "BYOD_DataUsageSettingsVisibleTest", |
| 257 | R.string.provisioning_byod_data_usage_settings_instruction, |
| 258 | new Intent(Settings.ACTION_SETTINGS)); |
| 259 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 260 | mPrintSettingsVisibleTest = new DialogTestListItem(this, |
| 261 | R.string.provisioning_byod_print_settings, |
| 262 | "BYOD_PrintSettingsVisibleTest", |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 263 | R.string.provisioning_byod_print_settings_instruction, |
| 264 | new Intent(Settings.ACTION_PRINT_SETTINGS)); |
| 265 | |
Alexandra Gherghina | aa24ed7 | 2014-10-08 01:11:32 +0100 | [diff] [blame] | 266 | Intent intent = new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE); |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 267 | Intent chooser = Intent.createChooser(intent, |
| 268 | getResources().getString(R.string.provisioning_cross_profile_chooser)); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 269 | mCrossProfileIntentFiltersTest = new DialogTestListItem(this, |
Alexandra Gherghina | aa24ed7 | 2014-10-08 01:11:32 +0100 | [diff] [blame] | 270 | R.string.provisioning_byod_cross_profile, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 271 | "BYOD_CrossProfileIntentFiltersTest", |
Alexandra Gherghina | aa24ed7 | 2014-10-08 01:11:32 +0100 | [diff] [blame] | 272 | R.string.provisioning_byod_cross_profile_instruction, |
| 273 | chooser); |
| 274 | |
Zoltan Szatmary-Ban | 46b5ceb | 2015-07-24 12:28:19 +0100 | [diff] [blame] | 275 | mKeyguardDisabledFeaturesTest = TestListItem.newTest(this, |
| 276 | R.string.provisioning_byod_keyguard_disabled_features, |
| 277 | KeyguardDisabledFeaturesActivity.class.getName(), |
| 278 | new Intent(this, KeyguardDisabledFeaturesActivity.class), null); |
| 279 | |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 280 | // Test for checking if the required intent filters are set during managed provisioning. |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 281 | mIntentFiltersTest = new DialogTestListItem(this, |
| 282 | R.string.provisioning_byod_cross_profile_intent_filters, |
| 283 | "BYOD_IntentFiltersTest") { |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 284 | @Override |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 285 | public void performTest(DialogTestListActivity activity) { |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 286 | checkIntentFilters(); |
| 287 | } |
| 288 | }; |
Sudheer Shanka | 72ba56a | 2015-07-17 18:30:44 +0100 | [diff] [blame] | 289 | |
| 290 | Intent permissionCheckIntent = new Intent( |
| 291 | PermissionLockdownTestActivity.ACTION_MANAGED_PROFILE_CHECK_PERMISSION_LOCKDOWN); |
| 292 | mPermissionLockdownTest = new DialogTestListItem(this, |
| 293 | R.string.device_profile_owner_permission_lockdown_test, |
| 294 | "BYOD_PermissionLockdownTest", |
| 295 | R.string.profile_owner_permission_lockdown_test_info, |
| 296 | permissionCheckIntent); |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 297 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 298 | adapter.add(mProfileOwnerInstalled); |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 299 | |
| 300 | // Badge related tests |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 301 | adapter.add(mWorkAppVisibleTest); |
| 302 | adapter.add(mWorkNotificationBadgedTest); |
| 303 | adapter.add(mWorkStatusBarIconTest); |
| 304 | adapter.add(mWorkStatusBarToastTest); |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 305 | |
| 306 | // Settings related tests. |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 307 | adapter.add(mProfileAccountVisibleTest); |
| 308 | adapter.add(mDeviceAdminVisibleTest); |
| 309 | adapter.add(mCredSettingsVisibleTest); |
| 310 | adapter.add(mAppSettingsVisibleTest); |
| 311 | adapter.add(mLocationSettingsVisibleTest); |
Michal Karpinski | bb5c533 | 2015-08-12 16:15:31 +0100 | [diff] [blame^] | 312 | adapter.add(mBatterySettingsVisibleTest); |
| 313 | adapter.add(mDataUsageSettingsVisibleTest); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 314 | adapter.add(mPrintSettingsVisibleTest); |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 315 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 316 | adapter.add(mCrossProfileIntentFiltersTest); |
| 317 | adapter.add(mDisableNonMarketTest); |
| 318 | adapter.add(mEnableNonMarketTest); |
| 319 | adapter.add(mIntentFiltersTest); |
Sudheer Shanka | 72ba56a | 2015-07-17 18:30:44 +0100 | [diff] [blame] | 320 | adapter.add(mPermissionLockdownTest); |
Zoltan Szatmary-Ban | 46b5ceb | 2015-07-24 12:28:19 +0100 | [diff] [blame] | 321 | adapter.add(mKeyguardDisabledFeaturesTest); |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 322 | |
| 323 | if (canResolveIntent(ByodHelperActivity.getCaptureImageIntent())) { |
| 324 | // Capture image intent can be resolved in primary profile, so test. |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 325 | mCrossProfileImageCaptureSupportTest = new DialogTestListItem(this, |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 326 | R.string.provisioning_byod_capture_image_support, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 327 | "BYOD_CrossProfileImageCaptureSupportTest", |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 328 | R.string.provisioning_byod_capture_image_support_info, |
| 329 | new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE)); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 330 | adapter.add(mCrossProfileImageCaptureSupportTest); |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 331 | } else { |
| 332 | // Capture image intent cannot be resolved in primary profile, so skip test. |
| 333 | Toast.makeText(ByodFlowTestActivity.this, |
| 334 | R.string.provisioning_byod_no_image_capture_resolver, Toast.LENGTH_SHORT) |
| 335 | .show(); |
| 336 | } |
| 337 | |
| 338 | if (canResolveIntent(ByodHelperActivity.getCaptureVideoIntent())) { |
| 339 | // Capture video intent can be resolved in primary profile, so test. |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 340 | mCrossProfileVideoCaptureSupportTest = new DialogTestListItem(this, |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 341 | R.string.provisioning_byod_capture_video_support, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 342 | "BYOD_CrossProfileVideoCaptureSupportTest", |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 343 | R.string.provisioning_byod_capture_video_support_info, |
| 344 | new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO)); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 345 | adapter.add(mCrossProfileVideoCaptureSupportTest); |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 346 | } else { |
| 347 | // Capture video intent cannot be resolved in primary profile, so skip test. |
| 348 | Toast.makeText(ByodFlowTestActivity.this, |
| 349 | R.string.provisioning_byod_no_video_capture_resolver, Toast.LENGTH_SHORT) |
| 350 | .show(); |
| 351 | } |
| 352 | |
| 353 | /* TODO: reinstate when bug b/20131958 is fixed |
| 354 | if (canResolveIntent(ByodHelperActivity.getCaptureAudioIntent())) { |
| 355 | // Capture audio intent can be resolved in primary profile, so test. |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 356 | mCrossProfileAudioCaptureSupportTest = new DialogTestListItem(this, |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 357 | R.string.provisioning_byod_capture_audio_support, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 358 | "BYOD_CrossProfileAudioCaptureSupportTest", |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 359 | R.string.provisioning_byod_capture_audio_support_info, |
| 360 | new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO)); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 361 | adapter.add(mCrossProfileAudioCaptureSupportTest); |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 362 | } else { |
| 363 | // Capture audio intent cannot be resolved in primary profile, so skip test. |
| 364 | Toast.makeText(ByodFlowTestActivity.this, |
| 365 | R.string.provisioning_byod_no_audio_capture_resolver, Toast.LENGTH_SHORT) |
| 366 | .show(); |
| 367 | } |
| 368 | */ |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Sander Alewijnse | 7e24fda | 2015-03-26 17:41:57 +0000 | [diff] [blame] | 371 | // Return whether the intent can be resolved in the current profile |
| 372 | private boolean canResolveIntent(Intent intent) { |
| 373 | return intent.resolveActivity(getPackageManager()) != null; |
| 374 | } |
| 375 | |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 376 | @Override |
| 377 | protected void clearRemainingState(final DialogTestListItem test) { |
| 378 | super.clearRemainingState(test); |
Alexandra Gherghina | 2c672b7 | 2015-01-22 11:20:23 +0000 | [diff] [blame] | 379 | if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION.equals( |
| 380 | test.getManualTestIntent().getAction())) { |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 381 | try { |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 382 | startActivity(new Intent( |
Rubin Xu | c2b00d8 | 2015-02-02 11:30:26 +0000 | [diff] [blame] | 383 | WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION)); |
| 384 | } catch (ActivityNotFoundException e) { |
| 385 | // User shouldn't run this test before work profile is set up. |
| 386 | } |
Alexandra Gherghina | 2c672b7 | 2015-01-22 11:20:23 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 390 | private void startByodProvisioning() { |
| 391 | Intent sending = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE); |
Sudheer Shanka | b64e0dc | 2015-03-23 16:42:35 +0000 | [diff] [blame] | 392 | sending.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, |
| 393 | mAdminReceiverComponent); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 394 | |
| 395 | if (sending.resolveActivity(getPackageManager()) != null) { |
| 396 | // ManagedProvisioning must be started with startActivityForResult, but we don't |
| 397 | // care about the result, so passing 0 as a requestCode |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 398 | startActivityForResult(sending, REQUEST_MANAGED_PROVISIONING); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 399 | } else { |
| 400 | showToast(R.string.provisioning_byod_disabled); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | private void queryProfileOwner(boolean showToast) { |
| 405 | try { |
| 406 | Intent intent = new Intent(ByodHelperActivity.ACTION_QUERY_PROFILE_OWNER); |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 407 | startActivityForResult(intent, REQUEST_PROFILE_OWNER_STATUS); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 408 | } |
| 409 | catch (ActivityNotFoundException e) { |
| 410 | Log.d(TAG, "queryProfileOwner: ActivityNotFoundException", e); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 411 | setTestResult(mProfileOwnerInstalled, TestResult.TEST_RESULT_FAILED); |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 412 | if (showToast) { |
| 413 | showToast(R.string.provisioning_byod_no_activity); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | private void requestDeleteProfileOwner() { |
| 419 | try { |
| 420 | Intent intent = new Intent(ByodHelperActivity.ACTION_REMOVE_PROFILE_OWNER); |
| 421 | startActivity(intent); |
| 422 | showToast(R.string.provisioning_byod_delete_profile); |
| 423 | } |
| 424 | catch (ActivityNotFoundException e) { |
| 425 | Log.d(TAG, "requestDeleteProfileOwner: ActivityNotFoundException", e); |
| 426 | } |
| 427 | } |
| 428 | |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 429 | private void checkIntentFilters() { |
| 430 | try { |
| 431 | // We disable the ByodHelperActivity in the primary profile. So, this intent |
| 432 | // will be handled by the ByodHelperActivity in the managed profile. |
| 433 | Intent intent = new Intent(ByodHelperActivity.ACTION_CHECK_INTENT_FILTERS); |
| 434 | startActivityForResult(intent, REQUEST_INTENT_FILTERS_STATUS); |
| 435 | } catch (ActivityNotFoundException e) { |
| 436 | Log.d(TAG, "checkIntentFilters: ActivityNotFoundException", e); |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 437 | setTestResult(mIntentFiltersTest, TestResult.TEST_RESULT_FAILED); |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 438 | showToast(R.string.provisioning_byod_no_activity); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | private void handleIntentFiltersStatus(int resultCode) { |
| 443 | // we use the resultCode from ByodHelperActivity in the managed profile to know if certain |
| 444 | // intents fired from the managed profile are forwarded. |
| 445 | final boolean intentFiltersSetForManagedIntents = (resultCode == RESULT_OK); |
| 446 | // Since the ByodFlowTestActivity is running in the primary profile, we directly use |
| 447 | // the IntentFiltersTestHelper to know if certain intents fired from the primary profile |
| 448 | // are forwarded. |
| 449 | final boolean intentFiltersSetForPrimaryIntents = |
| 450 | new IntentFiltersTestHelper(this).checkCrossProfileIntentFilters( |
| 451 | IntentFiltersTestHelper.FLAG_INTENTS_FROM_PRIMARY); |
| 452 | final boolean intentFiltersSet = |
| 453 | intentFiltersSetForPrimaryIntents & intentFiltersSetForManagedIntents; |
| 454 | setTestResult(mIntentFiltersTest, |
Zoltan Szatmary-Ban | 27a2bb5 | 2015-07-23 11:58:49 +0100 | [diff] [blame] | 455 | intentFiltersSet ? TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED); |
Sudheer Shanka | 98ff000 | 2015-03-26 16:32:59 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 458 | private void disableComponent() { |
| 459 | // Disable app components in the current profile, so only the counterpart in the other profile |
| 460 | // can respond (via cross-profile intent filter) |
Sudheer Shanka | 72ba56a | 2015-07-17 18:30:44 +0100 | [diff] [blame] | 461 | final String[] components = { |
| 462 | ByodHelperActivity.class.getName(), |
| 463 | WorkNotificationTestActivity.class.getName(), |
| 464 | WorkStatusTestActivity.class.getName(), |
| 465 | PermissionLockdownTestActivity.ACTIVITY_ALIAS |
| 466 | }; |
| 467 | for (String component : components) { |
| 468 | getPackageManager().setComponentEnabledSetting(new ComponentName(this, component), |
| 469 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, |
| 470 | PackageManager.DONT_KILL_APP); |
| 471 | } |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 472 | } |
Rubin Xu | 55d22d4 | 2014-09-24 19:56:58 +0100 | [diff] [blame] | 473 | } |