blob: 6206ea00f03321bd9dd64b5ecb09de3b2a16aa50 [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-Ban27a2bb52015-07-23 11:58:49 +010035import com.android.cts.verifier.TestResult;
Rubin Xu55d22d42014-09-24 19:56:58 +010036
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-Ban27a2bb52015-07-23 11:58:49 +010048public class ByodFlowTestActivity extends DialogTestListActivity {
Rubin Xu55d22d42014-09-24 19:56:58 +010049
50 private final String TAG = "ByodFlowTestActivity";
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010051 private static final int REQUEST_MANAGED_PROVISIONING = 0;
Sudheer Shanka98ff0002015-03-26 16:32:59 +000052 private static final int REQUEST_PROFILE_OWNER_STATUS = 1;
53 private static final int REQUEST_INTENT_FILTERS_STATUS = 2;
Rubin Xu55d22d42014-09-24 19:56:58 +010054
55 private ComponentName mAdminReceiverComponent;
56
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010057 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 Xu55d22d42014-09-24 19:56:58 +010075
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010076 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 Xu55d22d42014-09-24 19:56:58 +010081
82 @Override
83 protected void onCreate(Bundle savedInstanceState) {
84 super.onCreate(savedInstanceState);
85 mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010086
Rubin Xu55d22d42014-09-24 19:56:58 +010087 disableComponent();
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +010088 mPrepareTestButton.setText(R.string.provisioning_byod_start);
89 mPrepareTestButton.setOnClickListener(new OnClickListener() {
Rubin Xu55d22d42014-09-24 19:56:58 +010090 @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-Ban27a2bb52015-07-23 11:58:49 +0100115 handleStatusUpdate(RESULT_OK, intent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100116 }
117 }
118
119 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100120 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 Xu55d22d42014-09-24 19:56:58 +0100135 }
136 }
137
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100138 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 Xu55d22d42014-09-24 19:56:58 +0100143 }
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-Ban27a2bb52015-07-23 11:58:49 +0100153 @Override
154 protected void setupTests(ArrayTestListAdapter adapter) {
155 mProfileOwnerInstalled = new DialogTestListItem(this,
156 R.string.provisioning_byod_profileowner,
157 "BYOD_ProfileOwnerInstalled") {
Rubin Xu55d22d42014-09-24 19:56:58 +0100158 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100159 public void performTest(DialogTestListActivity activity) {
Rubin Xu55d22d42014-09-24 19:56:58 +0100160 queryProfileOwner(true);
161 }
162 };
163
Alexandra Gherghina9c1c5a52014-12-09 12:55:23 +0000164 /*
165 * To keep the image in this test up to date, use the instructions in
166 * {@link ByodIconSamplerActivity}.
167 */
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100168 mWorkAppVisibleTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000169 R.string.provisioning_byod_workapps_visible,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100170 "BYOD_WorkAppVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000171 R.string.provisioning_byod_workapps_visible_instruction,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000172 new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),
173 R.drawable.badged_icon);
174
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100175 mWorkNotificationBadgedTest = new DialogTestListItemWithIcon(this,
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000176 R.string.provisioning_byod_work_notification,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100177 "BYOD_WorkNotificationBadgedTest",
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000178 R.string.provisioning_byod_work_notification_instruction,
179 new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION),
180 R.drawable.ic_corp_icon);
Rubin Xu55d22d42014-09-24 19:56:58 +0100181
Kenny Guy68e7df92015-05-29 15:26:28 +0100182 Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
183 workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100184 mWorkStatusBarIconTest = new DialogTestListItemWithIcon(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100185 R.string.provisioning_byod_work_status_icon,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100186 "BYOD_WorkStatusBarIconTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100187 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-Ban27a2bb52015-07-23 11:58:49 +0100193 mWorkStatusBarToastTest = new DialogTestListItem(this,
Kenny Guy68e7df92015-05-29 15:26:28 +0100194 R.string.provisioning_byod_work_status_toast,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100195 "BYOD_WorkStatusBarToastTest",
Kenny Guy68e7df92015-05-29 15:26:28 +0100196 R.string.provisioning_byod_work_status_toast_instruction,
197 workStatusToast);
198
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100199 mDisableNonMarketTest = new DialogTestListItem(this,
200 R.string.provisioning_byod_nonmarket_deny,
201 "BYOD_DisableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000202 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-Ban27a2bb52015-07-23 11:58:49 +0100206 mEnableNonMarketTest = new DialogTestListItem(this,
207 R.string.provisioning_byod_nonmarket_allow,
208 "BYOD_EnableNonMarketTest",
Robin Lee020f1852015-01-15 11:56:05 +0000209 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-Ban27a2bb52015-07-23 11:58:49 +0100213 mProfileAccountVisibleTest = new DialogTestListItem(this,
214 R.string.provisioning_byod_profile_visible,
215 "BYOD_ProfileAccountVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000216 R.string.provisioning_byod_profile_visible_instruction,
217 new Intent(Settings.ACTION_SETTINGS));
218
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100219 mAppSettingsVisibleTest = new DialogTestListItem(this,
220 R.string.provisioning_byod_app_settings,
221 "BYOD_AppSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000222 R.string.provisioning_byod_app_settings_instruction,
223 new Intent(Settings.ACTION_APPLICATION_SETTINGS));
224
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100225 mDeviceAdminVisibleTest = new DialogTestListItem(this,
226 R.string.provisioning_byod_admin_visible,
227 "BYOD_DeviceAdminVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000228 R.string.provisioning_byod_admin_visible_instruction,
229 new Intent(Settings.ACTION_SECURITY_SETTINGS));
230
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100231 mCredSettingsVisibleTest = new DialogTestListItem(this,
232 R.string.provisioning_byod_cred_settings,
233 "BYOD_CredSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000234 R.string.provisioning_byod_cred_settings_instruction,
235 new Intent(Settings.ACTION_SECURITY_SETTINGS));
236
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100237 mLocationSettingsVisibleTest = new DialogTestListItem(this,
Rubin Xuc2b00d82015-02-02 11:30:26 +0000238 R.string.provisioning_byod_location_settings,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100239 "BYOD_LocationSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000240 R.string.provisioning_byod_location_settings_instruction,
241 new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
242
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100243 mPrintSettingsVisibleTest = new DialogTestListItem(this,
244 R.string.provisioning_byod_print_settings,
245 "BYOD_PrintSettingsVisibleTest",
Rubin Xuc2b00d82015-02-02 11:30:26 +0000246 R.string.provisioning_byod_print_settings_instruction,
247 new Intent(Settings.ACTION_PRINT_SETTINGS));
248
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100249 Intent intent = new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000250 Intent chooser = Intent.createChooser(intent,
251 getResources().getString(R.string.provisioning_cross_profile_chooser));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100252 mCrossProfileIntentFiltersTest = new DialogTestListItem(this,
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100253 R.string.provisioning_byod_cross_profile,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100254 "BYOD_CrossProfileIntentFiltersTest",
Alexandra Gherghinaaa24ed72014-10-08 01:11:32 +0100255 R.string.provisioning_byod_cross_profile_instruction,
256 chooser);
257
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000258 // Test for checking if the required intent filters are set during managed provisioning.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100259 mIntentFiltersTest = new DialogTestListItem(this,
260 R.string.provisioning_byod_cross_profile_intent_filters,
261 "BYOD_IntentFiltersTest") {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000262 @Override
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100263 public void performTest(DialogTestListActivity activity) {
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000264 checkIntentFilters();
265 }
266 };
267
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100268 adapter.add(mProfileOwnerInstalled);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000269
270 // Badge related tests
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100271 adapter.add(mWorkAppVisibleTest);
272 adapter.add(mWorkNotificationBadgedTest);
273 adapter.add(mWorkStatusBarIconTest);
274 adapter.add(mWorkStatusBarToastTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000275
276 // Settings related tests.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100277 adapter.add(mProfileAccountVisibleTest);
278 adapter.add(mDeviceAdminVisibleTest);
279 adapter.add(mCredSettingsVisibleTest);
280 adapter.add(mAppSettingsVisibleTest);
281 adapter.add(mLocationSettingsVisibleTest);
282 adapter.add(mPrintSettingsVisibleTest);
Rubin Xuc2b00d82015-02-02 11:30:26 +0000283
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100284 adapter.add(mCrossProfileIntentFiltersTest);
285 adapter.add(mDisableNonMarketTest);
286 adapter.add(mEnableNonMarketTest);
287 adapter.add(mIntentFiltersTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000288
289 if (canResolveIntent(ByodHelperActivity.getCaptureImageIntent())) {
290 // Capture image intent can be resolved in primary profile, so test.
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100291 mCrossProfileImageCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000292 R.string.provisioning_byod_capture_image_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100293 "BYOD_CrossProfileImageCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000294 R.string.provisioning_byod_capture_image_support_info,
295 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_IMAGE));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100296 adapter.add(mCrossProfileImageCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000297 } 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-Ban27a2bb52015-07-23 11:58:49 +0100306 mCrossProfileVideoCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000307 R.string.provisioning_byod_capture_video_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100308 "BYOD_CrossProfileVideoCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000309 R.string.provisioning_byod_capture_video_support_info,
310 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_VIDEO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100311 adapter.add(mCrossProfileVideoCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000312 } 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-Ban27a2bb52015-07-23 11:58:49 +0100322 mCrossProfileAudioCaptureSupportTest = new DialogTestListItem(this,
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000323 R.string.provisioning_byod_capture_audio_support,
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100324 "BYOD_CrossProfileAudioCaptureSupportTest",
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000325 R.string.provisioning_byod_capture_audio_support_info,
326 new Intent(ByodHelperActivity.ACTION_CAPTURE_AND_CHECK_AUDIO));
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100327 adapter.add(mCrossProfileAudioCaptureSupportTest);
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000328 } 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 Xu55d22d42014-09-24 19:56:58 +0100335 }
336
Sander Alewijnse7e24fda2015-03-26 17:41:57 +0000337 // 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-Ban27a2bb52015-07-23 11:58:49 +0100342 @Override
343 protected void clearRemainingState(final DialogTestListItem test) {
344 super.clearRemainingState(test);
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000345 if (WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION.equals(
346 test.getManualTestIntent().getAction())) {
Rubin Xuc2b00d82015-02-02 11:30:26 +0000347 try {
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100348 startActivity(new Intent(
Rubin Xuc2b00d82015-02-02 11:30:26 +0000349 WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION));
350 } catch (ActivityNotFoundException e) {
351 // User shouldn't run this test before work profile is set up.
352 }
Alexandra Gherghina2c672b72015-01-22 11:20:23 +0000353 }
354 }
355
Rubin Xu55d22d42014-09-24 19:56:58 +0100356 private void startByodProvisioning() {
357 Intent sending = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
Sudheer Shankab64e0dc2015-03-23 16:42:35 +0000358 sending.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
359 mAdminReceiverComponent);
Rubin Xu55d22d42014-09-24 19:56:58 +0100360
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-Ban27a2bb52015-07-23 11:58:49 +0100364 startActivityForResult(sending, REQUEST_MANAGED_PROVISIONING);
Rubin Xu55d22d42014-09-24 19:56:58 +0100365 } 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 Shanka98ff0002015-03-26 16:32:59 +0000373 startActivityForResult(intent, REQUEST_PROFILE_OWNER_STATUS);
Rubin Xu55d22d42014-09-24 19:56:58 +0100374 }
375 catch (ActivityNotFoundException e) {
376 Log.d(TAG, "queryProfileOwner: ActivityNotFoundException", e);
Zoltan Szatmary-Ban27a2bb52015-07-23 11:58:49 +0100377 setTestResult(mProfileOwnerInstalled, TestResult.TEST_RESULT_FAILED);
Rubin Xu55d22d42014-09-24 19:56:58 +0100378 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 Shanka98ff0002015-03-26 16:32:59 +0000395 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-Ban27a2bb52015-07-23 11:58:49 +0100403 setTestResult(mIntentFiltersTest, TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000404 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-Ban27a2bb52015-07-23 11:58:49 +0100421 intentFiltersSet ? TestResult.TEST_RESULT_PASSED : TestResult.TEST_RESULT_FAILED);
Sudheer Shanka98ff0002015-03-26 16:32:59 +0000422 }
423
Rubin Xu55d22d42014-09-24 19:56:58 +0100424 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 Gherghina2c672b72015-01-22 11:20:23 +0000431 getPackageManager().setComponentEnabledSetting(new ComponentName(
432 this, WorkNotificationTestActivity.class),
433 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
434 PackageManager.DONT_KILL_APP);
Kenny Guy68e7df92015-05-29 15:26:28 +0100435 getPackageManager().setComponentEnabledSetting(new ComponentName(
436 this, WorkStatusTestActivity.class),
437 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
438 PackageManager.DONT_KILL_APP);
Rubin Xu55d22d42014-09-24 19:56:58 +0100439 }
Rubin Xu55d22d42014-09-24 19:56:58 +0100440}