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_PROVISION_FINANCED_DEVICE;
20 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE;
21 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE;
22 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
23 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE;
24 import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_USER;
25 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
26 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE;
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_ICON_URI;
33 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL;
34 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME;
35 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM;
36 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DISCLAIMERS;
37 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DISCLAIMER_CONTENT;
38 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DISCLAIMER_HEADER;
39 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION;
40 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED;
41 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOCALE;
42 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME;
43 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOGO_URI;
44 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_MAIN_COLOR;
45 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ORGANIZATION_NAME;
46 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION;
47 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_USER_CONSENT;
48 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS;
49 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_USER_SETUP;
50 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SUPPORT_URL;
51 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE;
52 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_USE_MOBILE_DATA;
53 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY;
54 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE;
55 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_DOMAIN;
56 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_EAP_METHOD;
57 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_HIDDEN;
58 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_IDENTITY;
59 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PAC_URL;
60 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD;
61 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PHASE2_AUTH;
62 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_BYPASS;
63 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_HOST;
64 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_PORT;
65 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SECURITY_TYPE;
66 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID;
67 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE;
68 
69 import static com.android.internal.util.Preconditions.checkNotNull;
70 import static com.android.managedprovisioning.common.Globals.ACTION_PROVISION_MANAGED_DEVICE_SILENTLY;
71 import static com.android.managedprovisioning.common.Globals.ACTION_RESUME_PROVISIONING;
72 import static com.android.managedprovisioning.model.ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS;
73 import static com.android.managedprovisioning.model.ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_USE_MOBILE_DATA;
74 import static com.android.managedprovisioning.model.ProvisioningParams.inferStaticDeviceAdminPackageName;
75 
76 import android.app.admin.DevicePolicyManager;
77 import android.content.ComponentName;
78 import android.content.Context;
79 import android.content.Intent;
80 import android.net.Uri;
81 import android.os.Bundle;
82 import android.os.Parcelable;
83 import android.os.UserHandle;
84 
85 import androidx.annotation.Nullable;
86 import androidx.annotation.VisibleForTesting;
87 
88 import com.android.managedprovisioning.common.IllegalProvisioningArgumentException;
89 import com.android.managedprovisioning.common.LogoUtils;
90 import com.android.managedprovisioning.common.ManagedProvisioningSharedPreferences;
91 import com.android.managedprovisioning.common.ProvisionLogger;
92 import com.android.managedprovisioning.common.StoreUtils;
93 import com.android.managedprovisioning.common.Utils;
94 import com.android.managedprovisioning.model.DisclaimersParam;
95 import com.android.managedprovisioning.model.PackageDownloadInfo;
96 import com.android.managedprovisioning.model.ProvisioningParams;
97 import com.android.managedprovisioning.model.WifiInfo;
98 
99 import java.util.Arrays;
100 import java.util.Collections;
101 import java.util.HashMap;
102 import java.util.HashSet;
103 import java.util.IllformedLocaleException;
104 import java.util.Map;
105 import java.util.Set;
106 
107 /**
108  * A parser which parses provisioning data from intent which stores in {@link Bundle} extras.
109  */
110 
111 @VisibleForTesting
112 public class ExtrasProvisioningDataParser implements ProvisioningDataParser {
113     private static final Set<String> PROVISIONING_ACTIONS_SUPPORT_ALL_PROVISIONING_DATA =
114             new HashSet<>(Arrays.asList(
115                     ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE,
116                     ACTION_PROVISION_FINANCED_DEVICE));
117 
118     private static final Set<String> PROVISIONING_ACTIONS_SUPPORT_MIN_PROVISIONING_DATA =
119             new HashSet<>(Arrays.asList(
120                     ACTION_PROVISION_MANAGED_DEVICE,
121                     ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE,
122                     ACTION_PROVISION_MANAGED_USER,
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_MAIN_COLOR_SHORT = "a.a.e.PMC";
143 
144     @VisibleForTesting
145     static final String EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED_SHORT = "a.a.e.PLASAE";
146 
147     @VisibleForTesting
148     static final String EXTRA_PROVISIONING_TIME_ZONE_SHORT = "a.a.e.PTZ";
149 
150     @VisibleForTesting
151     static final String EXTRA_PROVISIONING_LOCAL_TIME_SHORT = "a.a.e.PLT";
152 
153     @VisibleForTesting
154     static final String EXTRA_PROVISIONING_LOCALE_SHORT = "a.a.e.PL";
155 
156     @VisibleForTesting
157     static final String EXTRA_PROVISIONING_WIFI_SSID_SHORT = "a.a.e.PWS";
158 
159     @VisibleForTesting
160     static final String EXTRA_PROVISIONING_WIFI_HIDDEN_SHORT = "a.a.e.PWH";
161 
162     @VisibleForTesting
163     static final String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE_SHORT = "a.a.e.PWST";
164 
165     @VisibleForTesting
166     static final String EXTRA_PROVISIONING_WIFI_PASSWORD_SHORT = "a.a.e.PWP";
167 
168     @VisibleForTesting
169     static final String EXTRA_PROVISIONING_WIFI_EAP_METHOD_SHORT = "a.a.e.PWEM";
170 
171     @VisibleForTesting
172     static final String EXTRA_PROVISIONING_WIFI_PHASE2_AUTH_SHORT = "a.a.e.PWPA";
173 
174     @VisibleForTesting
175     static final String EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE_SHORT = "a.a.e.PWCC";
176 
177     @VisibleForTesting
178     static final String EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE_SHORT = "a.a.e.PWUC";
179 
180     @VisibleForTesting
181     static final String EXTRA_PROVISIONING_WIFI_IDENTITY_SHORT = "a.a.e.PWI";
182 
183     @VisibleForTesting
184     static final String EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY_SHORT = "a.a.e.PWAI";
185 
186     @VisibleForTesting
187     static final String EXTRA_PROVISIONING_WIFI_DOMAIN_SHORT = "a.a.e.PWD";
188 
189     @VisibleForTesting
190     static final String EXTRA_PROVISIONING_WIFI_PROXY_HOST_SHORT = "a.a.e.PWPH";
191 
192     @VisibleForTesting
193     static final String EXTRA_PROVISIONING_WIFI_PROXY_PORT_SHORT = "a.a.e.PWPRP";
194 
195     @VisibleForTesting
196     static final String EXTRA_PROVISIONING_WIFI_PROXY_BYPASS_SHORT = "a.a.e.PWPB";
197 
198     @VisibleForTesting
199     static final String EXTRA_PROVISIONING_WIFI_PAC_URL_SHORT = "a.a.e.PWPU";
200 
201     @VisibleForTesting
202     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION_SHORT =
203             "a.a.e.PDAPDL";
204 
205     @VisibleForTesting
206     static final String EXTRA_PROVISIONING_ORGANIZATION_NAME_SHORT = "a.a.e.PON";
207 
208     @VisibleForTesting
209     static final String EXTRA_PROVISIONING_SUPPORT_URL_SHORT = "a.a.e.PSU";
210 
211     @VisibleForTesting
212     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL_SHORT = "a.a.e.PDAPL";
213 
214     @VisibleForTesting
215     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI_SHORT = "a.a.e.PDAPIU";
216 
217     @VisibleForTesting
218     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE_SHORT = "a.a.e.PDAMVC";
219 
220     @VisibleForTesting
221     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER_SHORT =
222             "a.a.e.PDAPDCH";
223 
224     @VisibleForTesting
225     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM_SHORT = "a.a.e.PDAPC";
226 
227     @VisibleForTesting
228     static final String EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM_SHORT = "a.a.e.PDASC";
229 
230     @VisibleForTesting
231     static final String EXTRA_PROVISIONING_SKIP_ENCRYPTION_SHORT = "a.a.e.PSE";
232 
233     @VisibleForTesting
234     static final String EXTRA_PROVISIONING_LOGO_URI_SHORT = "a.a.e.PLU";
235 
236     @VisibleForTesting
237     static final String EXTRA_PROVISIONING_DISCLAIMERS_SHORT = "a.a.e.PD";
238 
239     @VisibleForTesting
240     static final String EXTRA_PROVISIONING_DISCLAIMER_HEADER_SHORT = "a.a.e.PDH";
241 
242     @VisibleForTesting
243     static final String EXTRA_PROVISIONING_DISCLAIMER_CONTENT_SHORT = "a.a.e.PDC";
244 
245     @VisibleForTesting
246     static final String EXTRA_PROVISIONING_SKIP_USER_SETUP_SHORT = "a.a.e.PSUS";
247 
248     @VisibleForTesting
249     static final String EXTRA_PROVISIONING_SKIP_USER_CONSENT_SHORT = "a.a.e.PSUC";
250 
251     @VisibleForTesting
252     static final String EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS_SHORT = "a.a.e.PSES";
253 
254     @VisibleForTesting
255     static final String EXTRA_PROVISIONING_USE_MOBILE_DATA_SHORT = "a.a.e.PUMD";
256 
257     private static final Map<String, String> SHORTER_EXTRAS = buildShorterExtrasMap();
258 
buildShorterExtrasMap()259     private static Map<String, String> buildShorterExtrasMap() {
260         Map<String, String> shorterExtras = new HashMap<>();
261         shorterExtras.put(
262                 EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE,
263                 EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE_SHORT);
264         shorterExtras.put(
265                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
266                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME_SHORT);
267         shorterExtras.put(
268                 EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
269                 EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME_SHORT);
270         shorterExtras.put(
271                 EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE_SHORT);
272         shorterExtras.put(
273                 EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION,
274                 EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION_SHORT);
275         shorterExtras.put(
276                 EXTRA_PROVISIONING_MAIN_COLOR, EXTRA_PROVISIONING_MAIN_COLOR_SHORT);
277         shorterExtras.put(
278                 EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED,
279                 EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED_SHORT);
280         shorterExtras.put(
281                 EXTRA_PROVISIONING_TIME_ZONE, EXTRA_PROVISIONING_TIME_ZONE_SHORT);
282         shorterExtras.put(
283                 EXTRA_PROVISIONING_LOCAL_TIME, EXTRA_PROVISIONING_LOCAL_TIME_SHORT);
284         shorterExtras.put(
285                 EXTRA_PROVISIONING_LOCALE, EXTRA_PROVISIONING_LOCALE_SHORT);
286         shorterExtras.put(
287                 EXTRA_PROVISIONING_WIFI_SSID, EXTRA_PROVISIONING_WIFI_SSID_SHORT);
288         shorterExtras.put(
289                 EXTRA_PROVISIONING_WIFI_HIDDEN, EXTRA_PROVISIONING_WIFI_HIDDEN_SHORT);
290         shorterExtras.put(
291                 EXTRA_PROVISIONING_WIFI_SECURITY_TYPE, EXTRA_PROVISIONING_WIFI_SECURITY_TYPE_SHORT);
292         shorterExtras.put(
293                 EXTRA_PROVISIONING_WIFI_PASSWORD, EXTRA_PROVISIONING_WIFI_PASSWORD_SHORT);
294         shorterExtras.put(
295                 EXTRA_PROVISIONING_WIFI_EAP_METHOD, EXTRA_PROVISIONING_WIFI_EAP_METHOD_SHORT);
296         shorterExtras.put(
297                 EXTRA_PROVISIONING_WIFI_PHASE2_AUTH, EXTRA_PROVISIONING_WIFI_PHASE2_AUTH_SHORT);
298         shorterExtras.put(
299                 EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE,
300                 EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE_SHORT);
301         shorterExtras.put(
302                 EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE,
303                 EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE_SHORT);
304         shorterExtras.put(
305                 EXTRA_PROVISIONING_WIFI_IDENTITY, EXTRA_PROVISIONING_WIFI_IDENTITY_SHORT);
306         shorterExtras.put(
307                 EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY,
308                 EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY_SHORT);
309         shorterExtras.put(
310                 EXTRA_PROVISIONING_WIFI_DOMAIN, EXTRA_PROVISIONING_WIFI_DOMAIN_SHORT);
311         shorterExtras.put(
312                 EXTRA_PROVISIONING_WIFI_PROXY_HOST, EXTRA_PROVISIONING_WIFI_PROXY_HOST_SHORT);
313         shorterExtras.put(
314                 EXTRA_PROVISIONING_WIFI_PROXY_PORT, EXTRA_PROVISIONING_WIFI_PROXY_PORT_SHORT);
315         shorterExtras.put(
316                 EXTRA_PROVISIONING_WIFI_PROXY_BYPASS, EXTRA_PROVISIONING_WIFI_PROXY_BYPASS_SHORT);
317         shorterExtras.put(
318                 EXTRA_PROVISIONING_WIFI_PAC_URL, EXTRA_PROVISIONING_WIFI_PAC_URL_SHORT);
319         shorterExtras.put(
320                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION,
321                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION_SHORT);
322         shorterExtras.put(
323                 EXTRA_PROVISIONING_ORGANIZATION_NAME, EXTRA_PROVISIONING_ORGANIZATION_NAME_SHORT);
324         shorterExtras.put(
325                 EXTRA_PROVISIONING_SUPPORT_URL, EXTRA_PROVISIONING_SUPPORT_URL_SHORT);
326         shorterExtras.put(
327                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL,
328                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL_SHORT);
329         shorterExtras.put(
330                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI,
331                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI_SHORT);
332         shorterExtras.put(
333                 EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE,
334                 EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE_SHORT);
335         shorterExtras.put(
336                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER,
337                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER_SHORT);
338         shorterExtras.put(
339                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM,
340                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM_SHORT);
341         shorterExtras.put(
342                 EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM,
343                 EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM_SHORT);
344         shorterExtras.put(
345                 EXTRA_PROVISIONING_SKIP_ENCRYPTION, EXTRA_PROVISIONING_SKIP_ENCRYPTION_SHORT);
346         shorterExtras.put(
347                 EXTRA_PROVISIONING_DISCLAIMERS, EXTRA_PROVISIONING_DISCLAIMERS_SHORT);
348         shorterExtras.put(
349                 EXTRA_PROVISIONING_LOGO_URI, EXTRA_PROVISIONING_LOGO_URI_SHORT);
350         shorterExtras.put(
351                 EXTRA_PROVISIONING_DISCLAIMER_HEADER, EXTRA_PROVISIONING_DISCLAIMER_HEADER_SHORT);
352         shorterExtras.put(
353                 EXTRA_PROVISIONING_DISCLAIMER_CONTENT, EXTRA_PROVISIONING_DISCLAIMER_CONTENT_SHORT);
354         shorterExtras.put(
355                 EXTRA_PROVISIONING_SKIP_USER_SETUP, EXTRA_PROVISIONING_SKIP_USER_SETUP_SHORT);
356         shorterExtras.put(
357                 EXTRA_PROVISIONING_SKIP_USER_CONSENT, EXTRA_PROVISIONING_SKIP_USER_CONSENT_SHORT);
358         shorterExtras.put(
359                 EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS,
360                 EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS_SHORT);
361         shorterExtras.put(
362                 EXTRA_PROVISIONING_USE_MOBILE_DATA, EXTRA_PROVISIONING_USE_MOBILE_DATA_SHORT);
363         return shorterExtras;
364     }
365 
366     private final Utils mUtils;
367     private final Context mContext;
368     private final ManagedProvisioningSharedPreferences mSharedPreferences;
369 
ExtrasProvisioningDataParser(Context context, Utils utils)370     ExtrasProvisioningDataParser(Context context, Utils utils) {
371         this(context, utils, new ManagedProvisioningSharedPreferences(context));
372     }
373 
374     @VisibleForTesting
ExtrasProvisioningDataParser(Context context, Utils utils, ManagedProvisioningSharedPreferences sharedPreferences)375     ExtrasProvisioningDataParser(Context context, Utils utils,
376             ManagedProvisioningSharedPreferences sharedPreferences) {
377         mContext = checkNotNull(context);
378         mUtils = checkNotNull(utils);
379         mSharedPreferences = checkNotNull(sharedPreferences);
380     }
381 
382     @Override
parse(Intent provisioningIntent)383     public ProvisioningParams parse(Intent provisioningIntent)
384             throws IllegalProvisioningArgumentException{
385         String provisioningAction = provisioningIntent.getAction();
386         if (ACTION_RESUME_PROVISIONING.equals(provisioningAction)) {
387             return getParcelableExtraFromLongName(provisioningIntent,
388                     ProvisioningParams.EXTRA_PROVISIONING_PARAMS);
389         }
390         if (PROVISIONING_ACTIONS_SUPPORT_MIN_PROVISIONING_DATA.contains(provisioningAction)) {
391             ProvisionLogger.logi("Processing mininalist extras intent.");
392             return parseMinimalistSupportedProvisioningDataInternal(provisioningIntent, mContext)
393                     .build();
394         } else if (PROVISIONING_ACTIONS_SUPPORT_ALL_PROVISIONING_DATA.contains(
395                 provisioningAction)) {
396             return parseAllSupportedProvisioningData(provisioningIntent, mContext);
397         } else {
398             throw new IllegalProvisioningArgumentException("Unsupported provisioning action: "
399                     + provisioningAction);
400         }
401     }
402 
403     /**
404      * Returns a short version of the requested extra.
405      */
getShortExtraNames(String extraName)406     static String getShortExtraNames(String extraName) {
407         return SHORTER_EXTRAS.get(extraName);
408     }
409 
hasExtraFromLongName(Intent intent, String longName)410     private boolean hasExtraFromLongName(Intent intent, String longName) {
411         return intent.hasExtra(longName) || intent.hasExtra(getShortExtraNames(longName));
412     }
413 
414     @Nullable
getParcelableExtraFromLongName( Intent intent, String longName)415     private <T extends Parcelable> T getParcelableExtraFromLongName(
416             Intent intent, String longName) {
417         if (intent.hasExtra(longName)) {
418             return intent.getParcelableExtra(longName);
419         }
420         String shortName = getShortExtraNames(longName);
421         if (intent.hasExtra(shortName)) {
422             return intent.getParcelableExtra(shortName);
423         }
424         return null;
425     }
426 
427     @Nullable
getParcelableArrayExtraFromLongName(Intent intent, String longName)428     private Parcelable[] getParcelableArrayExtraFromLongName(Intent intent, String longName) {
429         if (intent.hasExtra(longName)) {
430             return intent.getParcelableArrayExtra(longName);
431         }
432         String shortName = getShortExtraNames(longName);
433         if (intent.hasExtra(shortName)) {
434             return intent.getParcelableArrayExtra(shortName);
435         }
436         return null;
437     }
438 
getIntExtraFromLongName(Intent intent, String longName, int defaultValue)439     private int getIntExtraFromLongName(Intent intent, String longName, int defaultValue) {
440         if (intent.hasExtra(longName)) {
441             return intent.getIntExtra(longName, defaultValue);
442         }
443         String shortName = getShortExtraNames(longName);
444         if (intent.hasExtra(shortName)) {
445             return intent.getIntExtra(shortName, defaultValue);
446         }
447         return defaultValue;
448     }
449 
getBooleanExtraFromLongName( Intent intent, String longName, boolean defaultValue)450     private boolean getBooleanExtraFromLongName(
451             Intent intent, String longName, boolean defaultValue) {
452         if (intent.hasExtra(longName)) {
453             return intent.getBooleanExtra(longName, defaultValue);
454         }
455         String shortName = getShortExtraNames(longName);
456         if (intent.hasExtra(shortName)) {
457             return intent.getBooleanExtra(shortName, defaultValue);
458         }
459         return defaultValue;
460     }
461 
getParcelableExtraFromLongName(Intent intent, String longName, long defaultValue)462     private long getParcelableExtraFromLongName(Intent intent, String longName, long defaultValue) {
463         if (intent.hasExtra(longName)) {
464             return intent.getLongExtra(longName, defaultValue);
465         }
466         String shortName = getShortExtraNames(longName);
467         if (intent.hasExtra(shortName)) {
468             return intent.getLongExtra(shortName, defaultValue);
469         }
470         return defaultValue;
471     }
472 
473     @Nullable
getStringExtraFromLongName(Intent intent, String longName)474     private String getStringExtraFromLongName(Intent intent, String longName) {
475         if (intent.getStringExtra(longName) != null) {
476             return intent.getStringExtra(longName);
477         }
478         String shortName = getShortExtraNames(longName);
479         if (intent.getStringExtra(shortName) != null) {
480             return intent.getStringExtra(shortName);
481         }
482         return null;
483     }
484 
485     /**
486      * Parses minimal supported set of parameters from bundle extras of a provisioning intent.
487      *
488      * <p>Here is the list of supported parameters.
489      * <ul>
490      *     <li>{@link EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME}</li>
491      *     <li>
492      *         {@link EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} only in
493      *         {@link ACTION_PROVISION_MANAGED_PROFILE}.
494      *     </li>
495      *     <li>{@link EXTRA_PROVISIONING_LOGO_URI}</li>
496      *     <li>{@link EXTRA_PROVISIONING_MAIN_COLOR}</li>
497      *     <li>
498      *         {@link EXTRA_PROVISIONING_SKIP_USER_SETUP} only in
499      *         {@link ACTION_PROVISION_MANAGED_USER} and {@link ACTION_PROVISION_MANAGED_DEVICE}.
500      *     </li>
501      *     <li>{@link EXTRA_PROVISIONING_SKIP_ENCRYPTION}</li>
502      *     <li>{@link EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED}</li>
503      *     <li>{@link EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE}</li>
504      *     <li>{@link EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}</li>
505      *     <li>{@link EXTRA_PROVISIONING_SKIP_USER_CONSENT}</li>
506      * </ul>
507      */
parseMinimalistSupportedProvisioningDataInternal( Intent intent, Context context)508     private ProvisioningParams.Builder parseMinimalistSupportedProvisioningDataInternal(
509             Intent intent, Context context)
510             throws IllegalProvisioningArgumentException {
511         final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
512         boolean isProvisionManagedDeviceFromTrustedSourceIntent =
513                 ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE.equals(intent.getAction());
514         boolean isFinancedDeviceProvisioning =
515                 ACTION_PROVISION_FINANCED_DEVICE.equals(intent.getAction());
516         try {
517             final long provisioningId = mSharedPreferences.incrementAndGetProvisioningId();
518             String provisioningAction = mUtils.mapIntentToDpmAction(intent);
519             final boolean isManagedProfileAction =
520                     ACTION_PROVISION_MANAGED_PROFILE.equals(provisioningAction);
521 
522             // Parse device admin package name and component name.
523             ComponentName deviceAdminComponentName = getParcelableExtraFromLongName(
524                     intent, EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME);
525             // Device admin package name is deprecated. It is only supported in Profile Owner
526             // provisioning and when resuming NFC provisioning.
527             String deviceAdminPackageName = null;
528             if (isManagedProfileAction) {
529                 // In L, we only support package name. This means some DPC may still send us the
530                 // device admin package name only. Attempts to obtain the package name from extras.
531                 deviceAdminPackageName = getStringExtraFromLongName(
532                         intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME);
533                 // For profile owner, the device admin package should be installed. Verify the
534                 // device admin package.
535                 deviceAdminComponentName = mUtils.findDeviceAdmin(
536                         deviceAdminPackageName,
537                         deviceAdminComponentName,
538                         context,
539                         UserHandle.myUserId());
540                 // Since the device admin package must be installed at this point and its component
541                 // name has been obtained, it should be safe to set the deprecated package name
542                 // value to null.
543                 deviceAdminPackageName = null;
544             }
545 
546             // Parse skip user setup in ACTION_PROVISION_MANAGED_USER and
547             // ACTION_PROVISION_MANAGED_DEVICE (sync auth) only. This extra is not supported if
548             // provisioning was started by trusted source, as it is not clear where SUW should
549             // continue from.
550             boolean skipUserSetup = ProvisioningParams.DEFAULT_SKIP_USER_SETUP;
551             if (!isProvisionManagedDeviceFromTrustedSourceIntent
552                     && (provisioningAction.equals(ACTION_PROVISION_MANAGED_USER)
553                             || provisioningAction.equals(ACTION_PROVISION_MANAGED_DEVICE))) {
554                 skipUserSetup = getBooleanExtraFromLongName(
555                         intent, EXTRA_PROVISIONING_SKIP_USER_SETUP,
556                         ProvisioningParams.DEFAULT_SKIP_USER_SETUP);
557             } else if (isFinancedDeviceProvisioning) {
558                 skipUserSetup = false;
559             }
560 
561             // Only current DeviceOwner can specify EXTRA_PROVISIONING_SKIP_USER_CONSENT when
562             // provisioning PO with ACTION_PROVISION_MANAGED_PROFILE
563             final boolean skipUserConsent = isManagedProfileAction
564                             && getBooleanExtraFromLongName(intent,
565                                 EXTRA_PROVISIONING_SKIP_USER_CONSENT,
566                                 ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_USER_CONSENT)
567                             && mUtils.isPackageDeviceOwner(dpm, inferStaticDeviceAdminPackageName(
568                                     deviceAdminComponentName, deviceAdminPackageName));
569 
570             final boolean skipEducationScreens = shouldSkipEducationScreens(intent);
571 
572             // Only when provisioning PO with ACTION_PROVISION_MANAGED_PROFILE
573             final boolean keepAccountMigrated = isManagedProfileAction
574                             && getBooleanExtraFromLongName(
575                                 intent, EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION,
576                                 ProvisioningParams
577                                         .DEFAULT_EXTRA_PROVISIONING_KEEP_ACCOUNT_MIGRATED);
578 
579             // Parse main color and organization's logo. This is not supported in managed device
580             // from trusted source provisioning because, currently, there is no way to send
581             // organization logo to the device at this stage.
582             Integer mainColor = ProvisioningParams.DEFAULT_MAIN_COLOR;
583             if (!isProvisionManagedDeviceFromTrustedSourceIntent) {
584                 if (hasExtraFromLongName(intent, EXTRA_PROVISIONING_MAIN_COLOR)) {
585                     mainColor = getIntExtraFromLongName(
586                             intent, EXTRA_PROVISIONING_MAIN_COLOR, 0 /* not used */);
587                 }
588                 parseOrganizationLogoUrlFromExtras(context, intent);
589             }
590 
591             DisclaimersParam disclaimersParam = new DisclaimersParser(context, provisioningId)
592                     .parse(getParcelableArrayExtraFromLongName(
593                             intent, EXTRA_PROVISIONING_DISCLAIMERS));
594 
595             String deviceAdminLabel = null;
596             String organizationName = null;
597             String supportUrl = null;
598             String deviceAdminIconFilePath = null;
599             if (isProvisionManagedDeviceFromTrustedSourceIntent || isFinancedDeviceProvisioning) {
600                 deviceAdminLabel = getStringExtraFromLongName(intent,
601                         EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_LABEL);
602                 organizationName = getStringExtraFromLongName(
603                         intent,EXTRA_PROVISIONING_ORGANIZATION_NAME);
604                 supportUrl = getStringExtraFromLongName(intent,EXTRA_PROVISIONING_SUPPORT_URL);
605                 deviceAdminIconFilePath = new DeviceAdminIconParser(context, provisioningId).parse(
606                         getParcelableExtraFromLongName(intent,
607                                 EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_ICON_URI));
608             }
609 
610             final boolean leaveAllSystemAppsEnabled = isManagedProfileAction
611                     ? false
612                     : (isFinancedDeviceProvisioning ||
613                             getBooleanExtraFromLongName(
614                                     intent, EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED,
615                                     ProvisioningParams.DEFAULT_LEAVE_ALL_SYSTEM_APPS_ENABLED));
616 
617             return ProvisioningParams.Builder.builder()
618                     .setProvisioningId(provisioningId)
619                     .setProvisioningAction(provisioningAction)
620                     .setDeviceAdminComponentName(deviceAdminComponentName)
621                     .setDeviceAdminPackageName(deviceAdminPackageName)
622                     .setSkipEncryption(
623                             getBooleanExtraFromLongName(
624                                     intent, EXTRA_PROVISIONING_SKIP_ENCRYPTION,
625                                     ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_ENCRYPTION))
626                     .setLeaveAllSystemAppsEnabled(leaveAllSystemAppsEnabled)
627                     .setAdminExtrasBundle(getParcelableExtraFromLongName(
628                             intent, EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE))
629                     .setMainColor(mainColor)
630                     .setDisclaimersParam(disclaimersParam)
631                     .setSkipUserConsent(skipUserConsent)
632                     .setKeepAccountMigrated(keepAccountMigrated)
633                     .setSkipUserSetup(skipUserSetup)
634                     .setSkipEducationScreens(skipEducationScreens)
635                     .setAccountToMigrate(getParcelableExtraFromLongName(
636                             intent, EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE))
637                     .setDeviceAdminLabel(deviceAdminLabel)
638                     .setOrganizationName(organizationName)
639                     .setSupportUrl(supportUrl)
640                     .setDeviceAdminIconFilePath(deviceAdminIconFilePath)
641                     .setIsQrProvisioning(mUtils.isQrProvisioning(intent))
642                     .setIsOrganizationOwnedProvisioning(
643                             mUtils.isOrganizationOwnedProvisioning(intent));
644         } catch (ClassCastException e) {
645             throw new IllegalProvisioningArgumentException("Extra has invalid type", e);
646         } catch (IllegalArgumentException e) {
647             throw new IllegalProvisioningArgumentException("Invalid parameter found!", e);
648         } catch (NullPointerException e) {
649             throw new IllegalProvisioningArgumentException("Compulsory parameter not found!", e);
650         }
651     }
652 
653     /**
654      * When {@link DevicePolicyManager#EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS} is passed as
655      * a provisioning extra, we only process it for managed Google account enrollment and
656      * persistent device owner.
657      */
shouldSkipEducationScreens(Intent intent)658     private boolean shouldSkipEducationScreens(Intent intent) {
659         if (!getBooleanExtraFromLongName(intent,
660                 EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS,
661                 DEFAULT_EXTRA_PROVISIONING_SKIP_EDUCATION_SCREENS)) {
662             return false;
663         }
664         if (mUtils.isOrganizationOwnedProvisioning(intent)) {
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 Wifi configuration from an Intent and returns the result in {@link WifiInfo}.
721      */
722     @Nullable
parseWifiInfoFromExtras(Intent intent)723     private WifiInfo parseWifiInfoFromExtras(Intent intent) {
724         if (getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_SSID) == null) {
725             return null;
726         }
727         return WifiInfo.Builder.builder()
728                 .setSsid(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_SSID))
729                 .setSecurityType(
730                         getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_SECURITY_TYPE))
731                 .setPassword(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_PASSWORD))
732                 .setProxyHost(getStringExtraFromLongName(
733                         intent, EXTRA_PROVISIONING_WIFI_PROXY_HOST))
734                 .setProxyBypassHosts(
735                         getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_PROXY_BYPASS))
736                 .setPacUrl(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_PAC_URL))
737                 .setProxyPort(getIntExtraFromLongName(
738                         intent, EXTRA_PROVISIONING_WIFI_PROXY_PORT,
739                         WifiInfo.DEFAULT_WIFI_PROXY_PORT))
740                 .setEapMethod(getStringExtraFromLongName(
741                         intent, EXTRA_PROVISIONING_WIFI_EAP_METHOD))
742                 .setPhase2Auth(getStringExtraFromLongName(
743                         intent, EXTRA_PROVISIONING_WIFI_PHASE2_AUTH))
744                 .setCaCertificate(getStringExtraFromLongName(
745                         intent, EXTRA_PROVISIONING_WIFI_CA_CERTIFICATE))
746                 .setUserCertificate(getStringExtraFromLongName(
747                         intent, EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE))
748                 .setIdentity(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_IDENTITY))
749                 .setAnonymousIdentity(getStringExtraFromLongName(
750                         intent, EXTRA_PROVISIONING_WIFI_ANONYMOUS_IDENTITY))
751                 .setDomain(getStringExtraFromLongName(intent, EXTRA_PROVISIONING_WIFI_DOMAIN))
752                 .setHidden(getBooleanExtraFromLongName(
753                         intent, EXTRA_PROVISIONING_WIFI_HIDDEN, WifiInfo.DEFAULT_WIFI_HIDDEN))
754                 .build();
755     }
756 
757     /**
758      * Parses device admin package download info configuration from an Intent and returns the result
759      * in {@link PackageDownloadInfo}.
760      */
761     @Nullable
parsePackageDownloadInfoFromExtras(Intent intent)762     private PackageDownloadInfo parsePackageDownloadInfoFromExtras(Intent intent) {
763         if (getStringExtraFromLongName(
764                 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION) == null) {
765             return null;
766         }
767         PackageDownloadInfo.Builder downloadInfoBuilder = PackageDownloadInfo.Builder.builder()
768                 .setMinVersion(getIntExtraFromLongName(
769                         intent, EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE,
770                         PackageDownloadInfo.DEFAULT_MINIMUM_VERSION))
771                 .setLocation(getStringExtraFromLongName(
772                         intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION))
773                 .setCookieHeader(getStringExtraFromLongName(
774                         intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER));
775         String packageHash =
776                 getStringExtraFromLongName(
777                         intent, EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM);
778         if (packageHash != null) {
779             downloadInfoBuilder.setPackageChecksum(StoreUtils.stringToByteArray(packageHash));
780         }
781         String sigHash = getStringExtraFromLongName(
782                 intent, EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM);
783         if (sigHash != null) {
784             downloadInfoBuilder.setSignatureChecksum(StoreUtils.stringToByteArray(sigHash));
785         }
786         return downloadInfoBuilder.build();
787     }
788 
789     /**
790      * Parses the organization logo url from intent.
791      */
parseOrganizationLogoUrlFromExtras(Context context, Intent intent)792     private void parseOrganizationLogoUrlFromExtras(Context context, Intent intent) {
793         Uri logoUri = getParcelableExtraFromLongName(intent, EXTRA_PROVISIONING_LOGO_URI);
794         if (logoUri != null) {
795             // If we go through encryption, and if the uri is a content uri:
796             // We'll lose the grant to this uri. So we need to save it to a local file.
797             LogoUtils.saveOrganisationLogo(context, logoUri);
798         }
799     }
800 }
801