blob: 52f92b966384cbe8b2a8ad69f33d7e20686d1eeb [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;
Rubin Xu55d22d42014-09-24 19:56:58 +010022import android.content.Intent;
Rubin Xu55d22d42014-09-24 19:56:58 +010023import android.content.pm.PackageManager;
24import android.os.Bundle;
25import android.provider.Settings;
26import android.util.Log;
27import android.view.View;
Rubin Xu55d22d42014-09-24 19:56:58 +010028import android.view.View.OnClickListener;
Rubin Xu55d22d42014-09-24 19:56:58 +010029import android.widget.Toast;
30
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010031import com.android.cts.verifier.ArrayTestListAdapter;
32import com.android.cts.verifier.DialogTestListActivity;
Rubin Xu55d22d42014-09-24 19:56:58 +010033import com.android.cts.verifier.R;
34import com.android.cts.verifier.TestListActivity;
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +010035import com.android.cts.verifier.TestListAdapter.TestListItem;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010036import com.android.cts.verifier.TestResult;
Rubin Xu55d22d42014-09-24 19:56:58 +010037
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-Ban27a2bb52015-07-23 11:58:49 +010049public class ByodFlowTestActivity extends DialogTestListActivity {
Rubin Xu55d22d42014-09-24 19:56:58 +010050
51 private final String TAG = "ByodFlowTestActivity";
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010052 private static final int REQUEST_MANAGED_PROVISIONING = 0;
Sudheer Shanka98ff0002015-03-26 16:32:59 +000053 private static final int REQUEST_PROFILE_OWNER_STATUS = 1;
54 private static final int REQUEST_INTENT_FILTERS_STATUS = 2;
Rubin Xu55d22d42014-09-24 19:56:58 +010055
56 private ComponentName mAdminReceiverComponent;
57
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010058 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;
70 private DialogTestListItem mCredSettingsVisibleTest;
71 private DialogTestListItem mPrintSettingsVisibleTest;
72 private DialogTestListItem mIntentFiltersTest;
Sudheer Shanka72ba56a2015-07-17 18:30:44 +010073 private DialogTestListItem mPermissionLockdownTest;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010074 private DialogTestListItem mCrossProfileImageCaptureSupportTest;
75 private DialogTestListItem mCrossProfileVideoCaptureSupportTest;
76 private DialogTestListItem mCrossProfileAudioCaptureSupportTest;
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +010077 private TestListItem mKeyguardDisabledFeaturesTest;
Alex Chau4c990c32015-08-14 15:55:18 +010078 private DialogTestListItem mDisableNfcBeamTest;
Rubin Xu55d22d42014-09-24 19:56:58 +010079
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010080 public ByodFlowTestActivity() {
81 super(R.layout.provisioning_byod,
82 R.string.provisioning_byod, R.string.provisioning_byod_info,
83 R.string.provisioning_byod_instructions);
84 }
Rubin Xu55d22d42014-09-24 19:56:58 +010085
86 @Override
87 protected void onCreate(Bundle savedInstanceState) {
88 super.onCreate(savedInstanceState);
89 mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010090
Rubin Xu55d22d42014-09-24 19:56:58 +010091 disableComponent();
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010092 mPrepareTestButton.setText(R.string.provisioning_byod_start);
93 mPrepareTestButton.setOnClickListener(new OnClickListener() {
Rubin Xu55d22d42014-09-24 19:56:58 +010094 @Override
95 public void onClick(View v) {
96 startByodProvisioning();
97 }
98 });
99
100 // If we are started by managed provisioning (fresh managed provisioning after encryption
101 // reboot), redirect the user back to the main test list. This is because the test result
102 // is only saved by the parent TestListActivity, and if we did allow the user to proceed
103 // here, the test result would be lost when this activity finishes.
104 if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(getIntent().getAction())) {
105 startActivity(new Intent(this, TestListActivity.class));
106 // Calling super.finish() because we delete managed profile in our overridden of finish(),
107 // which is not what we want to do here.
108 super.finish();
109 } else {
110 queryProfileOwner(false);
111 }
112 }
113
114 @Override
115 protected void onNewIntent(Intent intent) {
116 // This is called when managed provisioning completes successfully without reboot.
117 super.onNewIntent(intent);
118 if (ByodHelperActivity.ACTION_PROFILE_OWNER_STATUS.equals(intent.getAction())) {
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100119 handleStatusUpdate(RESULT_OK, intent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100120 }
121 }
122
123 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100124 protected void handleActivityResult(int requestCode, int resultCode, Intent data) {
125 switch (requestCode) {
126 case REQUEST_MANAGED_PROVISIONING:
127 return;
128 case REQUEST_PROFILE_OWNER_STATUS: {
129 // Called after queryProfileOwner()
130 handleStatusUpdate(resultCode, data);
131 } break;
132 case REQUEST_INTENT_FILTERS_STATUS: {
133 // Called after checkIntentFilters()
134 handleIntentFiltersStatus(resultCode);
135 } break;
136 default: {
137 super.handleActivityResult(requestCode, resultCode, data);
138 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100139 }
140 }
141
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100142 private void handleStatusUpdate(int resultCode, Intent data) {
143 boolean provisioned = data != null &&
144 data.getBooleanExtra(ByodHelperActivity.EXTRA_PROVISIONED, false);
145 setTestResult(mProfileOwnerInstalled, (provisioned && resultCode == RESULT_OK) ?
146 TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED);
Rubin Xu55d22d42014-09-24 19:56:58 +0100147 }
148
149 @Override
150 public void finish() {
151 // Pass and fail buttons are known to call finish() when clicked, and this is when we want to
152 // clean up the provisioned profile.
153 requestDeleteProfileOwner();
154 super.finish();
155 }
156
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100157 @Override
158 protected void setupTests(ArrayTestListAdapter adapter) {
159 mProfileOwnerInstalled = new DialogTestListItem(this,
160 R.string.provisioning_byod_profileowner,
161 "BYOD_ProfileOwnerInstalled") {
Rubin Xu55d22d42014-09-24 19:56:58 +0100162 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100163 public void performTest(DialogTestListActivity activity) {
Rubin Xu55d22d42014-09-24 19:56:58 +0100164 queryProfileOwner(true);
165 }
166 };
167
Alexandra Gherghina9c1c5a52014-12-09 12:55:23 +0000168 /*
169 * To keep the image in this test up to date, use the instructions in
170 * {@link ByodIconSamplerActivity}.
171 */
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100172 mWorkAppVisibleTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000173 R.string.provisioning_byod_workapps_visible,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100174 "BYOD_WorkAppVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000175 R.string.provisioning_byod_workapps_visible_instruction,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000176 new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),
177 R.drawable.badged_icon);
178
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100179 mWorkNotificationBadgedTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000180 R.string.provisioning_byod_work_notification,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100181 "BYOD_WorkNotificationBadgedTest",
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000182 R.string.provisioning_byod_work_notification_instruction,
183 new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION),
184 R.drawable.ic_corp_icon);
Rubin Xu55d22d42014-09-24 19:56:58 +0100185
Kenny Guy68e7df92015-05-29 15:26:28 +0100186 Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
187 workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100188 mWorkStatusBarIconTest = new DialogTestListItemWithIcon(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100189 R.string.provisioning_byod_work_status_icon,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100190 "BYOD_WorkStatusBarIconTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100191 R.string.provisioning_byod_work_status_icon_instruction,
192 workStatusIcon,
193 R.drawable.stat_sys_managed_profile_status);
194
195 Intent workStatusToast = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST);
196 workStatusToast.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100197 mWorkStatusBarToastTest = new DialogTestListItem(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100198 R.string.provisioning_byod_work_status_toast,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100199 "BYOD_WorkStatusBarToastTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100200 R.string.provisioning_byod_work_status_toast_instruction,
201 workStatusToast);
202
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100203 mDisableNonMarketTest = new DialogTestListItem(this,
204 R.string.provisioning_byod_nonmarket_deny,
205 "BYOD_DisableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000206 R.string.provisioning_byod_nonmarket_deny_info,
207 new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
208 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, false));
209
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100210 mEnableNonMarketTest = new DialogTestListItem(this,
211 R.string.provisioning_byod_nonmarket_allow,
212 "BYOD_EnableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000213 R.string.provisioning_byod_nonmarket_allow_info,
214 new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
215 .putExtra(ByodHelperActivity.EXTRA_ALLOW_NON_MARKET_APPS, true));
216
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100217 mProfileAccountVisibleTest = new DialogTestListItem(this,
218 R.string.provisioning_byod_profile_visible,
219 "BYOD_ProfileAccountVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000220 R.string.provisioning_byod_profile_visible_instruction,
221 new Intent(Settings.ACTION_SETTINGS));
222
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100223 mAppSettingsVisibleTest = new DialogTestListItem(this,
224 R.string.provisioning_byod_app_settings,
225 "BYOD_AppSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000226 R.string.provisioning_byod_app_settings_instruction,
227 new Intent(Settings.ACTION_APPLICATION_SETTINGS));
228
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100229 mDeviceAdminVisibleTest = new DialogTestListItem(this,
230 R.string.provisioning_byod_admin_visible,
231 "BYOD_DeviceAdminVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000232 R.string.provisioning_byod_admin_visible_instruction,
233 new Intent(Settings.ACTION_SECURITY_SETTINGS));
234
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100235 mCredSettingsVisibleTest = new DialogTestListItem(this,
236 R.string.provisioning_byod_cred_settings,
237 "BYOD_CredSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000238 R.string.provisioning_byod_cred_settings_instruction,
239 new Intent(Settings.ACTION_SECURITY_SETTINGS));
240
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100241 mLocationSettingsVisibleTest = new DialogTestListItem(this,
Rubin Xuc2b00d82015-02-02 11:30:26 +0000242 R.string.provisioning_byod_location_settings,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100243 "BYOD_LocationSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000244 R.string.provisioning_byod_location_settings_instruction,
245 new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
246
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100247 mPrintSettingsVisibleTest = new DialogTestListItem(this,
248 R.string.provisioning_byod_print_settings,
249 "BYOD_PrintSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000250 R.string.provisioning_byod_print_settings_instruction,
251 new Intent(Settings.ACTION_PRINT_SETTINGS));
252
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100253 Intent intent = new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000254 Intent chooser = Intent.createChooser(intent,
255 getResources().getString(R.string.provisioning_cross_profile_chooser));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100256 mCrossProfileIntentFiltersTest = new DialogTestListItem(this,
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100257 R.string.provisioning_byod_cross_profile,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100258 "BYOD_CrossProfileIntentFiltersTest",
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100259 R.string.provisioning_byod_cross_profile_instruction,
260 chooser);
261
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +0100262 mKeyguardDisabledFeaturesTest = TestListItem.newTest(this,
263 R.string.provisioning_byod_keyguard_disabled_features,
264 KeyguardDisabledFeaturesActivity.class.getName(),
265 new Intent(this, KeyguardDisabledFeaturesActivity.class), null);
266
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000267 // Test for checking if the required intent filters are set during managed provisioning.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100268 mIntentFiltersTest = new DialogTestListItem(this,
269 R.string.provisioning_byod_cross_profile_intent_filters,
270 "BYOD_IntentFiltersTest") {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000271 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100272 public void performTest(DialogTestListActivity activity) {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000273 checkIntentFilters();
274 }
275 };
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100276
277 Intent permissionCheckIntent = new Intent(
278 PermissionLockdownTestActivity.ACTION_MANAGED_PROFILE_CHECK_PERMISSION_LOCKDOWN);
279 mPermissionLockdownTest = new DialogTestListItem(this,
280 R.string.device_profile_owner_permission_lockdown_test,
281 "BYOD_PermissionLockdownTest",
282 R.string.profile_owner_permission_lockdown_test_info,
283 permissionCheckIntent);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000284
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100285 adapter.add(mProfileOwnerInstalled);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000286
287 // Badge related tests
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100288 adapter.add(mWorkAppVisibleTest);
289 adapter.add(mWorkNotificationBadgedTest);
290 adapter.add(mWorkStatusBarIconTest);
291 adapter.add(mWorkStatusBarToastTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000292
293 // Settings related tests.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100294 adapter.add(mProfileAccountVisibleTest);
295 adapter.add(mDeviceAdminVisibleTest);
296 adapter.add(mCredSettingsVisibleTest);
297 adapter.add(mAppSettingsVisibleTest);
298 adapter.add(mLocationSettingsVisibleTest);
299 adapter.add(mPrintSettingsVisibleTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000300
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100301 adapter.add(mCrossProfileIntentFiltersTest);
302 adapter.add(mDisableNonMarketTest);
303 adapter.add(mEnableNonMarketTest);
304 adapter.add(mIntentFiltersTest);
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100305 adapter.add(mPermissionLockdownTest);
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +0100306 adapter.add(mKeyguardDisabledFeaturesTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000307
308 if (canResolveIntent(ByodHelperActivity.getCaptureImageIntent())) {
309 // Capture image intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100310 mCrossProfileImageCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000311 R.string.provisioning_byod_capture_image_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100312 "BYOD_CrossProfileImageCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000313 R.string.provisioning_byod_capture_image_support_info,
314 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100315 adapter.add(mCrossProfileImageCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000316 } else {
317 // Capture image intent cannot be resolved in primary profile, so skip test.
318 Toast.makeText(ByodFlowTestActivity.this,
319 R.string.provisioning_byod_no_image_capture_resolver, Toast.LENGTH_SHORT)
320 .show();
321 }
322
323 if (canResolveIntent(ByodHelperActivity.getCaptureVideoIntent())) {
324 // Capture video intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100325 mCrossProfileVideoCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000326 R.string.provisioning_byod_capture_video_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100327 "BYOD_CrossProfileVideoCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000328 R.string.provisioning_byod_capture_video_support_info,
329 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100330 adapter.add(mCrossProfileVideoCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000331 } else {
332 // Capture video intent cannot be resolved in primary profile, so skip test.
333 Toast.makeText(ByodFlowTestActivity.this,
334 R.string.provisioning_byod_no_video_capture_resolver, Toast.LENGTH_SHORT)
335 .show();
336 }
337
Alex Chauc7ef16d2015-07-30 18:01:30 +0100338 if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
Alex Chau4c990c32015-08-14 15:55:18 +0100339 mDisableNfcBeamTest = new DialogTestListItem(this, R.string.provisioning_byod_nfc_beam,
340 "BYOD_DisableNfcBeamTest",
Alex Chauc7ef16d2015-07-30 18:01:30 +0100341 R.string.provisioning_byod_nfc_beam_allowed_instruction,
342 new Intent(ByodHelperActivity.ACTION_TEST_NFC_BEAM)) {
343 @Override
Alex Chau4c990c32015-08-14 15:55:18 +0100344 public void performTest(final DialogTestListActivity activity) {
Alex Chauc7ef16d2015-07-30 18:01:30 +0100345 activity.showManualTestDialog(mDisableNfcBeamTest,
346 new DefaultTestCallback(mDisableNfcBeamTest) {
347 @Override
348 public void onPass() {
349 // Start a second test with beam disallowed by policy.
350 Intent testNfcBeamIntent = new Intent(
351 ByodHelperActivity.ACTION_TEST_NFC_BEAM);
352 testNfcBeamIntent.putExtra(NfcTestActivity.EXTRA_DISALLOW_BY_POLICY,
353 true);
Alex Chau4c990c32015-08-14 15:55:18 +0100354 DialogTestListItem disableNfcBeamTest2 =
355 new DialogTestListItem(activity,
Alex Chauc7ef16d2015-07-30 18:01:30 +0100356 R.string.provisioning_byod_nfc_beam,
Alex Chau4c990c32015-08-14 15:55:18 +0100357 "BYOD_DisableNfcBeamTest",
Alex Chauc7ef16d2015-07-30 18:01:30 +0100358 R.string.provisioning_byod_nfc_beam_disallowed_instruction,
359 testNfcBeamIntent);
360 // The result should be reflected on the original test.
361 activity.showManualTestDialog(disableNfcBeamTest2,
362 new DefaultTestCallback(mDisableNfcBeamTest));
363 }
364 });
365 }
366 };
Alex Chau4c990c32015-08-14 15:55:18 +0100367 adapter.add(mDisableNfcBeamTest);
Alex Chauc7ef16d2015-07-30 18:01:30 +0100368 }
369
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000370 /* TODO: reinstate when bug b/20131958 is fixed
371 if (canResolveIntent(ByodHelperActivity.getCaptureAudioIntent())) {
372 // Capture audio intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100373 mCrossProfileAudioCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000374 R.string.provisioning_byod_capture_audio_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100375 "BYOD_CrossProfileAudioCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000376 R.string.provisioning_byod_capture_audio_support_info,
377 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100378 adapter.add(mCrossProfileAudioCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000379 } else {
380 // Capture audio intent cannot be resolved in primary profile, so skip test.
381 Toast.makeText(ByodFlowTestActivity.this,
382 R.string.provisioning_byod_no_audio_capture_resolver, Toast.LENGTH_SHORT)
383 .show();
384 }
385 */
Rubin Xu55d22d42014-09-24 19:56:58 +0100386 }
387
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000388 // Return whether the intent can be resolved in the current profile
389 private boolean canResolveIntent(Intent intent) {
390 return intent.resolveActivity(getPackageManager()) != null;
391 }
392
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100393 @Override
394 protected void clearRemainingState(final DialogTestListItem test) {
395 super.clearRemainingState(test);
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000396 if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION.equals(
397 test.getManualTestIntent().getAction())) {
Rubin Xuc2b00d82015-02-02 11:30:26 +0000398 try {
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100399 startActivity(new Intent(
Rubin Xuc2b00d82015-02-02 11:30:26 +0000400 WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION));
401 } catch (ActivityNotFoundException e) {
402 // User shouldn't run this test before work profile is set up.
403 }
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000404 }
405 }
406
Rubin Xu55d22d42014-09-24 19:56:58 +0100407 private void startByodProvisioning() {
408 Intent sending = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
Sudheer Shankab64e0dc2015-03-23 16:42:35 +0000409 sending.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
410 mAdminReceiverComponent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100411
412 if (sending.resolveActivity(getPackageManager()) != null) {
413 // ManagedProvisioning must be started with startActivityForResult, but we don't
414 // care about the result, so passing 0 as a requestCode
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100415 startActivityForResult(sending, REQUEST_MANAGED_PROVISIONING);
Rubin Xu55d22d42014-09-24 19:56:58 +0100416 } else {
417 showToast(R.string.provisioning_byod_disabled);
418 }
419 }
420
421 private void queryProfileOwner(boolean showToast) {
422 try {
423 Intent intent = new Intent(ByodHelperActivity.ACTION_QUERY_PROFILE_OWNER);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000424 startActivityForResult(intent, REQUEST_PROFILE_OWNER_STATUS);
Rubin Xu55d22d42014-09-24 19:56:58 +0100425 }
426 catch (ActivityNotFoundException e) {
427 Log.d(TAG, "queryProfileOwner: ActivityNotFoundException", e);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100428 setTestResult(mProfileOwnerInstalled, TestResult.TEST_RESULT_FAILED);
Rubin Xu55d22d42014-09-24 19:56:58 +0100429 if (showToast) {
430 showToast(R.string.provisioning_byod_no_activity);
431 }
432 }
433 }
434
435 private void requestDeleteProfileOwner() {
436 try {
437 Intent intent = new Intent(ByodHelperActivity.ACTION_REMOVE_PROFILE_OWNER);
438 startActivity(intent);
439 showToast(R.string.provisioning_byod_delete_profile);
440 }
441 catch (ActivityNotFoundException e) {
442 Log.d(TAG, "requestDeleteProfileOwner: ActivityNotFoundException", e);
443 }
444 }
445
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000446 private void checkIntentFilters() {
447 try {
448 // We disable the ByodHelperActivity in the primary profile. So, this intent
449 // will be handled by the ByodHelperActivity in the managed profile.
450 Intent intent = new Intent(ByodHelperActivity.ACTION_CHECK_INTENT_FILTERS);
451 startActivityForResult(intent, REQUEST_INTENT_FILTERS_STATUS);
452 } catch (ActivityNotFoundException e) {
453 Log.d(TAG, "checkIntentFilters: ActivityNotFoundException", e);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100454 setTestResult(mIntentFiltersTest, TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000455 showToast(R.string.provisioning_byod_no_activity);
456 }
457 }
458
459 private void handleIntentFiltersStatus(int resultCode) {
460 // we use the resultCode from ByodHelperActivity in the managed profile to know if certain
461 // intents fired from the managed profile are forwarded.
462 final boolean intentFiltersSetForManagedIntents = (resultCode == RESULT_OK);
463 // Since the ByodFlowTestActivity is running in the primary profile, we directly use
464 // the IntentFiltersTestHelper to know if certain intents fired from the primary profile
465 // are forwarded.
466 final boolean intentFiltersSetForPrimaryIntents =
467 new IntentFiltersTestHelper(this).checkCrossProfileIntentFilters(
468 IntentFiltersTestHelper.FLAG_INTENTS_FROM_PRIMARY);
469 final boolean intentFiltersSet =
470 intentFiltersSetForPrimaryIntents & intentFiltersSetForManagedIntents;
471 setTestResult(mIntentFiltersTest,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100472 intentFiltersSet ? TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000473 }
474
Rubin Xu55d22d42014-09-24 19:56:58 +0100475 private void disableComponent() {
476 // Disable app components in the current profile, so only the counterpart in the other profile
477 // can respond (via cross-profile intent filter)
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100478 final String[] components = {
479 ByodHelperActivity.class.getName(),
480 WorkNotificationTestActivity.class.getName(),
481 WorkStatusTestActivity.class.getName(),
482 PermissionLockdownTestActivity.ACTIVITY_ALIAS
483 };
484 for (String component : components) {
485 getPackageManager().setComponentEnabledSetting(new ComponentName(this, component),
486 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
487 PackageManager.DONT_KILL_APP);
488 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100489 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100490}