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