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 17 package com.android.managedprovisioning.parser; 18 19 import static android.app.admin.DevicePolicyManager.ACTION_ESTABLISH_NETWORK_CONNECTION; 20 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_FINANCED_DEVICE; 21 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE; 22 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE; 23 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE; 24 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE; 25 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE; 26 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ALLOW_OFFLINE; 27 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME; 28 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE; 29 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM; 30 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER; 31 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION; 32 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME; 33 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM; 34 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DISCLAIMERS; 35 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DISCLAIMER_CONTENT; 36 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DISCLAIMER_HEADER; 37 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION; 38 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED; 39 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOCALE; 40 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME; 41 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ORGANIZATION_NAME; 42 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_RETURN_BEFORE_POLICY_COMPLIANCE; 43 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ROLE_HOLDER_PACKAGE_DOWNLOAD_COOKIE_HEADER; 44 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ROLE_HOLDER_PACKAGE_DOWNLOAD_LOCATION; 45 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ROLE_HOLDER_SIGNATURE_CHECKSUM; 46 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT; 47 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SHOULD_LAUNCH_RESULT_INTENT; 48 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS; 49 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION; 50 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SUPPORTED_MODES; 51 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SUPPORT_URL; 52 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE; 53 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_USE_MOBILE_DATA; 54 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY; 55 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE; 56 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_DOMAIN; 57 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_EAP_METHOD; 58 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_HIDDEN; 59 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_IDENTITY; 60 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PAC_URL; 61 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD; 62 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PHASE2_AUTH; 63 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_BYPASS; 64 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_HOST; 65 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_PORT; 66 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SECURITY_TYPE; 67 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID; 68 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE; 69 import static android.app.admin.DevicePolicyManager.FLAG_SUPPORTED_MODES_ORGANIZATION_OWNED; 70 import static android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_CLOUD_ENROLLMENT; 71 import static android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_QR_CODE; 72 import static android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED; 73 74 import static com.android.internal.util.Preconditions.checkNotNull; 75 import static com.android.managedprovisioning.common.Globals.ACTION_PROVISION_MANAGED_DEVICE_SILENTLY; 76 import static com.android.managedprovisioning.common.Globals.ACTION_RESUME_PROVISIONING; 77 import static com.android.managedprovisioning.model.ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS; 78 import static com.android.managedprovisioning.model.ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_USE_MOBILE_DATA; 79 80 import android.app.admin.DevicePolicyManager; 81 import android.content.ComponentName; 82 import android.content.Context; 83 import android.content.Intent; 84 import android.os.Bundle; 85 import android.os.Parcelable; 86 import android.os.UserHandle; 87 88 import androidx.annotation.Nullable; 89 import androidx.annotation.VisibleForTesting; 90 91 import com.android.managedprovisioning.common.IllegalProvisioningArgumentException; 92 import com.android.managedprovisioning.common.ManagedProvisioningSharedPreferences; 93 import com.android.managedprovisioning.common.ProvisionLogger; 94 import com.android.managedprovisioning.common.SettingsFacade; 95 import com.android.managedprovisioning.common.StoreUtils; 96 import com.android.managedprovisioning.common.Utils; 97 import com.android.managedprovisioning.model.DisclaimersParam; 98 import com.android.managedprovisioning.model.PackageDownloadInfo; 99 import com.android.managedprovisioning.model.ProvisioningParams; 100 import com.android.managedprovisioning.model.WifiInfo; 101 102 import java.util.Arrays; 103 import java.util.HashMap; 104 import java.util.HashSet; 105 import java.util.IllformedLocaleException; 106 import java.util.Map; 107 import java.util.Set; 108 109 /** 110 * A parser which parses provisioning data from intent which stores in {@link Bundle} extras. 111 */ 112 113 @VisibleForTesting 114 public class ExtrasProvisioningDataParser implements ProvisioningDataParser { 115 private static final Set<String> PROVISIONING_ACTIONS_SUPPORT_ALL_PROVISIONING_DATA = 116 new HashSet<>(Arrays.asList( 117 ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE, 118 ACTION_PROVISION_FINANCED_DEVICE)); 119 120 private static final Set<String> PROVISIONING_ACTIONS_SUPPORT_MIN_PROVISIONING_DATA = 121 new HashSet<>(Arrays.asList( 122 ACTION_PROVISION_MANAGED_DEVICE, 123 ACTION_PROVISION_MANAGED_PROFILE, 124 ACTION_PROVISION_MANAGED_DEVICE_SILENTLY)); 125 126 @VisibleForTesting 127 static final String EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE_SHORT = "a.a.e.PAEB"; 128 129 @VisibleForTesting 130 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME_SHORT = "a.a.e.PDAPN"; 131 132 @VisibleForTesting 133 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME_SHORT = "a.a.e.PDACN"; 134 135 @VisibleForTesting 136 static final String EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE_SHORT = "a.a.e.PATM"; 137 138 @VisibleForTesting 139 static final String EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION_SHORT = "a.a.e.PKAOM"; 140 141 @VisibleForTesting 142 static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED_SHORT = "a.a.e.PLASAE"; 143 144 @VisibleForTesting 145 static final String EXTRA_PROVISIONING_TIME_ZONE_SHORT = "a.a.e.PTZ"; 146 147 @VisibleForTesting 148 static final String EXTRA_PROVISIONING_LOCAL_TIME_SHORT = "a.a.e.PLT"; 149 150 @VisibleForTesting 151 static final String EXTRA_PROVISIONING_LOCALE_SHORT = "a.a.e.PL"; 152 153 @VisibleForTesting 154 static final String EXTRA_PROVISIONING_WIFI_SSID_SHORT = "a.a.e.PWS"; 155 156 @VisibleForTesting 157 static final String EXTRA_PROVISIONING_WIFI_HIDDEN_SHORT = "a.a.e.PWH"; 158 159 @VisibleForTesting 160 static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE_SHORT = "a.a.e.PWST"; 161 162 @VisibleForTesting 163 static final String EXTRA_PROVISIONING_WIFI_PASSWORD_SHORT = "a.a.e.PWP"; 164 165 @VisibleForTesting 166 static final String EXTRA_PROVISIONING_WIFI_EAP_METHOD_SHORT = "a.a.e.PWEM"; 167 168 @VisibleForTesting 169 static final String EXTRA_PROVISIONING_WIFI_PHASE2_AUTH_SHORT = "a.a.e.PWPA"; 170 171 @VisibleForTesting 172 static final String EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE_SHORT = "a.a.e.PWCC"; 173 174 @VisibleForTesting 175 static final String EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE_SHORT = "a.a.e.PWUC"; 176 177 @VisibleForTesting 178 static final String EXTRA_PROVISIONING_WIFI_IDENTITY_SHORT = "a.a.e.PWI"; 179 180 @VisibleForTesting 181 static final String EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY_SHORT = "a.a.e.PWAI"; 182 183 @VisibleForTesting 184 static final String EXTRA_PROVISIONING_WIFI_DOMAIN_SHORT = "a.a.e.PWD"; 185 186 @VisibleForTesting 187 static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST_SHORT = "a.a.e.PWPH"; 188 189 @VisibleForTesting 190 static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT_SHORT = "a.a.e.PWPRP"; 191 192 @VisibleForTesting 193 static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS_SHORT = "a.a.e.PWPB"; 194 195 @VisibleForTesting 196 static final String EXTRA_PROVISIONING_WIFI_PAC_URL_SHORT = "a.a.e.PWPU"; 197 198 @VisibleForTesting 199 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION_SHORT = 200 "a.a.e.PDAPDL"; 201 202 @VisibleForTesting 203 static final String EXTRA_PROVISIONING_ORGANIZATION_NAME_SHORT = "a.a.e.PON"; 204 205 @VisibleForTesting 206 static final String EXTRA_PROVISIONING_SUPPORT_URL_SHORT = "a.a.e.PSU"; 207 208 @VisibleForTesting 209 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE_SHORT = "a.a.e.PDAMVC"; 210 211 @VisibleForTesting 212 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER_SHORT = 213 "a.a.e.PDAPDCH"; 214 215 @VisibleForTesting 216 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM_SHORT = "a.a.e.PDAPC"; 217 218 @VisibleForTesting 219 static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM_SHORT = "a.a.e.PDASC"; 220 221 @VisibleForTesting 222 static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION_SHORT = "a.a.e.PSE"; 223 224 @VisibleForTesting 225 static final String EXTRA_PROVISIONING_DISCLAIMERS_SHORT = "a.a.e.PD"; 226 227 @VisibleForTesting 228 static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER_SHORT = "a.a.e.PDH"; 229 230 @VisibleForTesting 231 static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT_SHORT = "a.a.e.PDC"; 232 233 @VisibleForTesting 234 static final String EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS_SHORT = "a.a.e.PSES"; 235 236 @VisibleForTesting 237 static final String EXTRA_PROVISIONING_USE_MOBILE_DATA_SHORT = "a.a.e.PUMD"; 238 239 @VisibleForTesting 240 static final String EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT_SHORT = "a.a.e.PPSGOO"; 241 242 private static final Map<String, String> SHORTER_EXTRAS = buildShorterExtrasMap(); 243 buildShorterExtrasMap()244 private static Map<String, String> buildShorterExtrasMap() { 245 Map<String, String> shorterExtras = new HashMap<>(); 246 shorterExtras.put( 247 EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, 248 EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE_SHORT); 249 shorterExtras.put( 250 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, 251 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME_SHORT); 252 shorterExtras.put( 253 EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, 254 EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME_SHORT); 255 shorterExtras.put( 256 EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE_SHORT); 257 shorterExtras.put( 258 EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION, 259 EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION_SHORT); 260 shorterExtras.put( 261 EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED, 262 EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED_SHORT); 263 shorterExtras.put( 264 EXTRA_PROVISIONING_TIME_ZONE, EXTRA_PROVISIONING_TIME_ZONE_SHORT); 265 shorterExtras.put( 266 EXTRA_PROVISIONING_LOCAL_TIME, EXTRA_PROVISIONING_LOCAL_TIME_SHORT); 267 shorterExtras.put( 268 EXTRA_PROVISIONING_LOCALE, EXTRA_PROVISIONING_LOCALE_SHORT); 269 shorterExtras.put( 270 EXTRA_PROVISIONING_WIFI_SSID, EXTRA_PROVISIONING_WIFI_SSID_SHORT); 271 shorterExtras.put( 272 EXTRA_PROVISIONING_WIFI_HIDDEN, EXTRA_PROVISIONING_WIFI_HIDDEN_SHORT); 273 shorterExtras.put( 274 EXTRA_PROVISIONING_WIFI_SECURITY_TYPE, EXTRA_PROVISIONING_WIFI_SECURITY_TYPE_SHORT); 275 shorterExtras.put( 276 EXTRA_PROVISIONING_WIFI_PASSWORD, EXTRA_PROVISIONING_WIFI_PASSWORD_SHORT); 277 shorterExtras.put( 278 EXTRA_PROVISIONING_WIFI_EAP_METHOD, EXTRA_PROVISIONING_WIFI_EAP_METHOD_SHORT); 279 shorterExtras.put( 280 EXTRA_PROVISIONING_WIFI_PHASE2_AUTH, EXTRA_PROVISIONING_WIFI_PHASE2_AUTH_SHORT); 281 shorterExtras.put( 282 EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE, 283 EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE_SHORT); 284 shorterExtras.put( 285 EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE, 286 EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE_SHORT); 287 shorterExtras.put( 288 EXTRA_PROVISIONING_WIFI_IDENTITY, EXTRA_PROVISIONING_WIFI_IDENTITY_SHORT); 289 shorterExtras.put( 290 EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY, 291 EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY_SHORT); 292 shorterExtras.put( 293 EXTRA_PROVISIONING_WIFI_DOMAIN, EXTRA_PROVISIONING_WIFI_DOMAIN_SHORT); 294 shorterExtras.put( 295 EXTRA_PROVISIONING_WIFI_PROXY_HOST, EXTRA_PROVISIONING_WIFI_PROXY_HOST_SHORT); 296 shorterExtras.put( 297 EXTRA_PROVISIONING_WIFI_PROXY_PORT, EXTRA_PROVISIONING_WIFI_PROXY_PORT_SHORT); 298 shorterExtras.put( 299 EXTRA_PROVISIONING_WIFI_PROXY_BYPASS, EXTRA_PROVISIONING_WIFI_PROXY_BYPASS_SHORT); 300 shorterExtras.put( 301 EXTRA_PROVISIONING_WIFI_PAC_URL, EXTRA_PROVISIONING_WIFI_PAC_URL_SHORT); 302 shorterExtras.put( 303 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, 304 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION_SHORT); 305 shorterExtras.put( 306 EXTRA_PROVISIONING_ORGANIZATION_NAME, EXTRA_PROVISIONING_ORGANIZATION_NAME_SHORT); 307 shorterExtras.put( 308 EXTRA_PROVISIONING_SUPPORT_URL, EXTRA_PROVISIONING_SUPPORT_URL_SHORT); 309 shorterExtras.put( 310 EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE, 311 EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE_SHORT); 312 shorterExtras.put( 313 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER, 314 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER_SHORT); 315 shorterExtras.put( 316 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, 317 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM_SHORT); 318 shorterExtras.put( 319 EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM, 320 EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM_SHORT); 321 shorterExtras.put( 322 EXTRA_PROVISIONING_SKIP_ENCRYPTION, EXTRA_PROVISIONING_SKIP_ENCRYPTION_SHORT); 323 shorterExtras.put( 324 EXTRA_PROVISIONING_DISCLAIMERS, EXTRA_PROVISIONING_DISCLAIMERS_SHORT); 325 shorterExtras.put( 326 EXTRA_PROVISIONING_DISCLAIMER_HEADER, EXTRA_PROVISIONING_DISCLAIMER_HEADER_SHORT); 327 shorterExtras.put( 328 EXTRA_PROVISIONING_DISCLAIMER_CONTENT, EXTRA_PROVISIONING_DISCLAIMER_CONTENT_SHORT); 329 shorterExtras.put( 330 EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS, 331 EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS_SHORT); 332 shorterExtras.put( 333 EXTRA_PROVISIONING_USE_MOBILE_DATA, EXTRA_PROVISIONING_USE_MOBILE_DATA_SHORT); 334 shorterExtras.put(EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT, 335 EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT_SHORT); 336 return shorterExtras; 337 } 338 339 private final Utils mUtils; 340 private final ParserUtils mParserUtils; 341 private final SettingsFacade mSettingsFacade; 342 private final Context mContext; 343 private final ManagedProvisioningSharedPreferences mSharedPreferences; 344 ExtrasProvisioningDataParser(Context context, Utils utils, ParserUtils parserUtils, SettingsFacade settingsFacade)345 ExtrasProvisioningDataParser(Context context, Utils utils, ParserUtils parserUtils, 346 SettingsFacade settingsFacade) { 347 this(context, utils, parserUtils, settingsFacade, 348 new ManagedProvisioningSharedPreferences(context)); 349 } 350 351 @VisibleForTesting ExtrasProvisioningDataParser(Context context, Utils utils, ParserUtils parserUtils, SettingsFacade settingsFacade, ManagedProvisioningSharedPreferences sharedPreferences)352 ExtrasProvisioningDataParser(Context context, Utils utils, ParserUtils parserUtils, 353 SettingsFacade settingsFacade, ManagedProvisioningSharedPreferences sharedPreferences) { 354 mContext = checkNotNull(context); 355 mUtils = checkNotNull(utils); 356 mParserUtils = checkNotNull(parserUtils); 357 mSettingsFacade = checkNotNull(settingsFacade); 358 mSharedPreferences = checkNotNull(sharedPreferences); 359 } 360 361 @Override parse(Intent provisioningIntent)362 public ProvisioningParams parse(Intent provisioningIntent) 363 throws IllegalProvisioningArgumentException{ 364 String provisioningAction = provisioningIntent.getAction(); 365 if (ACTION_RESUME_PROVISIONING.equals(provisioningAction)) { 366 return getParcelableExtraFromLongName(provisioningIntent, 367 ProvisioningParams.EXTRA_PROVISIONING_PARAMS); 368 } 369 if (PROVISIONING_ACTIONS_SUPPORT_MIN_PROVISIONING_DATA.contains(provisioningAction)) { 370 ProvisionLogger.logi("Processing mininalist extras intent."); 371 return parseMinimalistSupportedProvisioningDataInternal(provisioningIntent, mContext) 372 .build(); 373 } else if (PROVISIONING_ACTIONS_SUPPORT_ALL_PROVISIONING_DATA.contains( 374 provisioningAction)) { 375 return parseAllSupportedProvisioningData(provisioningIntent, mContext); 376 } else if (ACTION_ESTABLISH_NETWORK_CONNECTION.equals(provisioningAction)) { 377 return parseNetworkProvisioningData(provisioningIntent); 378 } else { 379 throw new IllegalProvisioningArgumentException("Unsupported provisioning action: " 380 + provisioningAction); 381 } 382 } 383 384 /** 385 * Returns a short version of the requested extra. 386 */ getShortExtraNames(String extraName)387 static String getShortExtraNames(String extraName) { 388 return SHORTER_EXTRAS.get(extraName); 389 } 390 hasExtraFromLongName(Intent intent, String longName)391 private boolean hasExtraFromLongName(Intent intent, String longName) { 392 return intent.hasExtra(longName) || intent.hasExtra(getShortExtraNames(longName)); 393 } 394 395 @Nullable getParcelableExtraFromLongName( Intent intent, String longName)396 private <T extends Parcelable> T getParcelableExtraFromLongName( 397 Intent intent, String longName) { 398 if (intent.hasExtra(longName)) { 399 return intent.getParcelableExtra(longName); 400 } 401 String shortName = getShortExtraNames(longName); 402 if (intent.hasExtra(shortName)) { 403 return intent.getParcelableExtra(shortName); 404 } 405 return null; 406 } 407 408 @Nullable getParcelableArrayExtraFromLongName(Intent intent, String longName)409 private Parcelable[] getParcelableArrayExtraFromLongName(Intent intent, String longName) { 410 if (intent.hasExtra(longName)) { 411 return intent.getParcelableArrayExtra(longName); 412 } 413 String shortName = getShortExtraNames(longName); 414 if (intent.hasExtra(shortName)) { 415 return intent.getParcelableArrayExtra(shortName); 416 } 417 return null; 418 } 419 getIntExtraFromLongName(Intent intent, String longName, int defaultValue)420 private int getIntExtraFromLongName(Intent intent, String longName, int defaultValue) { 421 if (intent.hasExtra(longName)) { 422 return intent.getIntExtra(longName, defaultValue); 423 } 424 String shortName = getShortExtraNames(longName); 425 if (intent.hasExtra(shortName)) { 426 return intent.getIntExtra(shortName, defaultValue); 427 } 428 return defaultValue; 429 } 430 getBooleanExtraFromLongName( Intent intent, String longName, boolean defaultValue)431 private boolean getBooleanExtraFromLongName( 432 Intent intent, String longName, boolean defaultValue) { 433 if (intent.hasExtra(longName)) { 434 return intent.getBooleanExtra(longName, defaultValue); 435 } 436 String shortName = getShortExtraNames(longName); 437 if (intent.hasExtra(shortName)) { 438 return intent.getBooleanExtra(shortName, defaultValue); 439 } 440 return defaultValue; 441 } 442 getParcelableExtraFromLongName(Intent intent, String longName, long defaultValue)443 private long getParcelableExtraFromLongName(Intent intent, String longName, long defaultValue) { 444 if (intent.hasExtra(longName)) { 445 return intent.getLongExtra(longName, defaultValue); 446 } 447 String shortName = getShortExtraNames(longName); 448 if (intent.hasExtra(shortName)) { 449 return intent.getLongExtra(shortName, defaultValue); 450 } 451 return defaultValue; 452 } 453 454 @Nullable getStringExtraFromLongName(Intent intent, String longName)455 private String getStringExtraFromLongName(Intent intent, String longName) { 456 if (intent.getStringExtra(longName) != null) { 457 return intent.getStringExtra(longName); 458 } 459 String shortName = getShortExtraNames(longName); 460 if (intent.getStringExtra(shortName) != null) { 461 return intent.getStringExtra(shortName); 462 } 463 return null; 464 } 465 466 /** 467 * Parses minimal supported set of parameters from bundle extras of a provisioning intent. 468 * 469 * <p>Here is the list of supported parameters. 470 * <ul> 471 * <li>{@link EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li> 472 * <li> 473 * {@link EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} only in 474 * {@link ACTION_PROVISION_MANAGED_PROFILE}. 475 * </li> 476 * <li>{@link EXTRA_PROVISIONING_SKIP_ENCRYPTION}</li> 477 * <li>{@link EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}</li> 478 * <li>{@link EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}</li> 479 * <li>{@link EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}</li> 480 * </ul> 481 */ parseMinimalistSupportedProvisioningDataInternal( Intent intent, Context context)482 private ProvisioningParams.Builder parseMinimalistSupportedProvisioningDataInternal( 483 Intent intent, Context context) 484 throws IllegalProvisioningArgumentException { 485 final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); 486 boolean isProvisionManagedDeviceFromTrustedSourceIntent = 487 ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE.equals(intent.getAction()); 488 boolean isFinancedDeviceProvisioning = 489 ACTION_PROVISION_FINANCED_DEVICE.equals(intent.getAction()); 490 final boolean isManagedProfileAction = 491 ACTION_PROVISION_MANAGED_PROFILE.equals(intent.getAction()); 492 try { 493 final long provisioningId = mSharedPreferences.incrementAndGetProvisioningId(); 494 String provisioningAction = mParserUtils.extractProvisioningAction( 495 intent, mSettingsFacade, mContext); 496 497 // Parse device admin package name and component name. 498 ComponentName deviceAdminComponentName = getParcelableExtraFromLongName( 499 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME); 500 // Device admin package name is deprecated. It is only supported in Profile Owner 501 // provisioning and when resuming NFC provisioning. 502 String deviceAdminPackageName = null; 503 if (isManagedProfileAction) { 504 // In L, we only support package name. This means some DPC may still send us the 505 // device admin package name only. Attempts to obtain the package name from extras. 506 deviceAdminPackageName = getStringExtraFromLongName( 507 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME); 508 // For profile owner, the device admin package should be installed. Verify the 509 // device admin package. 510 deviceAdminComponentName = mUtils.findDeviceAdmin( 511 deviceAdminPackageName, 512 deviceAdminComponentName, 513 context, 514 UserHandle.myUserId()); 515 // Since the device admin package must be installed at this point and its component 516 // name has been obtained, it should be safe to set the deprecated package name 517 // value to null. 518 deviceAdminPackageName = null; 519 } 520 521 final boolean skipEducationScreens = shouldSkipEducationScreens(intent); 522 523 // Only when provisioning PO with ACTION_PROVISION_MANAGED_PROFILE 524 final boolean keepAccountMigrated = isManagedProfileAction 525 && getBooleanExtraFromLongName( 526 intent, EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION, 527 ProvisioningParams 528 .DEFAULT_EXTRA_PROVISIONING_KEEP_ACCOUNT_MIGRATED); 529 530 DisclaimersParam disclaimersParam = new DisclaimersParserImpl(context, provisioningId) 531 .parse(getParcelableArrayExtraFromLongName( 532 intent, EXTRA_PROVISIONING_DISCLAIMERS)); 533 534 String organizationName = 535 getStringExtraFromLongName(intent, EXTRA_PROVISIONING_ORGANIZATION_NAME); 536 String supportUrl = null; 537 if (isProvisionManagedDeviceFromTrustedSourceIntent || isFinancedDeviceProvisioning) { 538 supportUrl = getStringExtraFromLongName(intent, EXTRA_PROVISIONING_SUPPORT_URL); 539 } 540 541 final boolean leaveAllSystemAppsEnabled = isManagedProfileAction 542 ? false 543 : (isFinancedDeviceProvisioning || 544 getBooleanExtraFromLongName( 545 intent, EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED, 546 ProvisioningParams.DEFAULT_LEAVE_ALL_SYSTEM_APPS_ENABLED)); 547 548 int provisioningTrigger = mParserUtils.extractProvisioningTrigger(intent); 549 int initiatorRequestedProvisioningModes = 550 getInitiatorRequestedProvisioningModes(intent); 551 552 final boolean adminOptedOutOfSensorsPermissionGrants = 553 getBooleanExtraFromLongName(intent, 554 EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT, 555 ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_PERMISSION_GRANT_OPT_OUT); 556 return ProvisioningParams.Builder.builder() 557 .setProvisioningId(provisioningId) 558 .setProvisioningAction(provisioningAction) 559 .setDeviceAdminComponentName(deviceAdminComponentName) 560 .setDeviceAdminPackageName(deviceAdminPackageName) 561 .setSkipEncryption( 562 getBooleanExtraFromLongName( 563 intent, EXTRA_PROVISIONING_SKIP_ENCRYPTION, 564 ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_ENCRYPTION)) 565 .setLeaveAllSystemAppsEnabled(leaveAllSystemAppsEnabled) 566 .setAdminExtrasBundle(getParcelableExtraFromLongName( 567 intent, EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE)) 568 .setDisclaimersParam(disclaimersParam) 569 .setKeepAccountMigrated(keepAccountMigrated) 570 .setSkipEducationScreens(skipEducationScreens) 571 .setAccountToMigrate(getParcelableExtraFromLongName( 572 intent, EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE)) 573 .setOrganizationName(organizationName) 574 .setSupportUrl(supportUrl) 575 .setIsQrProvisioning(provisioningTrigger == PROVISIONING_TRIGGER_QR_CODE) 576 .setProvisioningTrigger(provisioningTrigger) 577 .setAllowedProvisioningModes(mParserUtils.getAllowedProvisioningModes( 578 mContext, initiatorRequestedProvisioningModes, mUtils)) 579 .setInitiatorRequestedProvisioningModes( 580 initiatorRequestedProvisioningModes) 581 .setSkipOwnershipDisclaimer(getSkipOwnershipDisclaimer(intent)) 582 .setReturnBeforePolicyCompliance(getReturnBeforePolicyCompliance(intent)) 583 .setDeviceOwnerPermissionGrantOptOut( 584 adminOptedOutOfSensorsPermissionGrants) 585 .setAllowOffline(getBooleanExtraFromLongName( 586 intent, 587 EXTRA_PROVISIONING_ALLOW_OFFLINE, 588 ProvisioningParams.DEFAULT_EXTRA_ALLOW_OFFLINE)) 589 .setRoleHolderDownloadInfo(parseRoleHolderDownloadInfoFromExtras(intent)) 590 .setProvisioningShouldLaunchResultIntent( 591 getProvisioningShouldLaunchResultIntent(intent)); 592 } catch (ClassCastException e) { 593 throw new IllegalProvisioningArgumentException("Extra has invalid type", e); 594 } catch (IllegalArgumentException e) { 595 throw new IllegalProvisioningArgumentException("Invalid parameter found!", e); 596 } catch (NullPointerException e) { 597 throw new IllegalProvisioningArgumentException("Compulsory parameter not found!", e); 598 } 599 } 600 getProvisioningShouldLaunchResultIntent(Intent intent)601 private boolean getProvisioningShouldLaunchResultIntent(Intent intent) { 602 if (!intent.getAction().equals(ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE) 603 && !intent.getAction().equals(ACTION_PROVISION_MANAGED_PROFILE)) { 604 return ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SHOULD_LAUNCH_RESULT_INTENT; 605 } 606 return getBooleanExtraFromLongName( 607 intent, 608 EXTRA_PROVISIONING_SHOULD_LAUNCH_RESULT_INTENT, 609 ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SHOULD_LAUNCH_RESULT_INTENT); 610 } 611 getSkipOwnershipDisclaimer(Intent intent)612 private boolean getSkipOwnershipDisclaimer(Intent intent) { 613 if (!intent.getAction().equals(ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE)) { 614 return ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_OWNERSHIP_DISCLAIMER; 615 } 616 return getBooleanExtraFromLongName( 617 intent, 618 DevicePolicyManager.EXTRA_PROVISIONING_SKIP_OWNERSHIP_DISCLAIMER, 619 ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_OWNERSHIP_DISCLAIMER); 620 } 621 getReturnBeforePolicyCompliance(Intent intent)622 private boolean getReturnBeforePolicyCompliance(Intent intent) { 623 if (intent.getAction().equals(ACTION_PROVISION_MANAGED_PROFILE)) { 624 // TODO(b/182462297): Default to false after in-setup wizard is no longer supported 625 return mSettingsFacade.isDuringSetupWizard(mContext); 626 } 627 // TODO(b/177849035): Remove financed device-specific logic 628 if (intent.getAction().equals(ACTION_PROVISION_FINANCED_DEVICE)) { 629 return true; 630 } 631 return getBooleanExtraFromLongName( 632 intent, 633 EXTRA_PROVISIONING_RETURN_BEFORE_POLICY_COMPLIANCE, 634 /* defaultValue */ true); 635 } 636 getInitiatorRequestedProvisioningModes(Intent intent)637 private int getInitiatorRequestedProvisioningModes(Intent intent) { 638 if (!intent.getAction().equals(ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE)) { 639 return ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SUPPORTED_MODES; 640 } 641 int supportedModes = getIntExtraFromLongName(intent, 642 EXTRA_PROVISIONING_SUPPORTED_MODES, 643 FLAG_SUPPORTED_MODES_ORGANIZATION_OWNED); 644 mParserUtils.validateSupportedModes(supportedModes); 645 return supportedModes; 646 } 647 648 /** 649 * When {@link DevicePolicyManager#EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS} is passed as 650 * a provisioning extra, we only process it for managed Google account enrollment and 651 * persistent device owner. 652 */ shouldSkipEducationScreens(Intent intent)653 private boolean shouldSkipEducationScreens(Intent intent) { 654 if (!getBooleanExtraFromLongName(intent, 655 EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS, 656 DEFAULT_EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS)) { 657 return false; 658 } 659 // TODO(b/175021111): Remove managed account provisioning-specific logic in MP for the 660 // skip education screens extra. 661 int provisioningTrigger = mParserUtils.extractProvisioningTrigger(intent); 662 if (provisioningTrigger == PROVISIONING_TRIGGER_QR_CODE 663 || provisioningTrigger == PROVISIONING_TRIGGER_CLOUD_ENROLLMENT 664 || ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { 665 return false; 666 } 667 return isFullyManagedDeviceAction(intent); 668 } 669 isFullyManagedDeviceAction(Intent intent)670 private boolean isFullyManagedDeviceAction(Intent intent) { 671 return ACTION_PROVISION_MANAGED_DEVICE.equals(intent.getAction()) 672 || ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE.equals(intent.getAction()); 673 } 674 675 /** 676 * Parses an intent and return a corresponding {@link ProvisioningParams} object. 677 * 678 * @param intent intent to be parsed. 679 * @param context a context 680 */ parseAllSupportedProvisioningData(Intent intent, Context context)681 private ProvisioningParams parseAllSupportedProvisioningData(Intent intent, Context context) 682 throws IllegalProvisioningArgumentException { 683 try { 684 ProvisionLogger.logi("Processing all supported extras intent: " + intent.getAction()); 685 return parseMinimalistSupportedProvisioningDataInternal(intent, context) 686 // Parse time zone, local time and locale. 687 .setTimeZone(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_TIME_ZONE)) 688 .setLocalTime( 689 getParcelableExtraFromLongName( 690 intent, EXTRA_PROVISIONING_LOCAL_TIME, 691 ProvisioningParams.DEFAULT_LOCAL_TIME)) 692 .setLocale(StoreUtils.stringToLocale( 693 getStringExtraFromLongName(intent,EXTRA_PROVISIONING_LOCALE))) 694 .setUseMobileData( 695 getBooleanExtraFromLongName( 696 intent, EXTRA_PROVISIONING_USE_MOBILE_DATA, 697 DEFAULT_EXTRA_PROVISIONING_USE_MOBILE_DATA)) 698 // Parse WiFi configuration. 699 .setWifiInfo(parseWifiInfoFromExtras(intent)) 700 // Parse device admin package download info. 701 .setDeviceAdminDownloadInfo(parsePackageDownloadInfoFromExtras(intent)) 702 // Cases where startedByTrustedSource can be true are 703 // 1. We are reloading a stored provisioning intent, either Nfc bump or 704 // PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE, after encryption reboot, 705 // which is a self-originated intent. 706 // 2. the intent is from a trusted source, for example QR provisioning. 707 .setStartedByTrustedSource(ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE 708 .equals(intent.getAction())) 709 .build(); 710 } catch (IllegalArgumentException e) { 711 throw new IllegalProvisioningArgumentException("Invalid parameter found!", e); 712 } catch (IllformedLocaleException e) { 713 throw new IllegalProvisioningArgumentException("Invalid locale format!", e); 714 } catch (NullPointerException e) { 715 throw new IllegalProvisioningArgumentException("Compulsory parameter not found!", e); 716 } 717 } 718 719 /** 720 * Parses an intent and return a corresponding {@link ProvisioningParams} object. 721 * 722 * @param intent intent to be parsed. 723 */ parseNetworkProvisioningData(Intent intent)724 private ProvisioningParams parseNetworkProvisioningData(Intent intent) 725 throws IllegalProvisioningArgumentException { 726 try { 727 ProvisionLogger.logi("Processing network-related extras intent: " + intent.getAction()); 728 return ProvisioningParams.Builder.builder(/* skipValidation= */ true) 729 .setUseMobileData( 730 getBooleanExtraFromLongName( 731 intent, EXTRA_PROVISIONING_USE_MOBILE_DATA, 732 DEFAULT_EXTRA_PROVISIONING_USE_MOBILE_DATA)) 733 .setWifiInfo(parseWifiInfoFromExtras(intent)) 734 .build(); 735 } catch (IllegalArgumentException e) { 736 throw new IllegalProvisioningArgumentException("Invalid parameter found!", e); 737 } catch (IllformedLocaleException e) { 738 throw new IllegalProvisioningArgumentException("Invalid locale format!", e); 739 } catch (NullPointerException e) { 740 throw new IllegalProvisioningArgumentException("Compulsory parameter not found!", e); 741 } 742 } 743 744 /** 745 * Parses Wifi configuration from an Intent and returns the result in {@link WifiInfo}. 746 */ 747 @Nullable parseWifiInfoFromExtras(Intent intent)748 private WifiInfo parseWifiInfoFromExtras(Intent intent) { 749 if (getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_SSID) == null) { 750 return null; 751 } 752 return WifiInfo.Builder.builder() 753 .setSsid(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_SSID)) 754 .setSecurityType( 755 getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_SECURITY_TYPE)) 756 .setPassword(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_PASSWORD)) 757 .setProxyHost(getStringExtraFromLongName( 758 intent, EXTRA_PROVISIONING_WIFI_PROXY_HOST)) 759 .setProxyBypassHosts( 760 getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_PROXY_BYPASS)) 761 .setPacUrl(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_PAC_URL)) 762 .setProxyPort(getIntExtraFromLongName( 763 intent, EXTRA_PROVISIONING_WIFI_PROXY_PORT, 764 WifiInfo.DEFAULT_WIFI_PROXY_PORT)) 765 .setEapMethod(getStringExtraFromLongName( 766 intent, EXTRA_PROVISIONING_WIFI_EAP_METHOD)) 767 .setPhase2Auth(getStringExtraFromLongName( 768 intent, EXTRA_PROVISIONING_WIFI_PHASE2_AUTH)) 769 .setCaCertificate(getStringExtraFromLongName( 770 intent, EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE)) 771 .setUserCertificate(getStringExtraFromLongName( 772 intent, EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE)) 773 .setIdentity(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_IDENTITY)) 774 .setAnonymousIdentity(getStringExtraFromLongName( 775 intent, EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY)) 776 .setDomain(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_DOMAIN)) 777 .setHidden(getBooleanExtraFromLongName( 778 intent, EXTRA_PROVISIONING_WIFI_HIDDEN, WifiInfo.DEFAULT_WIFI_HIDDEN)) 779 .build(); 780 } 781 782 /** 783 * Parses device admin package download info configuration from an Intent and returns the result 784 * in {@link PackageDownloadInfo}. 785 */ 786 @Nullable parsePackageDownloadInfoFromExtras(Intent intent)787 private PackageDownloadInfo parsePackageDownloadInfoFromExtras(Intent intent) { 788 if (getStringExtraFromLongName( 789 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION) == null) { 790 return null; 791 } 792 PackageDownloadInfo.Builder downloadInfoBuilder = PackageDownloadInfo.Builder.builder() 793 .setMinVersion(getIntExtraFromLongName( 794 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE, 795 PackageDownloadInfo.DEFAULT_MINIMUM_VERSION)) 796 .setLocation(getStringExtraFromLongName( 797 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION)) 798 .setCookieHeader(getStringExtraFromLongName( 799 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER)); 800 String packageHash = 801 getStringExtraFromLongName( 802 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM); 803 if (packageHash != null) { 804 downloadInfoBuilder.setPackageChecksum(StoreUtils.stringToByteArray(packageHash)); 805 } 806 String sigHash = getStringExtraFromLongName( 807 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM); 808 if (sigHash != null) { 809 downloadInfoBuilder.setSignatureChecksum(StoreUtils.stringToByteArray(sigHash)); 810 } 811 return downloadInfoBuilder.build(); 812 } 813 814 /** 815 * Parses role holder package download info configuration from an Intent and returns the result 816 * in {@link PackageDownloadInfo}. 817 * 818 * @return the {@link PackageDownloadInfo} or {@code null} if not supplied alongside {@link 819 * DevicePolicyManager#ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE}, {@link 820 * DevicePolicyManager#EXTRA_PROVISIONING_ROLE_HOLDER_PACKAGE_DOWNLOAD_LOCATION} or 821 * {@link DevicePolicyManager#EXTRA_PROVISIONING_ROLE_HOLDER_SIGNATURE_CHECKSUM}. 822 */ 823 @Nullable parseRoleHolderDownloadInfoFromExtras(Intent intent)824 private PackageDownloadInfo parseRoleHolderDownloadInfoFromExtras(Intent intent) { 825 if (!intent.getAction().equals(ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE)) { 826 ProvisionLogger.logi("Cannot parse role holder download info for non-trusted source " 827 + "provisioning."); 828 return null; 829 } 830 String downloadLocation = getStringExtraFromLongName( 831 intent, EXTRA_PROVISIONING_ROLE_HOLDER_PACKAGE_DOWNLOAD_LOCATION); 832 if (downloadLocation == null) { 833 ProvisionLogger.logi("Cannot parse role holder download info, because it does not " 834 + "include the download location extra."); 835 return null; 836 } 837 String sigHash = getStringExtraFromLongName( 838 intent, EXTRA_PROVISIONING_ROLE_HOLDER_SIGNATURE_CHECKSUM); 839 if (sigHash == null) { 840 ProvisionLogger.logi("Cannot parse role holder download info, because it does not " 841 + "include the signature checksum extra."); 842 return null; 843 } 844 PackageDownloadInfo.Builder downloadInfoBuilder = PackageDownloadInfo.Builder.builder() 845 .setLocation(downloadLocation) 846 .setCookieHeader(getStringExtraFromLongName( 847 intent, EXTRA_PROVISIONING_ROLE_HOLDER_PACKAGE_DOWNLOAD_COOKIE_HEADER)); 848 downloadInfoBuilder.setSignatureChecksum(StoreUtils.stringToByteArray(sigHash)); 849 return downloadInfoBuilder.build(); 850 } 851 } 852