1 /* 2 * Copyright 2016, 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 package com.android.managedprovisioning.model; 17 18 import static android.app.admin.DevicePolicyManager.PROVISIONING_MODE_FULLY_MANAGED_DEVICE; 19 import static android.app.admin.DevicePolicyManager.PROVISIONING_MODE_MANAGED_PROFILE; 20 import static android.app.admin.DevicePolicyManager.PROVISIONING_MODE_MANAGED_PROFILE_ON_PERSONAL_DEVICE; 21 import static android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_CLOUD_ENROLLMENT; 22 import static android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_PERSISTENT_DEVICE_OWNER; 23 import static android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_QR_CODE; 24 import static android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_UNSPECIFIED; 25 26 import static com.android.managedprovisioning.TestUtils.createTestAdminExtras; 27 import static com.android.managedprovisioning.model.ProvisioningParams.FLOW_TYPE_ADMIN_INTEGRATED; 28 import static com.android.managedprovisioning.model.ProvisioningParams.FLOW_TYPE_LEGACY; 29 import static com.android.managedprovisioning.model.ProvisioningParams.FLOW_TYPE_UNSPECIFIED; 30 31 import static com.google.common.truth.Truth.assertThat; 32 33 import static org.mockito.ArgumentMatchers.eq; 34 import static org.mockito.ArgumentMatchers.nullable; 35 import static org.mockito.Mockito.when; 36 37 import android.accounts.Account; 38 import android.app.admin.DevicePolicyManager; 39 import android.content.ComponentName; 40 import android.os.Parcel; 41 import android.os.UserHandle; 42 import android.test.AndroidTestCase; 43 44 import androidx.test.filters.SmallTest; 45 46 import com.android.managedprovisioning.common.IllegalProvisioningArgumentException; 47 import com.android.managedprovisioning.common.Utils; 48 49 import org.mockito.Mock; 50 import org.mockito.MockitoAnnotations; 51 52 import java.io.File; 53 import java.util.ArrayList; 54 import java.util.List; 55 import java.util.Locale; 56 57 /** Tests for {@link ProvisioningParams} */ 58 public class ProvisioningParamsTest extends AndroidTestCase { 59 private static final String TEST_PROVISIONING_ACTION = 60 DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE; 61 62 private static final String TEST_PACKAGE_NAME = "com.afwsamples.testdpc"; 63 private static final ComponentName TEST_COMPONENT_NAME = 64 ComponentName.unflattenFromString( 65 "com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver"); 66 private static final long TEST_LOCAL_TIME = 1456939524713L; 67 private static final Locale TEST_LOCALE = Locale.UK; 68 private static final String TEST_TIME_ZONE = "GMT"; 69 private static final boolean TEST_STARTED_BY_TRUSTED_SOURCE = true; 70 private static final boolean TEST_IS_NFC = true; 71 private static final boolean TEST_LEAVE_ALL_SYSTEM_APP_ENABLED = true; 72 private static final boolean TEST_SKIP_ENCRYPTION = true; 73 private static final Account TEST_ACCOUNT_TO_MIGRATE = 74 new Account("user@gmail.com", "com.google"); 75 private static final boolean TEST_USE_MOBILE_DATA = true; 76 77 // Wifi info 78 private static final String TEST_SSID = "\"TestWifi\""; 79 private static final boolean TEST_HIDDEN = true; 80 private static final String TEST_SECURITY_TYPE = "WPA2"; 81 private static final String TEST_PASSWORD = "GoogleRock"; 82 private static final String TEST_PROXY_HOST = "testhost.com"; 83 private static final int TEST_PROXY_PORT = 7689; 84 private static final String TEST_PROXY_BYPASS_HOSTS = "http://host1.com;https://host2.com"; 85 private static final String TEST_PAC_URL = "pac.test.com"; 86 private static final WifiInfo TEST_WIFI_INFO = WifiInfo.Builder.builder() 87 .setSsid(TEST_SSID) 88 .setHidden(TEST_HIDDEN) 89 .setSecurityType(TEST_SECURITY_TYPE) 90 .setPassword(TEST_PASSWORD) 91 .setProxyHost(TEST_PROXY_HOST) 92 .setProxyPort(TEST_PROXY_PORT) 93 .setProxyBypassHosts(TEST_PROXY_BYPASS_HOSTS) 94 .setPacUrl(TEST_PAC_URL) 95 .build(); 96 97 // Device admin package download info 98 private static final String TEST_DOWNLOAD_LOCATION = 99 "http://example/dpc.apk"; 100 private static final String TEST_COOKIE_HEADER = 101 "Set-Cookie: sessionToken=foobar; Expires=Thu, 18 Feb 2016 23:59:59 GMT"; 102 private static final byte[] TEST_PACKAGE_CHECKSUM = new byte[] { '1', '2', '3', '4', '5' }; 103 private static final byte[] TEST_SIGNATURE_CHECKSUM = new byte[] { '5', '4', '3', '2', '1' }; 104 private static final int TEST_MIN_SUPPORT_VERSION = 17689; 105 private static final PackageDownloadInfo TEST_DOWNLOAD_INFO = 106 PackageDownloadInfo.Builder.builder() 107 .setLocation(TEST_DOWNLOAD_LOCATION) 108 .setCookieHeader(TEST_COOKIE_HEADER) 109 .setPackageChecksum(TEST_PACKAGE_CHECKSUM) 110 .setSignatureChecksum(TEST_SIGNATURE_CHECKSUM) 111 .setMinVersion(TEST_MIN_SUPPORT_VERSION) 112 .build(); 113 private static final PackageDownloadInfo ROLE_HOLDER_DOWNLOAD_INFO_LOCATION_AND_SIGNATURE = 114 PackageDownloadInfo.Builder.builder() 115 .setLocation(TEST_DOWNLOAD_LOCATION) 116 .setSignatureChecksum(TEST_SIGNATURE_CHECKSUM) 117 .build(); 118 private static final PackageDownloadInfo ROLE_HOLDER_DOWNLOAD_INFO = 119 PackageDownloadInfo.Builder.builder() 120 .setLocation(TEST_DOWNLOAD_LOCATION) 121 .setSignatureChecksum(TEST_SIGNATURE_CHECKSUM) 122 .setCookieHeader(TEST_COOKIE_HEADER) 123 .build(); 124 125 @Mock 126 private Utils mUtils; 127 128 @Override setUp()129 protected void setUp() throws Exception { 130 super.setUp(); 131 MockitoAnnotations.initMocks(this); 132 } 133 134 @SmallTest testFailToConstructProvisioningParamsWithoutPackageNameOrComponentName()135 public void testFailToConstructProvisioningParamsWithoutPackageNameOrComponentName() { 136 // WHEN the ProvisioningParams is constructed by with neither a package name nor a component 137 // name 138 try { 139 ProvisioningParams provisioningParams = ProvisioningParams.Builder.builder() 140 .setProvisioningAction(TEST_PROVISIONING_ACTION) 141 .build(); 142 fail("Package name or component name is mandatory."); 143 } catch (IllegalArgumentException e) { 144 // THEN the ProvisioningParams fails to construct. 145 } 146 } 147 148 @SmallTest testFailToConstructProvisioningParamsWithoutProvisioningAction()149 public void testFailToConstructProvisioningParamsWithoutProvisioningAction() { 150 // WHEN the ProvisioningParams is constructed by without a provisioning action. 151 try { 152 ProvisioningParams provisioningParams = ProvisioningParams.Builder.builder() 153 .setDeviceAdminComponentName(TEST_COMPONENT_NAME) 154 .build(); 155 fail("Provisioning action is mandatory"); 156 } catch (NullPointerException e) { 157 // THEN the ProvisioningParams fails to construct. 158 } 159 } 160 161 @SmallTest testEquals()162 public void testEquals() { 163 // GIVEN 2 ProvisioningParams objects created by the same set of parameters 164 ProvisioningParams provisioningParams1 = getCompleteProvisioningParams(); 165 ProvisioningParams provisioningParams2 = getCompleteProvisioningParams(); 166 167 // WHEN these two objects compare. 168 // THEN they are the same. 169 assertThat(provisioningParams1).isEqualTo(provisioningParams2); 170 } 171 172 @SmallTest testNotEquals()173 public void testNotEquals() { 174 // GIVEN 2 ProvisioningParams objects created by different sets of parameters 175 ProvisioningParams provisioningParams1 = ProvisioningParams.Builder.builder() 176 .setProvisioningAction(TEST_PROVISIONING_ACTION) 177 .setDeviceAdminPackageName(TEST_PACKAGE_NAME) 178 .setDeviceAdminComponentName(TEST_COMPONENT_NAME) 179 .setDeviceAdminDownloadInfo(TEST_DOWNLOAD_INFO) 180 .setLocalTime(TEST_LOCAL_TIME) 181 .setLocale(TEST_LOCALE) 182 .setTimeZone(TEST_TIME_ZONE) 183 .setStartedByTrustedSource(TEST_STARTED_BY_TRUSTED_SOURCE) 184 .setLeaveAllSystemAppsEnabled(TEST_LEAVE_ALL_SYSTEM_APP_ENABLED) 185 .setSkipEncryption(TEST_SKIP_ENCRYPTION) 186 .setAccountToMigrate(TEST_ACCOUNT_TO_MIGRATE) 187 .setWifiInfo(TEST_WIFI_INFO) 188 .setUseMobileData(TEST_USE_MOBILE_DATA) 189 .setAdminExtrasBundle(createTestAdminExtras()) 190 .build(); 191 ProvisioningParams provisioningParams2 = ProvisioningParams.Builder.builder() 192 .setProvisioningAction("different.action") 193 .setDeviceAdminPackageName(TEST_PACKAGE_NAME) 194 .setDeviceAdminComponentName(TEST_COMPONENT_NAME) 195 .setDeviceAdminDownloadInfo(TEST_DOWNLOAD_INFO) 196 .setLocalTime(TEST_LOCAL_TIME) 197 .setLocale(TEST_LOCALE) 198 .setTimeZone(TEST_TIME_ZONE) 199 .setStartedByTrustedSource(TEST_STARTED_BY_TRUSTED_SOURCE) 200 .setLeaveAllSystemAppsEnabled(TEST_LEAVE_ALL_SYSTEM_APP_ENABLED) 201 .setSkipEncryption(TEST_SKIP_ENCRYPTION) 202 .setAccountToMigrate(TEST_ACCOUNT_TO_MIGRATE) 203 .setWifiInfo(TEST_WIFI_INFO) 204 .setUseMobileData(TEST_USE_MOBILE_DATA) 205 .setAdminExtrasBundle(createTestAdminExtras()) 206 .build(); 207 208 // WHEN these two objects compare. 209 // THEN they are not the same. 210 assertThat(provisioningParams1).isNotEqualTo(provisioningParams2); 211 } 212 213 @SmallTest testSaveAndRestoreComplete()214 public void testSaveAndRestoreComplete() throws Exception { 215 testSaveAndRestore(getCompleteProvisioningParams()); 216 } 217 218 // Testing with a minimum set of parameters to cover all null use cases. 219 @SmallTest testSaveAndRestoreMinimalist()220 public void testSaveAndRestoreMinimalist() throws Exception { 221 testSaveAndRestore(ProvisioningParams.Builder.builder() 222 .setProvisioningAction(TEST_PROVISIONING_ACTION) 223 .setDeviceAdminPackageName(TEST_PACKAGE_NAME) 224 .build()); 225 } 226 testSaveAndRestore(ProvisioningParams original)227 private void testSaveAndRestore(ProvisioningParams original) { 228 // GIVEN a ProvisioningParams object 229 // WHEN the ProvisioningParams is written to xml and then read back 230 File file = new File(mContext.getFilesDir(), "test_store.xml"); 231 original.save(file); 232 ProvisioningParams copy = ProvisioningParams.load(file); 233 // THEN the same ProvisioningParams is obtained 234 assertThat(original).isEqualTo(copy); 235 } 236 237 @SmallTest testParceable()238 public void testParceable() { 239 // GIVEN a ProvisioningParams object. 240 ProvisioningParams expectedProvisioningParams = getCompleteProvisioningParams(); 241 242 // WHEN the ProvisioningParams is written to parcel and then read back. 243 Parcel parcel = Parcel.obtain(); 244 expectedProvisioningParams.writeToParcel(parcel, 0); 245 parcel.setDataPosition(0); 246 ProvisioningParams actualProvisioningParams = 247 ProvisioningParams.CREATOR.createFromParcel(parcel); 248 249 // THEN the same ProvisioningParams is obtained. 250 assertThat(expectedProvisioningParams).isEqualTo(actualProvisioningParams); 251 } 252 253 @SmallTest testInferDeviceAdminComponentName_componentNameIsGiven()254 public void testInferDeviceAdminComponentName_componentNameIsGiven() 255 throws IllegalProvisioningArgumentException { 256 ProvisioningParams provisioningParams = new 257 ProvisioningParams.Builder() 258 .setDeviceAdminComponentName(TEST_COMPONENT_NAME) 259 .setProvisioningAction(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE) 260 .build(); 261 262 assertThat(TEST_COMPONENT_NAME) 263 .isEqualTo(provisioningParams.inferDeviceAdminComponentName( 264 mUtils, mContext, UserHandle.myUserId())); 265 } 266 267 @SmallTest testInferDeviceAdminComponentName_componentNameIsNotGiven()268 public void testInferDeviceAdminComponentName_componentNameIsNotGiven() 269 throws IllegalProvisioningArgumentException { 270 ProvisioningParams provisioningParams = new 271 ProvisioningParams.Builder() 272 .setDeviceAdminPackageName(TEST_PACKAGE_NAME) 273 .setProvisioningAction(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE) 274 .build(); 275 276 when(mUtils.findDeviceAdmin(eq(TEST_PACKAGE_NAME), nullable(ComponentName.class), 277 eq(mContext), eq(UserHandle.myUserId()))).thenReturn(TEST_COMPONENT_NAME); 278 279 assertThat(TEST_COMPONENT_NAME) 280 .isEqualTo(provisioningParams.inferDeviceAdminComponentName( 281 mUtils, mContext, UserHandle.myUserId())); 282 } 283 284 @SmallTest testSetUseMobileData_true()285 public void testSetUseMobileData_true() { 286 ProvisioningParams provisioningParams = 287 createDefaultProvisioningParamsBuilder().setUseMobileData(true).build(); 288 assertThat(provisioningParams.useMobileData).isTrue(); 289 } 290 291 @SmallTest testSetUseMobileData_false()292 public void testSetUseMobileData_false() { 293 ProvisioningParams provisioningParams = 294 createDefaultProvisioningParamsBuilder().setUseMobileData(false).build(); 295 assertThat(provisioningParams.useMobileData).isFalse(); 296 } 297 298 @SmallTest testSetUseMobileData_defaultsToFalse()299 public void testSetUseMobileData_defaultsToFalse() { 300 assertThat(createDefaultProvisioningParamsBuilder().build().useMobileData).isFalse(); 301 } 302 303 @SmallTest testSetFlowType_legacy_areEqual()304 public void testSetFlowType_legacy_areEqual() { 305 ProvisioningParams provisioningParams = 306 createDefaultProvisioningParamsBuilder() 307 .setFlowType(FLOW_TYPE_LEGACY).build(); 308 309 assertThat(provisioningParams.flowType).isEqualTo(FLOW_TYPE_LEGACY); 310 } 311 312 @SmallTest testSetFlowType_adminIntegrated_areEqual()313 public void testSetFlowType_adminIntegrated_areEqual() { 314 ProvisioningParams provisioningParams = 315 createDefaultProvisioningParamsBuilder() 316 .setFlowType(FLOW_TYPE_ADMIN_INTEGRATED).build(); 317 318 assertThat(provisioningParams.flowType).isEqualTo(FLOW_TYPE_ADMIN_INTEGRATED); 319 } 320 321 @SmallTest testSetFlowType_defaultsToUnspecified()322 public void testSetFlowType_defaultsToUnspecified() { 323 assertThat(createDefaultProvisioningParamsBuilder().build().flowType) 324 .isEqualTo(FLOW_TYPE_UNSPECIFIED); 325 } 326 327 @SmallTest testSetProvisioningTrigger_cloudEnrollment_areEqual()328 public void testSetProvisioningTrigger_cloudEnrollment_areEqual() { 329 ProvisioningParams provisioningParams = 330 createDefaultProvisioningParamsBuilder() 331 .setProvisioningTrigger(PROVISIONING_TRIGGER_CLOUD_ENROLLMENT).build(); 332 333 assertThat(provisioningParams.provisioningTrigger) 334 .isEqualTo(PROVISIONING_TRIGGER_CLOUD_ENROLLMENT); 335 } 336 337 @SmallTest testSetProvisioningTrigger_qrCode_areEqual()338 public void testSetProvisioningTrigger_qrCode_areEqual() { 339 ProvisioningParams provisioningParams = 340 createDefaultProvisioningParamsBuilder() 341 .setProvisioningTrigger(PROVISIONING_TRIGGER_QR_CODE).build(); 342 343 assertThat(provisioningParams.provisioningTrigger).isEqualTo(PROVISIONING_TRIGGER_QR_CODE); 344 } 345 346 @SmallTest testSetProvisioningTrigger_persistentDeviceOwner_areEqual()347 public void testSetProvisioningTrigger_persistentDeviceOwner_areEqual() { 348 ProvisioningParams provisioningParams = 349 createDefaultProvisioningParamsBuilder() 350 .setProvisioningTrigger(PROVISIONING_TRIGGER_PERSISTENT_DEVICE_OWNER) 351 .build(); 352 353 assertThat(provisioningParams.provisioningTrigger) 354 .isEqualTo(PROVISIONING_TRIGGER_PERSISTENT_DEVICE_OWNER); 355 } 356 357 @SmallTest testSetProvisioningTrigger_defaultsToUnspecified()358 public void testSetProvisioningTrigger_defaultsToUnspecified() { 359 assertThat(createDefaultProvisioningParamsBuilder().build().provisioningTrigger) 360 .isEqualTo(PROVISIONING_TRIGGER_UNSPECIFIED); 361 } 362 363 @SmallTest testSetAllowedProvisioningModes_defaultsToEmptyArray()364 public void testSetAllowedProvisioningModes_defaultsToEmptyArray() { 365 assertThat(createDefaultProvisioningParamsBuilder().build().allowedProvisioningModes) 366 .isEmpty(); 367 } 368 369 @SmallTest testSetAllowedProvisioningModes_personallyOwned_areEqual()370 public void testSetAllowedProvisioningModes_personallyOwned_areEqual() { 371 ProvisioningParams params = 372 createDefaultProvisioningParamsBuilder() 373 .setAllowedProvisioningModes(new ArrayList<>(List.of( 374 PROVISIONING_MODE_MANAGED_PROFILE))) 375 .build(); 376 377 assertThat(params.allowedProvisioningModes) 378 .containsExactly(PROVISIONING_MODE_MANAGED_PROFILE); 379 } 380 381 @SmallTest testSetAllowedProvisioningModes_organizationOwned_areEqual()382 public void testSetAllowedProvisioningModes_organizationOwned_areEqual() { 383 ProvisioningParams params = 384 createDefaultProvisioningParamsBuilder() 385 .setAllowedProvisioningModes(new ArrayList<>(List.of( 386 PROVISIONING_MODE_MANAGED_PROFILE, 387 PROVISIONING_MODE_FULLY_MANAGED_DEVICE))) 388 .build(); 389 390 assertThat(params.allowedProvisioningModes).containsExactly( 391 PROVISIONING_MODE_MANAGED_PROFILE, 392 PROVISIONING_MODE_FULLY_MANAGED_DEVICE); 393 } 394 395 @SmallTest testSetAllowedProvisioningModes_organizationAndPersonallyOwned_areEqual()396 public void testSetAllowedProvisioningModes_organizationAndPersonallyOwned_areEqual() { 397 ProvisioningParams params = 398 createDefaultProvisioningParamsBuilder() 399 .setAllowedProvisioningModes(new ArrayList<>(List.of( 400 PROVISIONING_MODE_MANAGED_PROFILE, 401 PROVISIONING_MODE_FULLY_MANAGED_DEVICE, 402 PROVISIONING_MODE_MANAGED_PROFILE_ON_PERSONAL_DEVICE))) 403 .build(); 404 405 assertThat(params.allowedProvisioningModes).containsExactly( 406 PROVISIONING_MODE_MANAGED_PROFILE, 407 PROVISIONING_MODE_FULLY_MANAGED_DEVICE, 408 PROVISIONING_MODE_MANAGED_PROFILE_ON_PERSONAL_DEVICE); 409 } 410 411 @SmallTest testSetSkipOwnershipDisclaimer_setTrue_isTrue()412 public void testSetSkipOwnershipDisclaimer_setTrue_isTrue() { 413 ProvisioningParams provisioningParams = 414 createDefaultProvisioningParamsBuilder() 415 .setSkipOwnershipDisclaimer(true) 416 .build(); 417 418 assertThat(provisioningParams.skipOwnershipDisclaimer).isTrue(); 419 } 420 421 @SmallTest testSetSkipOwnershipDisclaimer_setFalse_isFalse()422 public void testSetSkipOwnershipDisclaimer_setFalse_isFalse() { 423 ProvisioningParams provisioningParams = 424 createDefaultProvisioningParamsBuilder() 425 .setSkipOwnershipDisclaimer(false) 426 .build(); 427 428 assertThat(provisioningParams.skipOwnershipDisclaimer).isFalse(); 429 } 430 431 @SmallTest testSetSkipOwnershipDisclaimer_notSet_isFalse()432 public void testSetSkipOwnershipDisclaimer_notSet_isFalse() { 433 ProvisioningParams provisioningParams = 434 createDefaultProvisioningParamsBuilder() 435 .build(); 436 437 assertThat(provisioningParams.skipOwnershipDisclaimer).isFalse(); 438 } 439 440 @SmallTest testSetReturnBeforePolicyCompliance_setTrue_isTrue()441 public void testSetReturnBeforePolicyCompliance_setTrue_isTrue() { 442 ProvisioningParams provisioningParams = 443 createDefaultProvisioningParamsBuilder() 444 .setReturnBeforePolicyCompliance(true) 445 .build(); 446 447 assertThat(provisioningParams.returnBeforePolicyCompliance).isTrue(); 448 } 449 450 @SmallTest testSetReturnBeforePolicyCompliance_setFalse_isFalse()451 public void testSetReturnBeforePolicyCompliance_setFalse_isFalse() { 452 ProvisioningParams provisioningParams = 453 createDefaultProvisioningParamsBuilder() 454 .setReturnBeforePolicyCompliance(false) 455 .build(); 456 457 assertThat(provisioningParams.returnBeforePolicyCompliance).isFalse(); 458 } 459 460 @SmallTest testSetReturnBeforePolicyCompliance_notSet_isFalse()461 public void testSetReturnBeforePolicyCompliance_notSet_isFalse() { 462 ProvisioningParams provisioningParams = 463 createDefaultProvisioningParamsBuilder() 464 .build(); 465 466 assertThat(provisioningParams.returnBeforePolicyCompliance).isFalse(); 467 } 468 469 @SmallTest testDeviceOwnerDoesNotOptOutOfSensorsPermissionGrantsByDefault()470 public void testDeviceOwnerDoesNotOptOutOfSensorsPermissionGrantsByDefault() { 471 ProvisioningParams params = createDefaultProvisioningParamsBuilder().build(); 472 assertThat(params.deviceOwnerPermissionGrantOptOut).isFalse(); 473 } 474 475 @SmallTest testDeviceOwnerCanOptOutOfSensorsPermissionGrants()476 public void testDeviceOwnerCanOptOutOfSensorsPermissionGrants() { 477 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 478 .setDeviceOwnerPermissionGrantOptOut(true).build(); 479 assertThat(params.deviceOwnerPermissionGrantOptOut).isTrue(); 480 } 481 482 @SmallTest testSetAllowProvisioningAfterUserSetupComplete_setTrue_isTrue()483 public void testSetAllowProvisioningAfterUserSetupComplete_setTrue_isTrue() { 484 ProvisioningParams provisioningParams = 485 createDefaultProvisioningParamsBuilder() 486 .setAllowProvisioningAfterUserSetupComplete(true) 487 .build(); 488 489 assertThat(provisioningParams.allowProvisioningAfterUserSetupComplete).isTrue(); 490 } 491 492 @SmallTest testSetAllowProvisioningAfterUserSetupComplete_setFalse_isFalse()493 public void testSetAllowProvisioningAfterUserSetupComplete_setFalse_isFalse() { 494 ProvisioningParams provisioningParams = 495 createDefaultProvisioningParamsBuilder() 496 .setAllowProvisioningAfterUserSetupComplete(false) 497 .build(); 498 499 assertThat(provisioningParams.allowProvisioningAfterUserSetupComplete).isFalse(); 500 } 501 502 @SmallTest testSetAllowProvisioningAfterUserSetupComplete_notSet_isFalse()503 public void testSetAllowProvisioningAfterUserSetupComplete_notSet_isFalse() { 504 ProvisioningParams provisioningParams = 505 createDefaultProvisioningParamsBuilder() 506 .build(); 507 508 assertThat(provisioningParams.allowProvisioningAfterUserSetupComplete).isFalse(); 509 } 510 511 @SmallTest testAllowOffline_setTrue_isTrue()512 public void testAllowOffline_setTrue_isTrue() { 513 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 514 .setAllowOffline(true) 515 .build(); 516 517 assertThat(params.allowOffline).isTrue(); 518 } 519 520 @SmallTest testAllowOffline_setFalse_isFalse()521 public void testAllowOffline_setFalse_isFalse() { 522 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 523 .setAllowOffline(false) 524 .build(); 525 526 assertThat(params.allowOffline).isFalse(); 527 } 528 529 @SmallTest testProvisioningShouldLaunchResultIntent_notSet_isFalse()530 public void testProvisioningShouldLaunchResultIntent_notSet_isFalse() { 531 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 532 .build(); 533 534 assertThat(params.provisioningShouldLaunchResultIntent).isFalse(); 535 } 536 537 @SmallTest testProvisioningShouldLaunchResultIntent_setTrue_isTrue()538 public void testProvisioningShouldLaunchResultIntent_setTrue_isTrue() { 539 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 540 .setProvisioningShouldLaunchResultIntent(true) 541 .build(); 542 543 assertThat(params.provisioningShouldLaunchResultIntent).isTrue(); 544 } 545 546 @SmallTest testProvisioningShouldLaunchResultIntent_setFalse_isFalse()547 public void testProvisioningShouldLaunchResultIntent_setFalse_isFalse() { 548 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 549 .setProvisioningShouldLaunchResultIntent(false) 550 .build(); 551 552 assertThat(params.provisioningShouldLaunchResultIntent).isFalse(); 553 } 554 555 @SmallTest testRoleHolderDownload_roleHolderDownloadInfoSet_notNull()556 public void testRoleHolderDownload_roleHolderDownloadInfoSet_notNull() { 557 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 558 .setRoleHolderDownloadInfo(ROLE_HOLDER_DOWNLOAD_INFO) 559 .build(); 560 561 assertThat(params.roleHolderDownloadInfo).isNotNull(); 562 } 563 564 @SmallTest testRoleHolderDownload_roleHolderDownloadInfoWithLocationAndSignature_works()565 public void testRoleHolderDownload_roleHolderDownloadInfoWithLocationAndSignature_works() { 566 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 567 .setRoleHolderDownloadInfo(ROLE_HOLDER_DOWNLOAD_INFO_LOCATION_AND_SIGNATURE) 568 .build(); 569 570 assertThat(params.roleHolderDownloadInfo.location).isEqualTo(TEST_DOWNLOAD_LOCATION); 571 assertThat(params.roleHolderDownloadInfo.signatureChecksum).isEqualTo( 572 TEST_SIGNATURE_CHECKSUM); 573 } 574 575 @SmallTest testRoleHolderDownload_roleHolderDownloadInfo_works()576 public void testRoleHolderDownload_roleHolderDownloadInfo_works() { 577 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 578 .setRoleHolderDownloadInfo(ROLE_HOLDER_DOWNLOAD_INFO) 579 .build(); 580 581 assertThat(params.roleHolderDownloadInfo.location).isEqualTo(TEST_DOWNLOAD_LOCATION); 582 assertThat(params.roleHolderDownloadInfo.signatureChecksum).isEqualTo( 583 TEST_SIGNATURE_CHECKSUM); 584 assertThat(params.roleHolderDownloadInfo.cookieHeader).isEqualTo(TEST_COOKIE_HEADER); 585 } 586 587 @SmallTest testRoleHolderDownload_defaultCookieHeaderNull()588 public void testRoleHolderDownload_defaultCookieHeaderNull() { 589 ProvisioningParams params = createDefaultProvisioningParamsBuilder() 590 .setRoleHolderDownloadInfo(ROLE_HOLDER_DOWNLOAD_INFO_LOCATION_AND_SIGNATURE) 591 .build(); 592 593 assertThat(params.roleHolderDownloadInfo.cookieHeader).isNull(); 594 } 595 createDefaultProvisioningParamsBuilder()596 private ProvisioningParams.Builder createDefaultProvisioningParamsBuilder() { 597 return ProvisioningParams.Builder 598 .builder() 599 .setProvisioningAction(TEST_PROVISIONING_ACTION) 600 .setDeviceAdminComponentName(TEST_COMPONENT_NAME); 601 } 602 getCompleteProvisioningParams()603 private ProvisioningParams getCompleteProvisioningParams() { 604 return ProvisioningParams.Builder.builder() 605 .setProvisioningAction(TEST_PROVISIONING_ACTION) 606 .setDeviceAdminPackageName(TEST_PACKAGE_NAME) 607 .setDeviceAdminComponentName(TEST_COMPONENT_NAME) 608 .setDeviceAdminDownloadInfo(TEST_DOWNLOAD_INFO) 609 .setLocalTime(TEST_LOCAL_TIME) 610 .setLocale(TEST_LOCALE) 611 .setTimeZone(TEST_TIME_ZONE) 612 .setStartedByTrustedSource(TEST_STARTED_BY_TRUSTED_SOURCE) 613 .setIsNfc(TEST_IS_NFC) 614 .setLeaveAllSystemAppsEnabled(TEST_LEAVE_ALL_SYSTEM_APP_ENABLED) 615 .setSkipEncryption(TEST_SKIP_ENCRYPTION) 616 .setAccountToMigrate(TEST_ACCOUNT_TO_MIGRATE) 617 .setWifiInfo(TEST_WIFI_INFO) 618 .setUseMobileData(TEST_USE_MOBILE_DATA) 619 .setAdminExtrasBundle(createTestAdminExtras()) 620 .setIsOrganizationOwnedProvisioning(true) 621 .setFlowType(FLOW_TYPE_ADMIN_INTEGRATED) 622 .setProvisioningTrigger(DevicePolicyManager.PROVISIONING_TRIGGER_QR_CODE) 623 .setAllowProvisioningAfterUserSetupComplete(true) 624 .build(); 625 } 626 } 627