blob: 856b18de78d836fbeada21c1fdb7988a57caa767 [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;
Michal Karpinskibb5c5332015-08-12 16:15:31 +010070 private DialogTestListItem mBatterySettingsVisibleTest;
71 private DialogTestListItem mDataUsageSettingsVisibleTest;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010072 private DialogTestListItem mCredSettingsVisibleTest;
73 private DialogTestListItem mPrintSettingsVisibleTest;
74 private DialogTestListItem mIntentFiltersTest;
Sudheer Shanka72ba56a2015-07-17 18:30:44 +010075 private DialogTestListItem mPermissionLockdownTest;
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010076 private DialogTestListItem mCrossProfileImageCaptureSupportTest;
77 private DialogTestListItem mCrossProfileVideoCaptureSupportTest;
78 private DialogTestListItem mCrossProfileAudioCaptureSupportTest;
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +010079 private TestListItem mKeyguardDisabledFeaturesTest;
Rubin Xu55d22d42014-09-24 19:56:58 +010080
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010081 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 Xu55d22d42014-09-24 19:56:58 +010086
87 @Override
88 protected void onCreate(Bundle savedInstanceState) {
89 super.onCreate(savedInstanceState);
90 mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010091
Rubin Xu55d22d42014-09-24 19:56:58 +010092 disableComponent();
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010093 mPrepareTestButton.setText(R.string.provisioning_byod_start);
94 mPrepareTestButton.setOnClickListener(new OnClickListener() {
Rubin Xu55d22d42014-09-24 19:56:58 +010095 @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-Ban27a2bb52015-07-23 11:58:49 +0100120 handleStatusUpdate(RESULT_OK, intent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100121 }
122 }
123
124 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100125 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 Xu55d22d42014-09-24 19:56:58 +0100140 }
141 }
142
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100143 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 Xu55d22d42014-09-24 19:56:58 +0100148 }
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-Ban27a2bb52015-07-23 11:58:49 +0100158 @Override
159 protected void setupTests(ArrayTestListAdapter adapter) {
160 mProfileOwnerInstalled = new DialogTestListItem(this,
161 R.string.provisioning_byod_profileowner,
162 "BYOD_ProfileOwnerInstalled") {
Rubin Xu55d22d42014-09-24 19:56:58 +0100163 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100164 public void performTest(DialogTestListActivity activity) {
Rubin Xu55d22d42014-09-24 19:56:58 +0100165 queryProfileOwner(true);
166 }
167 };
168
Alexandra Gherghina9c1c5a52014-12-09 12:55:23 +0000169 /*
170 * To keep the image in this test up to date, use the instructions in
171 * {@link ByodIconSamplerActivity}.
172 */
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100173 mWorkAppVisibleTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000174 R.string.provisioning_byod_workapps_visible,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100175 "BYOD_WorkAppVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000176 R.string.provisioning_byod_workapps_visible_instruction,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000177 new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),
178 R.drawable.badged_icon);
179
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100180 mWorkNotificationBadgedTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000181 R.string.provisioning_byod_work_notification,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100182 "BYOD_WorkNotificationBadgedTest",
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000183 R.string.provisioning_byod_work_notification_instruction,
184 new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION),
185 R.drawable.ic_corp_icon);
Rubin Xu55d22d42014-09-24 19:56:58 +0100186
Kenny Guy68e7df92015-05-29 15:26:28 +0100187 Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
188 workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100189 mWorkStatusBarIconTest = new DialogTestListItemWithIcon(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100190 R.string.provisioning_byod_work_status_icon,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100191 "BYOD_WorkStatusBarIconTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100192 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-Ban27a2bb52015-07-23 11:58:49 +0100198 mWorkStatusBarToastTest = new DialogTestListItem(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100199 R.string.provisioning_byod_work_status_toast,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100200 "BYOD_WorkStatusBarToastTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100201 R.string.provisioning_byod_work_status_toast_instruction,
202 workStatusToast);
203
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100204 mDisableNonMarketTest = new DialogTestListItem(this,
205 R.string.provisioning_byod_nonmarket_deny,
206 "BYOD_DisableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000207 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-Ban27a2bb52015-07-23 11:58:49 +0100211 mEnableNonMarketTest = new DialogTestListItem(this,
212 R.string.provisioning_byod_nonmarket_allow,
213 "BYOD_EnableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000214 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-Ban27a2bb52015-07-23 11:58:49 +0100218 mProfileAccountVisibleTest = new DialogTestListItem(this,
219 R.string.provisioning_byod_profile_visible,
220 "BYOD_ProfileAccountVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000221 R.string.provisioning_byod_profile_visible_instruction,
222 new Intent(Settings.ACTION_SETTINGS));
223
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100224 mAppSettingsVisibleTest = new DialogTestListItem(this,
225 R.string.provisioning_byod_app_settings,
226 "BYOD_AppSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000227 R.string.provisioning_byod_app_settings_instruction,
228 new Intent(Settings.ACTION_APPLICATION_SETTINGS));
229
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100230 mDeviceAdminVisibleTest = new DialogTestListItem(this,
231 R.string.provisioning_byod_admin_visible,
232 "BYOD_DeviceAdminVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000233 R.string.provisioning_byod_admin_visible_instruction,
234 new Intent(Settings.ACTION_SECURITY_SETTINGS));
235
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100236 mCredSettingsVisibleTest = new DialogTestListItem(this,
237 R.string.provisioning_byod_cred_settings,
238 "BYOD_CredSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000239 R.string.provisioning_byod_cred_settings_instruction,
240 new Intent(Settings.ACTION_SECURITY_SETTINGS));
241
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100242 mLocationSettingsVisibleTest = new DialogTestListItem(this,
Rubin Xuc2b00d82015-02-02 11:30:26 +0000243 R.string.provisioning_byod_location_settings,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100244 "BYOD_LocationSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000245 R.string.provisioning_byod_location_settings_instruction,
246 new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
247
Michal Karpinskibb5c5332015-08-12 16:15:31 +0100248 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-Ban27a2bb52015-07-23 11:58:49 +0100260 mPrintSettingsVisibleTest = new DialogTestListItem(this,
261 R.string.provisioning_byod_print_settings,
262 "BYOD_PrintSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000263 R.string.provisioning_byod_print_settings_instruction,
264 new Intent(Settings.ACTION_PRINT_SETTINGS));
265
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100266 Intent intent = new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000267 Intent chooser = Intent.createChooser(intent,
268 getResources().getString(R.string.provisioning_cross_profile_chooser));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100269 mCrossProfileIntentFiltersTest = new DialogTestListItem(this,
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100270 R.string.provisioning_byod_cross_profile,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100271 "BYOD_CrossProfileIntentFiltersTest",
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100272 R.string.provisioning_byod_cross_profile_instruction,
273 chooser);
274
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +0100275 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 Shanka98ff0002015-03-26 16:32:59 +0000280 // Test for checking if the required intent filters are set during managed provisioning.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100281 mIntentFiltersTest = new DialogTestListItem(this,
282 R.string.provisioning_byod_cross_profile_intent_filters,
283 "BYOD_IntentFiltersTest") {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000284 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100285 public void performTest(DialogTestListActivity activity) {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000286 checkIntentFilters();
287 }
288 };
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100289
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 Shanka98ff0002015-03-26 16:32:59 +0000297
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100298 adapter.add(mProfileOwnerInstalled);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000299
300 // Badge related tests
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100301 adapter.add(mWorkAppVisibleTest);
302 adapter.add(mWorkNotificationBadgedTest);
303 adapter.add(mWorkStatusBarIconTest);
304 adapter.add(mWorkStatusBarToastTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000305
306 // Settings related tests.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100307 adapter.add(mProfileAccountVisibleTest);
308 adapter.add(mDeviceAdminVisibleTest);
309 adapter.add(mCredSettingsVisibleTest);
310 adapter.add(mAppSettingsVisibleTest);
311 adapter.add(mLocationSettingsVisibleTest);
Michal Karpinskibb5c5332015-08-12 16:15:31 +0100312 adapter.add(mBatterySettingsVisibleTest);
313 adapter.add(mDataUsageSettingsVisibleTest);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100314 adapter.add(mPrintSettingsVisibleTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000315
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100316 adapter.add(mCrossProfileIntentFiltersTest);
317 adapter.add(mDisableNonMarketTest);
318 adapter.add(mEnableNonMarketTest);
319 adapter.add(mIntentFiltersTest);
Sudheer Shanka72ba56a2015-07-17 18:30:44 +0100320 adapter.add(mPermissionLockdownTest);
Zoltan Szatmary-Ban46b5ceb2015-07-24 12:28:19 +0100321 adapter.add(mKeyguardDisabledFeaturesTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000322
323 if (canResolveIntent(ByodHelperActivity.getCaptureImageIntent())) {
324 // Capture image intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100325 mCrossProfileImageCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000326 R.string.provisioning_byod_capture_image_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100327 "BYOD_CrossProfileImageCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000328 R.string.provisioning_byod_capture_image_support_info,
329 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100330 adapter.add(mCrossProfileImageCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000331 } 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-Ban27a2bb52015-07-23 11:58:49 +0100340 mCrossProfileVideoCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000341 R.string.provisioning_byod_capture_video_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100342 "BYOD_CrossProfileVideoCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000343 R.string.provisioning_byod_capture_video_support_info,
344 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100345 adapter.add(mCrossProfileVideoCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000346 } 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-Ban27a2bb52015-07-23 11:58:49 +0100356 mCrossProfileAudioCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000357 R.string.provisioning_byod_capture_audio_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100358 "BYOD_CrossProfileAudioCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000359 R.string.provisioning_byod_capture_audio_support_info,
360 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100361 adapter.add(mCrossProfileAudioCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000362 } 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 Xu55d22d42014-09-24 19:56:58 +0100369 }
370
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000371 // 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-Ban27a2bb52015-07-23 11:58:49 +0100376 @Override
377 protected void clearRemainingState(final DialogTestListItem test) {
378 super.clearRemainingState(test);
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000379 if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION.equals(
380 test.getManualTestIntent().getAction())) {
Rubin Xuc2b00d82015-02-02 11:30:26 +0000381 try {
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100382 startActivity(new Intent(
Rubin Xuc2b00d82015-02-02 11:30:26 +0000383 WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION));
384 } catch (ActivityNotFoundException e) {
385 // User shouldn't run this test before work profile is set up.
386 }
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000387 }
388 }
389
Rubin Xu55d22d42014-09-24 19:56:58 +0100390 private void startByodProvisioning() {
391 Intent sending = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
Sudheer Shankab64e0dc2015-03-23 16:42:35 +0000392 sending.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
393 mAdminReceiverComponent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100394
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-Ban27a2bb52015-07-23 11:58:49 +0100398 startActivityForResult(sending, REQUEST_MANAGED_PROVISIONING);
Rubin Xu55d22d42014-09-24 19:56:58 +0100399 } 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 Shanka98ff0002015-03-26 16:32:59 +0000407 startActivityForResult(intent, REQUEST_PROFILE_OWNER_STATUS);
Rubin Xu55d22d42014-09-24 19:56:58 +0100408 }
409 catch (ActivityNotFoundException e) {
410 Log.d(TAG, "queryProfileOwner: ActivityNotFoundException", e);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100411 setTestResult(mProfileOwnerInstalled, TestResult.TEST_RESULT_FAILED);
Rubin Xu55d22d42014-09-24 19:56:58 +0100412 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 Shanka98ff0002015-03-26 16:32:59 +0000429 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-Ban27a2bb52015-07-23 11:58:49 +0100437 setTestResult(mIntentFiltersTest, TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000438 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-Ban27a2bb52015-07-23 11:58:49 +0100455 intentFiltersSet ? TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000456 }
457
Rubin Xu55d22d42014-09-24 19:56:58 +0100458 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 Shanka72ba56a2015-07-17 18:30:44 +0100461 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 Xu55d22d42014-09-24 19:56:58 +0100472 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100473}