blob: a5022a32b6175be2e80309679dbd089067e593ea [file] [log] [blame]
Rubin Xu55d22d42014-09-24 19:56:58 +01001/*
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
17package com.android.cts.verifier.managedprovisioning;
18
Rubin Xu55d22d42014-09-24 19:56:58 +010019import android.app.admin.DevicePolicyManager;
20import android.content.ActivityNotFoundException;
21import android.content.ComponentName;
Daniel Xiea41d4972015-10-19 15:35:16 -070022import android.content.Context;
Rubin Xu55d22d42014-09-24 19:56:58 +010023import android.content.Intent;
Rubin Xu55d22d42014-09-24 19:56:58 +010024import android.content.pm.PackageManager;
25import android.os.Bundle;
26import android.provider.Settings;
27import android.util.Log;
28import android.view.View;
Rubin Xu55d22d42014-09-24 19:56:58 +010029import android.view.View.OnClickListener;
Rubin Xu55d22d42014-09-24 19:56:58 +010030import android.widget.Toast;
31
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010032import com.android.cts.verifier.ArrayTestListAdapter;
33import com.android.cts.verifier.DialogTestListActivity;
Rubin Xu55d22d42014-09-24 19:56:58 +010034import com.android.cts.verifier.R;
35import com.android.cts.verifier.TestListActivity;
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +010036import com.android.cts.verifier.TestListAdapter.TestListItem;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010037import com.android.cts.verifier.TestResult;
Rubin Xu55d22d42014-09-24 19:56:58 +010038
39/**
40 * CTS verifier test for BYOD managed provisioning flow.
41 * This activity is responsible for starting the managed provisioning flow and verify the outcome of provisioning.
42 * It performs the following verifications:
43 * Full disk encryption is enabled.
44 * Profile owner is correctly installed.
45 * Profile owner shows up in the Settings app.
46 * Badged work apps show up in launcher.
47 * The first two verifications are performed automatically, by interacting with profile owner using
48 * cross-profile intents, while the last two are carried out manually by the user.
49 */
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010050public class ByodFlowTestActivity extends DialogTestListActivity {
Rubin Xu55d22d42014-09-24 19:56:58 +010051
52 private final String TAG = "ByodFlowTestActivity";
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010053 private static final int REQUEST_MANAGED_PROVISIONING = 0;
Sudheer Shanka98ff0002015-03-26 16:32:59 +000054 private static final int REQUEST_PROFILE_OWNER_STATUS = 1;
55 private static final int REQUEST_INTENT_FILTERS_STATUS = 2;
Rubin Xu55d22d42014-09-24 19:56:58 +010056
57 private ComponentName mAdminReceiverComponent;
58
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010059 private DialogTestListItem mProfileOwnerInstalled;
60 private DialogTestListItem mProfileAccountVisibleTest;
61 private DialogTestListItem mDeviceAdminVisibleTest;
62 private DialogTestListItem mWorkAppVisibleTest;
Daniel Xiea41d4972015-10-19 15:35:16 -070063 private DialogTestListItem mCrossProfileIntentFiltersTestFromPersonal;
64 private DialogTestListItem mCrossProfileIntentFiltersTestFromWork;
65 private DialogTestListItem mAppLinkingTest;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010066 private DialogTestListItem mDisableNonMarketTest;
67 private DialogTestListItem mEnableNonMarketTest;
68 private DialogTestListItem mWorkNotificationBadgedTest;
69 private DialogTestListItem mWorkStatusBarIconTest;
70 private DialogTestListItem mWorkStatusBarToastTest;
71 private DialogTestListItem mAppSettingsVisibleTest;
72 private DialogTestListItem mLocationSettingsVisibleTest;
Michal Karpinskibb5c5332015-08-12 16:15:31 +010073 private DialogTestListItem mBatterySettingsVisibleTest;
74 private DialogTestListItem mDataUsageSettingsVisibleTest;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010075 private DialogTestListItem mCredSettingsVisibleTest;
76 private DialogTestListItem mPrintSettingsVisibleTest;
77 private DialogTestListItem mIntentFiltersTest;
Sudheer Shanka72ba56a2015-07-17 18:30:44 +010078 private DialogTestListItem mPermissionLockdownTest;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010079 private DialogTestListItem mCrossProfileImageCaptureSupportTest;
80 private DialogTestListItem mCrossProfileVideoCaptureSupportTest;
81 private DialogTestListItem mCrossProfileAudioCaptureSupportTest;
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +010082 private TestListItem mKeyguardDisabledFeaturesTest;
Alex Chau4c990c32015-08-14 15:55:18 +010083 private DialogTestListItem mDisableNfcBeamTest;
Daniel Xiea41d4972015-10-19 15:35:16 -070084 private TestListItem mAuthenticationBoundKeyTest;
Rubin Xu55d22d42014-09-24 19:56:58 +010085
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010086 public ByodFlowTestActivity() {
87 super(R.layout.provisioning_byod,
88 R.string.provisioning_byod, R.string.provisioning_byod_info,
89 R.string.provisioning_byod_instructions);
90 }
Rubin Xu55d22d42014-09-24 19:56:58 +010091
92 @Override
93 protected void onCreate(Bundle savedInstanceState) {
94 super.onCreate(savedInstanceState);
95 mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010096
Rubin Xu55d22d42014-09-24 19:56:58 +010097 disableComponent();
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010098 mPrepareTestButton.setText(R.string.provisioning_byod_start);
99 mPrepareTestButton.setOnClickListener(new OnClickListener() {
Rubin Xu55d22d42014-09-24 19:56:58 +0100100 @Override
101 public void onClick(View v) {
102 startByodProvisioning();
103 }
104 });
105
106 // If we are started by managed provisioning (fresh managed provisioning after encryption
107 // reboot), redirect the user back to the main test list. This is because the test result
108 // is only saved by the parent TestListActivity, and if we did allow the user to proceed
109 // here, the test result would be lost when this activity finishes.
110 if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(getIntent().getAction())) {
111 startActivity(new Intent(this, TestListActivity.class));
112 // Calling super.finish() because we delete managed profile in our overridden of finish(),
113 // which is not what we want to do here.
114 super.finish();
115 } else {
116 queryProfileOwner(false);
117 }
118 }
119
120 @Override
121 protected void onNewIntent(Intent intent) {
122 // This is called when managed provisioning completes successfully without reboot.
123 super.onNewIntent(intent);
124 if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(intent.getAction())) {
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100125 handleStatusUpdate(RESULT_OK, intent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100126 }
127 }
128
129 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100130 protected void handleActivityResult(int requestCode, int resultCode, Intent data) {
131 switch (requestCode) {
132 case REQUEST_MANAGED_PROVISIONING:
133 return;
134 case REQUEST_PROFILE_OWNER_STATUS: {
135 // Called after queryProfileOwner()
136 handleStatusUpdate(resultCode, data);
137 } break;
138 case REQUEST_INTENT_FILTERS_STATUS: {
139 // Called after checkIntentFilters()
140 handleIntentFiltersStatus(resultCode);
141 } break;
142 default: {
143 super.handleActivityResult(requestCode, resultCode, data);
144 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100145 }
146 }
147
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100148 private void handleStatusUpdate(int resultCode, Intent data) {
149 boolean provisioned = data != null &&
150 data.getBooleanExtra(ByodHelperActivity.EXTRA_PROVISIONED, false);
151 setTestResult(mProfileOwnerInstalled, (provisioned && resultCode == RESULT_OK) ?
152 TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED);
Rubin Xu55d22d42014-09-24 19:56:58 +0100153 }
154
155 @Override
156 public void finish() {
157 // Pass and fail buttons are known to call finish() when clicked, and this is when we want to
158 // clean up the provisioned profile.
159 requestDeleteProfileOwner();
160 super.finish();
161 }
162
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100163 @Override
164 protected void setupTests(ArrayTestListAdapter adapter) {
165 mProfileOwnerInstalled = new DialogTestListItem(this,
166 R.string.provisioning_byod_profileowner,
167 "BYOD_ProfileOwnerInstalled") {
Rubin Xu55d22d42014-09-24 19:56:58 +0100168 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100169 public void performTest(DialogTestListActivity activity) {
Rubin Xu55d22d42014-09-24 19:56:58 +0100170 queryProfileOwner(true);
171 }
172 };
173
Alexandra Gherghina9c1c5a52014-12-09 12:55:23 +0000174 /*
175 * To keep the image in this test up to date, use the instructions in
176 * {@link ByodIconSamplerActivity}.
177 */
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100178 mWorkAppVisibleTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000179 R.string.provisioning_byod_workapps_visible,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100180 "BYOD_WorkAppVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000181 R.string.provisioning_byod_workapps_visible_instruction,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000182 new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),
183 R.drawable.badged_icon);
184
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100185 mWorkNotificationBadgedTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000186 R.string.provisioning_byod_work_notification,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100187 "BYOD_WorkNotificationBadgedTest",
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000188 R.string.provisioning_byod_work_notification_instruction,
189 new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION),
190 R.drawable.ic_corp_icon);
Rubin Xu55d22d42014-09-24 19:56:58 +0100191
Kenny Guy68e7df92015-05-29 15:26:28 +0100192 Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
193 workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100194 mWorkStatusBarIconTest = new DialogTestListItemWithIcon(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100195 R.string.provisioning_byod_work_status_icon,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100196 "BYOD_WorkStatusBarIconTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100197 R.string.provisioning_byod_work_status_icon_instruction,
198 workStatusIcon,
199 R.drawable.stat_sys_managed_profile_status);
200
201 Intent workStatusToast = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST);
202 workStatusToast.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100203 mWorkStatusBarToastTest = new DialogTestListItem(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100204 R.string.provisioning_byod_work_status_toast,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100205 "BYOD_WorkStatusBarToastTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100206 R.string.provisioning_byod_work_status_toast_instruction,
207 workStatusToast);
208
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100209 mDisableNonMarketTest = new DialogTestListItem(this,
210 R.string.provisioning_byod_nonmarket_deny,
211 "BYOD_DisableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000212 R.string.provisioning_byod_nonmarket_deny_info,
213 new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
214 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, false));
215
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100216 mEnableNonMarketTest = new DialogTestListItem(this,
217 R.string.provisioning_byod_nonmarket_allow,
218 "BYOD_EnableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000219 R.string.provisioning_byod_nonmarket_allow_info,
220 new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
221 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, true));
222
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100223 mProfileAccountVisibleTest = new DialogTestListItem(this,
224 R.string.provisioning_byod_profile_visible,
225 "BYOD_ProfileAccountVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000226 R.string.provisioning_byod_profile_visible_instruction,
227 new Intent(Settings.ACTION_SETTINGS));
228
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100229 mAppSettingsVisibleTest = new DialogTestListItem(this,
230 R.string.provisioning_byod_app_settings,
231 "BYOD_AppSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000232 R.string.provisioning_byod_app_settings_instruction,
233 new Intent(Settings.ACTION_APPLICATION_SETTINGS));
234
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100235 mDeviceAdminVisibleTest = new DialogTestListItem(this,
236 R.string.provisioning_byod_admin_visible,
237 "BYOD_DeviceAdminVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000238 R.string.provisioning_byod_admin_visible_instruction,
239 new Intent(Settings.ACTION_SECURITY_SETTINGS));
240
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100241 mCredSettingsVisibleTest = new DialogTestListItem(this,
242 R.string.provisioning_byod_cred_settings,
243 "BYOD_CredSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000244 R.string.provisioning_byod_cred_settings_instruction,
245 new Intent(Settings.ACTION_SECURITY_SETTINGS));
246
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100247 mLocationSettingsVisibleTest = new DialogTestListItem(this,
Rubin Xuc2b00d82015-02-02 11:30:26 +0000248 R.string.provisioning_byod_location_settings,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100249 "BYOD_LocationSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000250 R.string.provisioning_byod_location_settings_instruction,
251 new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
252
Michal Karpinskibb5c5332015-08-12 16:15:31 +0100253 mBatterySettingsVisibleTest = new DialogTestListItem(this,
254 R.string.provisioning_byod_battery_settings,
255 "BYOD_BatterySettingsVisibleTest",
256 R.string.provisioning_byod_battery_settings_instruction,
257 new Intent(Intent.ACTION_POWER_USAGE_SUMMARY));
258
259 mDataUsageSettingsVisibleTest = new DialogTestListItem(this,
260 R.string.provisioning_byod_data_usage_settings,
261 "BYOD_DataUsageSettingsVisibleTest",
262 R.string.provisioning_byod_data_usage_settings_instruction,
263 new Intent(Settings.ACTION_SETTINGS));
264
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100265 mPrintSettingsVisibleTest = new DialogTestListItem(this,
266 R.string.provisioning_byod_print_settings,
267 "BYOD_PrintSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000268 R.string.provisioning_byod_print_settings_instruction,
269 new Intent(Settings.ACTION_PRINT_SETTINGS));
270
Daniel Xiea41d4972015-10-19 15:35:16 -0700271 Intent intent = new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_WORK);
272 intent.putExtra(CrossProfileTestActivity.EXTRA_STARTED_FROM_WORK, false);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000273 Intent chooser = Intent.createChooser(intent,
274 getResources().getString(R.string.provisioning_cross_profile_chooser));
Daniel Xiea41d4972015-10-19 15:35:16 -0700275 mCrossProfileIntentFiltersTestFromPersonal = new DialogTestListItem(this,
276 R.string.provisioning_byod_cross_profile_from_personal,
277 "BYOD_CrossProfileIntentFiltersTestFromPersonal",
278 R.string.provisioning_byod_cross_profile_from_personal_instruction,
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100279 chooser);
280
Daniel Xiea41d4972015-10-19 15:35:16 -0700281 mCrossProfileIntentFiltersTestFromWork = new DialogTestListItem(this,
282 R.string.provisioning_byod_cross_profile_from_work,
283 "BYOD_CrossProfileIntentFiltersTestFromWork",
284 R.string.provisioning_byod_cross_profile_from_work_instruction,
285 new Intent(ByodHelperActivity.ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG));
286
287 mAppLinkingTest = new DialogTestListItem(this,
288 R.string.provisioning_app_linking,
289 "BYOD_AppLinking",
290 R.string.provisioning_byod_app_linking_instruction,
291 new Intent(ByodHelperActivity.ACTION_TEST_APP_LINKING_DIALOG));
292
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +0100293 mKeyguardDisabledFeaturesTest = TestListItem.newTest(this,
294 R.string.provisioning_byod_keyguard_disabled_features,
295 KeyguardDisabledFeaturesActivity.class.getName(),
296 new Intent(this, KeyguardDisabledFeaturesActivity.class), null);
297
Daniel Xiea41d4972015-10-19 15:35:16 -0700298 mAuthenticationBoundKeyTest = TestListItem.newTest(this,
299 R.string.provisioning_byod_auth_bound_key,
300 AuthenticationBoundKeyTestActivity.class.getName(),
301 new Intent(AuthenticationBoundKeyTestActivity.ACTION_AUTH_BOUND_KEY_TEST),
302 null);
303
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000304 // Test for checking if the required intent filters are set during managed provisioning.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100305 mIntentFiltersTest = new DialogTestListItem(this,
306 R.string.provisioning_byod_cross_profile_intent_filters,
307 "BYOD_IntentFiltersTest") {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000308 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100309 public void performTest(DialogTestListActivity activity) {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000310 checkIntentFilters();
311 }
312 };
Daniel Xiea41d4972015-10-19 15:35:16 -0700313
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100314 Intent permissionCheckIntent = new Intent(
315 PermissionLockdownTestActivity.ACTION_MANAGED_PROFILE_CHECK_PERMISSION_LOCKDOWN);
316 mPermissionLockdownTest = new DialogTestListItem(this,
317 R.string.device_profile_owner_permission_lockdown_test,
318 "BYOD_PermissionLockdownTest",
319 R.string.profile_owner_permission_lockdown_test_info,
320 permissionCheckIntent);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000321
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100322 adapter.add(mProfileOwnerInstalled);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000323
324 // Badge related tests
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100325 adapter.add(mWorkAppVisibleTest);
326 adapter.add(mWorkNotificationBadgedTest);
327 adapter.add(mWorkStatusBarIconTest);
328 adapter.add(mWorkStatusBarToastTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000329
330 // Settings related tests.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100331 adapter.add(mProfileAccountVisibleTest);
332 adapter.add(mDeviceAdminVisibleTest);
333 adapter.add(mCredSettingsVisibleTest);
334 adapter.add(mAppSettingsVisibleTest);
335 adapter.add(mLocationSettingsVisibleTest);
Michal Karpinskibb5c5332015-08-12 16:15:31 +0100336 adapter.add(mBatterySettingsVisibleTest);
337 adapter.add(mDataUsageSettingsVisibleTest);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100338 adapter.add(mPrintSettingsVisibleTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000339
Daniel Xiea41d4972015-10-19 15:35:16 -0700340 adapter.add(mCrossProfileIntentFiltersTestFromPersonal);
341 adapter.add(mCrossProfileIntentFiltersTestFromWork);
342 adapter.add(mAppLinkingTest);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100343 adapter.add(mDisableNonMarketTest);
344 adapter.add(mEnableNonMarketTest);
345 adapter.add(mIntentFiltersTest);
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100346 adapter.add(mPermissionLockdownTest);
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +0100347 adapter.add(mKeyguardDisabledFeaturesTest);
Daniel Xiea41d4972015-10-19 15:35:16 -0700348 adapter.add(mAuthenticationBoundKeyTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000349
Mahaver Chopradb568172015-10-15 12:01:35 +0100350 /* If there is an application that handles ACTION_IMAGE_CAPTURE, test that it handles it
351 * well.
352 */
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000353 if (canResolveIntent(ByodHelperActivity.getCaptureImageIntent())) {
354 // Capture image intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100355 mCrossProfileImageCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000356 R.string.provisioning_byod_capture_image_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100357 "BYOD_CrossProfileImageCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000358 R.string.provisioning_byod_capture_image_support_info,
359 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100360 adapter.add(mCrossProfileImageCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000361 } else {
362 // Capture image intent cannot be resolved in primary profile, so skip test.
363 Toast.makeText(ByodFlowTestActivity.this,
364 R.string.provisioning_byod_no_image_capture_resolver, Toast.LENGTH_SHORT)
365 .show();
366 }
367
Mahaver Chopradb568172015-10-15 12:01:35 +0100368 /* If there is an application that handles ACTION_VIDEO_CAPTURE, test that it handles it
369 * well.
370 */
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000371 if (canResolveIntent(ByodHelperActivity.getCaptureVideoIntent())) {
372 // Capture video intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100373 mCrossProfileVideoCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000374 R.string.provisioning_byod_capture_video_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100375 "BYOD_CrossProfileVideoCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000376 R.string.provisioning_byod_capture_video_support_info,
377 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100378 adapter.add(mCrossProfileVideoCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000379 } else {
380 // Capture video intent cannot be resolved in primary profile, so skip test.
381 Toast.makeText(ByodFlowTestActivity.this,
382 R.string.provisioning_byod_no_video_capture_resolver, Toast.LENGTH_SHORT)
383 .show();
384 }
385
Alex Chauc7ef16d2015-07-30 18:01:30 +0100386 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
Alex Chau4c990c32015-08-14 15:55:18 +0100387 mDisableNfcBeamTest = new DialogTestListItem(this, R.string.provisioning_byod_nfc_beam,
388 "BYOD_DisableNfcBeamTest",
Alex Chauc7ef16d2015-07-30 18:01:30 +0100389 R.string.provisioning_byod_nfc_beam_allowed_instruction,
390 new Intent(ByodHelperActivity.ACTION_TEST_NFC_BEAM)) {
391 @Override
Alex Chau4c990c32015-08-14 15:55:18 +0100392 public void performTest(final DialogTestListActivity activity) {
Alex Chauc7ef16d2015-07-30 18:01:30 +0100393 activity.showManualTestDialog(mDisableNfcBeamTest,
394 new DefaultTestCallback(mDisableNfcBeamTest) {
395 @Override
396 public void onPass() {
397 // Start a second test with beam disallowed by policy.
398 Intent testNfcBeamIntent = new Intent(
399 ByodHelperActivity.ACTION_TEST_NFC_BEAM);
400 testNfcBeamIntent.putExtra(NfcTestActivity.EXTRA_DISALLOW_BY_POLICY,
401 true);
Alex Chau4c990c32015-08-14 15:55:18 +0100402 DialogTestListItem disableNfcBeamTest2 =
403 new DialogTestListItem(activity,
Alex Chauc7ef16d2015-07-30 18:01:30 +0100404 R.string.provisioning_byod_nfc_beam,
Alex Chau4c990c32015-08-14 15:55:18 +0100405 "BYOD_DisableNfcBeamTest",
Alex Chauc7ef16d2015-07-30 18:01:30 +0100406 R.string.provisioning_byod_nfc_beam_disallowed_instruction,
407 testNfcBeamIntent);
408 // The result should be reflected on the original test.
409 activity.showManualTestDialog(disableNfcBeamTest2,
410 new DefaultTestCallback(mDisableNfcBeamTest));
411 }
412 });
413 }
414 };
Alex Chau4c990c32015-08-14 15:55:18 +0100415 adapter.add(mDisableNfcBeamTest);
Alex Chauc7ef16d2015-07-30 18:01:30 +0100416 }
417
Mahaver Chopradb568172015-10-15 12:01:35 +0100418 /* If there is an application that handles RECORD_SOUND_ACTION, test that it handles it
419 * well.
420 */
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000421 if (canResolveIntent(ByodHelperActivity.getCaptureAudioIntent())) {
422 // Capture audio intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100423 mCrossProfileAudioCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000424 R.string.provisioning_byod_capture_audio_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100425 "BYOD_CrossProfileAudioCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000426 R.string.provisioning_byod_capture_audio_support_info,
427 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100428 adapter.add(mCrossProfileAudioCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000429 } else {
430 // Capture audio intent cannot be resolved in primary profile, so skip test.
431 Toast.makeText(ByodFlowTestActivity.this,
432 R.string.provisioning_byod_no_audio_capture_resolver, Toast.LENGTH_SHORT)
433 .show();
434 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100435 }
436
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000437 // Return whether the intent can be resolved in the current profile
438 private boolean canResolveIntent(Intent intent) {
439 return intent.resolveActivity(getPackageManager()) != null;
440 }
441
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100442 @Override
443 protected void clearRemainingState(final DialogTestListItem test) {
444 super.clearRemainingState(test);
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000445 if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION.equals(
446 test.getManualTestIntent().getAction())) {
Rubin Xuc2b00d82015-02-02 11:30:26 +0000447 try {
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100448 startActivity(new Intent(
Rubin Xuc2b00d82015-02-02 11:30:26 +0000449 WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION));
450 } catch (ActivityNotFoundException e) {
451 // User shouldn't run this test before work profile is set up.
452 }
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000453 }
454 }
455
Rubin Xu55d22d42014-09-24 19:56:58 +0100456 private void startByodProvisioning() {
457 Intent sending = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
Sudheer Shankab64e0dc2015-03-23 16:42:35 +0000458 sending.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
459 mAdminReceiverComponent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100460
461 if (sending.resolveActivity(getPackageManager()) != null) {
462 // ManagedProvisioning must be started with startActivityForResult, but we don't
463 // care about the result, so passing 0 as a requestCode
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100464 startActivityForResult(sending, REQUEST_MANAGED_PROVISIONING);
Rubin Xu55d22d42014-09-24 19:56:58 +0100465 } else {
466 showToast(R.string.provisioning_byod_disabled);
467 }
468 }
469
470 private void queryProfileOwner(boolean showToast) {
471 try {
472 Intent intent = new Intent(ByodHelperActivity.ACTION_QUERY_PROFILE_OWNER);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000473 startActivityForResult(intent, REQUEST_PROFILE_OWNER_STATUS);
Rubin Xu55d22d42014-09-24 19:56:58 +0100474 }
475 catch (ActivityNotFoundException e) {
476 Log.d(TAG, "queryProfileOwner: ActivityNotFoundException", e);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100477 setTestResult(mProfileOwnerInstalled, TestResult.TEST_RESULT_FAILED);
Rubin Xu55d22d42014-09-24 19:56:58 +0100478 if (showToast) {
479 showToast(R.string.provisioning_byod_no_activity);
480 }
481 }
482 }
483
484 private void requestDeleteProfileOwner() {
485 try {
486 Intent intent = new Intent(ByodHelperActivity.ACTION_REMOVE_PROFILE_OWNER);
487 startActivity(intent);
488 showToast(R.string.provisioning_byod_delete_profile);
489 }
490 catch (ActivityNotFoundException e) {
491 Log.d(TAG, "requestDeleteProfileOwner: ActivityNotFoundException", e);
492 }
493 }
494
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000495 private void checkIntentFilters() {
496 try {
497 // We disable the ByodHelperActivity in the primary profile. So, this intent
498 // will be handled by the ByodHelperActivity in the managed profile.
499 Intent intent = new Intent(ByodHelperActivity.ACTION_CHECK_INTENT_FILTERS);
500 startActivityForResult(intent, REQUEST_INTENT_FILTERS_STATUS);
501 } catch (ActivityNotFoundException e) {
502 Log.d(TAG, "checkIntentFilters: ActivityNotFoundException", e);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100503 setTestResult(mIntentFiltersTest, TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000504 showToast(R.string.provisioning_byod_no_activity);
505 }
506 }
507
508 private void handleIntentFiltersStatus(int resultCode) {
509 // we use the resultCode from ByodHelperActivity in the managed profile to know if certain
510 // intents fired from the managed profile are forwarded.
511 final boolean intentFiltersSetForManagedIntents = (resultCode == RESULT_OK);
512 // Since the ByodFlowTestActivity is running in the primary profile, we directly use
513 // the IntentFiltersTestHelper to know if certain intents fired from the primary profile
514 // are forwarded.
515 final boolean intentFiltersSetForPrimaryIntents =
516 new IntentFiltersTestHelper(this).checkCrossProfileIntentFilters(
517 IntentFiltersTestHelper.FLAG_INTENTS_FROM_PRIMARY);
518 final boolean intentFiltersSet =
519 intentFiltersSetForPrimaryIntents & intentFiltersSetForManagedIntents;
520 setTestResult(mIntentFiltersTest,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100521 intentFiltersSet ? TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000522 }
523
Rubin Xu55d22d42014-09-24 19:56:58 +0100524 private void disableComponent() {
525 // Disable app components in the current profile, so only the counterpart in the other profile
526 // can respond (via cross-profile intent filter)
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100527 final String[] components = {
528 ByodHelperActivity.class.getName(),
529 WorkNotificationTestActivity.class.getName(),
530 WorkStatusTestActivity.class.getName(),
Daniel Xiea41d4972015-10-19 15:35:16 -0700531 PermissionLockdownTestActivity.ACTIVITY_ALIAS,
532 AuthenticationBoundKeyTestActivity.class.getName()
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100533 };
534 for (String component : components) {
535 getPackageManager().setComponentEnabledSetting(new ComponentName(this, component),
536 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
537 PackageManager.DONT_KILL_APP);
538 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100539 }
Daniel Xiea41d4972015-10-19 15:35:16 -0700540
Rubin Xu55d22d42014-09-24 19:56:58 +0100541}