Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014, 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; |
| 18 | |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 19 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE; |
| 20 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME; |
| 21 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOCALE; |
| 22 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID; |
| 23 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_HIDDEN; |
| 24 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SECURITY_TYPE; |
| 25 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD; |
| 26 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_HOST; |
| 27 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_PORT; |
| 28 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PROXY_BYPASS; |
| 29 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PAC_URL; |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 30 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE; |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 31 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME; |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 32 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE; |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 33 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM; |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 34 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION; |
Sander Alewijnse | d8dcb1f | 2014-07-24 15:24:50 +0100 | [diff] [blame] | 35 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER; |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 36 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME; |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 37 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM; |
| 38 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME; |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 39 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE; |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 40 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION; |
| 41 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER; |
| 42 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM; |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 43 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED; |
Julia Reynolds | 5d47b65 | 2015-02-02 06:47:25 -0500 | [diff] [blame] | 44 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION; |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 45 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_BT_MAC_ADDRESS; |
| 46 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_BT_UUID; |
| 47 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_BT_DEVICE_ID; |
| 48 | import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_BT_USE_PROXY; |
Esteban Talavera | e917d11 | 2014-08-20 14:23:53 +0100 | [diff] [blame] | 49 | import static android.app.admin.DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC; |
Craig Lafayette | a58843e | 2015-03-27 06:54:28 -0400 | [diff] [blame^] | 50 | import static android.app.admin.DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC_V2; |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 51 | import static java.nio.charset.StandardCharsets.UTF_8; |
| 52 | |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 53 | import android.content.ComponentName; |
| 54 | import android.content.Context; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 55 | import android.content.Intent; |
| 56 | import android.nfc.NdefMessage; |
| 57 | import android.nfc.NdefRecord; |
| 58 | import android.nfc.NfcAdapter; |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 59 | import android.os.Bundle; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 60 | import android.os.Parcelable; |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 61 | import android.os.PersistableBundle; |
Sander Alewijnse | d704385 | 2014-06-17 15:50:48 +0100 | [diff] [blame] | 62 | import android.text.TextUtils; |
Sander Alewijnse | 48fdbe0 | 2014-07-03 14:25:45 +0100 | [diff] [blame] | 63 | import android.util.Base64; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 64 | |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 65 | import com.android.managedprovisioning.Utils.IllegalProvisioningArgumentException; |
| 66 | |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 67 | import java.io.IOException; |
| 68 | import java.io.StringReader; |
| 69 | import java.util.Enumeration; |
| 70 | import java.util.HashMap; |
Narayan Kamath | 53ff3c0 | 2014-07-17 14:02:58 +0100 | [diff] [blame] | 71 | import java.util.IllformedLocaleException; |
Sander Alewijnse | 63254f4 | 2014-03-21 15:31:12 +0000 | [diff] [blame] | 72 | import java.util.Locale; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 73 | import java.util.Properties; |
| 74 | |
| 75 | /** |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 76 | * This class can initialize a {@link ProvisioningParams} object from an intent. |
| 77 | * A {@link ProvisioningParams} object stores various parameters for the device owner provisioning. |
| 78 | * There are two kinds of intents that can be parsed it into {@link ProvisioningParams}: |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 79 | * |
| 80 | * <p> |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 81 | * Intent was received via Nfc. |
| 82 | * The intent contains the extra {@link NfcAdapter.EXTRA_NDEF_MESSAGES}, which indicates that |
| 83 | * provisioning was started via Nfc bump. This extra contains an NDEF message, which contains an |
Esteban Talavera | e917d11 | 2014-08-20 14:23:53 +0100 | [diff] [blame] | 84 | * NfcRecord with mime type {@link MIME_TYPE_PROVISIONING_NFC}. This record stores a serialized |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 85 | * properties object, which contains the serialized extra's described in the next option. |
| 86 | * A typical use case would be a programmer application that sends an Nfc bump to start Nfc |
| 87 | * provisioning from a programmer device. |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 88 | * |
| 89 | * <p> |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 90 | * Intent was received directly. |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 91 | * The intent contains the extra {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME} or |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 92 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME} (which is deprecated and supported for |
| 93 | * legacy reasons only), and may contain {@link #EXTRA_PROVISIONING_TIME_ZONE}, |
| 94 | * {@link #EXTRA_PROVISIONING_LOCAL_TIME}, {@link #EXTRA_PROVISIONING_LOCALE}, and |
| 95 | * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME}. A download |
| 96 | * location for the device admin may be specified in |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 97 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION}, together with an optional |
| 98 | * {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE}, an optional |
| 99 | * http cookie header {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER}, and |
| 100 | * the SHA-1 sum of the target file {@link #EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM}. A |
| 101 | * download location for the device initializer may be specified in |
| 102 | * {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION}, together with an |
| 103 | * optional (@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE}, an optional http |
| 104 | * cookie header {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER} , and |
| 105 | * the SHA-1 sum of the target file {@link #EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM}. |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 106 | * Additional information to send through to the device initializer and admin may be specified in |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 107 | * {@link #EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE}. |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 108 | * The optional boolean {@link #EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED} indicates whether |
| 109 | * system apps should not be disabled. The optional boolean |
| 110 | * {@link #EXTRA_PROVISIONING_SKIP_ENCRYPTION} specifies whether the device should be encrypted. |
Sander Alewijnse | d8dcb1f | 2014-07-24 15:24:50 +0100 | [diff] [blame] | 111 | * Furthermore a wifi network may be specified in {@link #EXTRA_PROVISIONING_WIFI_SSID}, and if |
| 112 | * applicable {@link #EXTRA_PROVISIONING_WIFI_HIDDEN}, |
| 113 | * {@link #EXTRA_PROVISIONING_WIFI_SECURITY_TYPE}, {@link #EXTRA_PROVISIONING_WIFI_PASSWORD}, |
| 114 | * {@link #EXTRA_PROVISIONING_WIFI_PROXY_HOST}, {@link #EXTRA_PROVISIONING_WIFI_PROXY_PORT}, |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 115 | * {@link #EXTRA_PROVISIONING_WIFI_PROXY_BYPASS}. The optional fields |
| 116 | * {@link #EXTRA_PROVISIONING_BT_MAC_ADDRESS}, {@link #EXTRA_PROVISIONING_BT_UUID}, and |
| 117 | * {@link #EXTRA_PROVISIONING_BT_DEVICE_ID} define how to connect to a remote device over Bluetooth. |
| 118 | * The boolean {@link #EXTRA_PROVISIONING_BT_USE_PROXY}, if true, will allow this device to proxy |
| 119 | * network activity over the defined Bluetooth connection during initial setup. |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 120 | * A typical use case would be the {@link BootReminder} sending the intent after device encryption |
| 121 | * and reboot. |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 122 | * |
| 123 | * <p> |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 124 | * Furthermore this class can construct the bundle of extras for the second kind of intent given a |
| 125 | * {@link ProvisioningParams}, and it keeps track of the types of the extras in the |
| 126 | * DEVICE_OWNER_x_EXTRAS, with x the appropriate type. |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 127 | */ |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 128 | public class MessageParser { |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 129 | private static final String EXTRA_PROVISIONING_STARTED_BY_NFC = |
| 130 | "com.android.managedprovisioning.extra.started_by_nfc"; |
| 131 | |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 132 | protected static final String[] DEVICE_OWNER_STRING_EXTRAS = { |
| 133 | EXTRA_PROVISIONING_TIME_ZONE, |
| 134 | EXTRA_PROVISIONING_LOCALE, |
| 135 | EXTRA_PROVISIONING_WIFI_SSID, |
| 136 | EXTRA_PROVISIONING_WIFI_SECURITY_TYPE, |
| 137 | EXTRA_PROVISIONING_WIFI_PASSWORD, |
| 138 | EXTRA_PROVISIONING_WIFI_PROXY_HOST, |
| 139 | EXTRA_PROVISIONING_WIFI_PROXY_BYPASS, |
| 140 | EXTRA_PROVISIONING_WIFI_PAC_URL, |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 141 | EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 142 | EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, |
Sander Alewijnse | d8dcb1f | 2014-07-24 15:24:50 +0100 | [diff] [blame] | 143 | EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER, |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 144 | EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, |
| 145 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION, |
| 146 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER, |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 147 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM, |
| 148 | EXTRA_PROVISIONING_BT_MAC_ADDRESS, |
| 149 | EXTRA_PROVISIONING_BT_UUID, |
| 150 | EXTRA_PROVISIONING_BT_DEVICE_ID |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | protected static final String[] DEVICE_OWNER_LONG_EXTRAS = { |
| 154 | EXTRA_PROVISIONING_LOCAL_TIME |
| 155 | }; |
| 156 | |
| 157 | protected static final String[] DEVICE_OWNER_INT_EXTRAS = { |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 158 | EXTRA_PROVISIONING_WIFI_PROXY_PORT, |
| 159 | EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE, |
| 160 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | protected static final String[] DEVICE_OWNER_BOOLEAN_EXTRAS = { |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 164 | EXTRA_PROVISIONING_WIFI_HIDDEN, |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 165 | EXTRA_PROVISIONING_STARTED_BY_NFC, |
Julia Reynolds | 5d47b65 | 2015-02-02 06:47:25 -0500 | [diff] [blame] | 166 | EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED, |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 167 | EXTRA_PROVISIONING_SKIP_ENCRYPTION, |
| 168 | EXTRA_PROVISIONING_BT_USE_PROXY |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 169 | }; |
| 170 | |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 171 | protected static final String[] DEVICE_OWNER_PERSISTABLE_BUNDLE_EXTRAS = { |
| 172 | EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE |
| 173 | }; |
| 174 | |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 175 | protected static final String[] DEVICE_OWNER_COMPONENT_NAME_EXTRAS = { |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 176 | EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, |
| 177 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 180 | public void addProvisioningParamsToBundle(Bundle bundle, ProvisioningParams params) { |
| 181 | bundle.putString(EXTRA_PROVISIONING_TIME_ZONE, params.mTimeZone); |
| 182 | bundle.putString(EXTRA_PROVISIONING_LOCALE, params.getLocaleAsString()); |
| 183 | bundle.putString(EXTRA_PROVISIONING_WIFI_SSID, params.mWifiSsid); |
| 184 | bundle.putString(EXTRA_PROVISIONING_WIFI_SECURITY_TYPE, params.mWifiSecurityType); |
| 185 | bundle.putString(EXTRA_PROVISIONING_WIFI_PASSWORD, params.mWifiPassword); |
| 186 | bundle.putString(EXTRA_PROVISIONING_WIFI_PROXY_HOST, params.mWifiProxyHost); |
| 187 | bundle.putString(EXTRA_PROVISIONING_WIFI_PROXY_BYPASS, params.mWifiProxyBypassHosts); |
| 188 | bundle.putString(EXTRA_PROVISIONING_WIFI_PAC_URL, params.mWifiPacUrl); |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 189 | bundle.putString(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, |
| 190 | params.mDeviceAdminPackageName); |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 191 | bundle.putParcelable(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, |
| 192 | params.mDeviceAdminComponentName); |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 193 | bundle.putInt(EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE, |
| 194 | params.mDeviceAdminMinVersion); |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 195 | bundle.putString(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, |
| 196 | params.mDeviceAdminPackageDownloadLocation); |
Sander Alewijnse | d8dcb1f | 2014-07-24 15:24:50 +0100 | [diff] [blame] | 197 | bundle.putString(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER, |
| 198 | params.mDeviceAdminPackageDownloadCookieHeader); |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 199 | bundle.putString(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, |
| 200 | params.getDeviceAdminPackageChecksumAsString()); |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 201 | bundle.putParcelable(EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME, |
| 202 | params.mDeviceInitializerComponentName); |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 203 | bundle.putInt(EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE, |
| 204 | params.mDeviceInitializerMinVersion); |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 205 | bundle.putString(EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION, |
| 206 | params.mDeviceInitializerPackageDownloadLocation); |
| 207 | bundle.putString(EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER, |
| 208 | params.mDeviceInitializerPackageDownloadCookieHeader); |
| 209 | bundle.putString(EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM, |
| 210 | params.getDeviceInitializerPackageChecksumAsString()); |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 211 | |
| 212 | bundle.putLong(EXTRA_PROVISIONING_LOCAL_TIME, params.mLocalTime); |
| 213 | |
| 214 | bundle.putInt(EXTRA_PROVISIONING_WIFI_PROXY_PORT, params.mWifiProxyPort); |
| 215 | |
| 216 | bundle.putBoolean(EXTRA_PROVISIONING_WIFI_HIDDEN, params.mWifiHidden); |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 217 | bundle.putBoolean(EXTRA_PROVISIONING_STARTED_BY_NFC, params.mStartedByNfc); |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 218 | bundle.putBoolean(EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED, |
| 219 | params.mLeaveAllSystemAppsEnabled); |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 220 | |
| 221 | bundle.putParcelable(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, params.mAdminExtrasBundle); |
Julia Reynolds | 5d47b65 | 2015-02-02 06:47:25 -0500 | [diff] [blame] | 222 | bundle.putBoolean(EXTRA_PROVISIONING_SKIP_ENCRYPTION, params.mSkipEncryption); |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 223 | |
| 224 | // Bluetooth parameters |
| 225 | bundle.putString(EXTRA_PROVISIONING_BT_MAC_ADDRESS, params.mBluetoothMac); |
| 226 | bundle.putString(EXTRA_PROVISIONING_BT_UUID, params.mBluetoothUuid); |
| 227 | bundle.putString(EXTRA_PROVISIONING_BT_DEVICE_ID, params.mBluetoothDeviceIdentifier); |
| 228 | bundle.putBoolean(EXTRA_PROVISIONING_BT_USE_PROXY, params.mUseBluetoothProxy); |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 231 | public ProvisioningParams parseIntent(Intent intent) |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 232 | throws IllegalProvisioningArgumentException { |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 233 | ProvisionLogger.logi("Processing intent."); |
| 234 | if (intent.hasExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 235 | return parseNfcIntent(intent); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 236 | } else { |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 237 | return parseNonNfcIntent(intent); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 238 | } |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 241 | public ProvisioningParams parseNfcIntent(Intent nfcIntent) |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 242 | throws IllegalProvisioningArgumentException { |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 243 | ProvisionLogger.logi("Processing Nfc Payload."); |
| 244 | // Only one first message with NFC_MIME_TYPE is used. |
| 245 | for (Parcelable rawMsg : nfcIntent |
| 246 | .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { |
| 247 | NdefMessage msg = (NdefMessage) rawMsg; |
| 248 | |
| 249 | // Assume only first record of message is used. |
| 250 | NdefRecord firstRecord = msg.getRecords()[0]; |
| 251 | String mimeType = new String(firstRecord.getType(), UTF_8); |
| 252 | |
Craig Lafayette | a58843e | 2015-03-27 06:54:28 -0400 | [diff] [blame^] | 253 | if (MIME_TYPE_PROVISIONING_NFC.equals(mimeType) || |
| 254 | MIME_TYPE_PROVISIONING_NFC_V2.equals(mimeType)) { |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 255 | ProvisioningParams params = parseProperties(new String(firstRecord.getPayload() |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 256 | , UTF_8)); |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 257 | params.mStartedByNfc = true; |
| 258 | return params; |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 259 | } |
| 260 | } |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 261 | throw new IllegalProvisioningArgumentException( |
| 262 | "Intent does not contain NfcRecord with the correct MIME type."); |
Sander Alewijnse | 28bffd6 | 2014-06-05 10:54:26 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Andrei Kapishnikov | d75aebb | 2015-02-02 11:22:19 -0500 | [diff] [blame] | 265 | // Note: EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE property contains a Properties object |
| 266 | // serialized into String. See Properties.store() and Properties.load() for more details. |
| 267 | // The property value is optional. |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 268 | private ProvisioningParams parseProperties(String data) |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 269 | throws IllegalProvisioningArgumentException { |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 270 | ProvisioningParams params = new ProvisioningParams(); |
| 271 | try { |
| 272 | Properties props = new Properties(); |
| 273 | props.load(new StringReader(data)); |
| 274 | |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 275 | String s; // Used for parsing non-Strings. |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 276 | params.mTimeZone |
| 277 | = props.getProperty(EXTRA_PROVISIONING_TIME_ZONE); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 278 | if ((s = props.getProperty(EXTRA_PROVISIONING_LOCALE)) != null) { |
| 279 | params.mLocale = stringToLocale(s); |
| 280 | } |
| 281 | params.mWifiSsid = props.getProperty(EXTRA_PROVISIONING_WIFI_SSID); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 282 | params.mWifiSecurityType = props.getProperty(EXTRA_PROVISIONING_WIFI_SECURITY_TYPE); |
| 283 | params.mWifiPassword = props.getProperty(EXTRA_PROVISIONING_WIFI_PASSWORD); |
| 284 | params.mWifiProxyHost = props.getProperty(EXTRA_PROVISIONING_WIFI_PROXY_HOST); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 285 | params.mWifiProxyBypassHosts = props.getProperty(EXTRA_PROVISIONING_WIFI_PROXY_BYPASS); |
| 286 | params.mWifiPacUrl = props.getProperty(EXTRA_PROVISIONING_WIFI_PAC_URL); |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 287 | params.mDeviceAdminPackageName |
| 288 | = props.getProperty(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME); |
| 289 | String componentNameString = props.getProperty( |
| 290 | EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME); |
| 291 | if (componentNameString != null) { |
| 292 | params.mDeviceAdminComponentName = ComponentName.unflattenFromString( |
| 293 | componentNameString); |
| 294 | } |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 295 | if ((s = props.getProperty( |
| 296 | EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE)) != null) { |
| 297 | params.mDeviceAdminMinVersion = Integer.parseInt(s); |
| 298 | } else { |
| 299 | params.mDeviceAdminMinVersion = ProvisioningParams.DEFAULT_MINIMUM_VERSION; |
| 300 | } |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 301 | params.mDeviceAdminPackageDownloadLocation |
| 302 | = props.getProperty(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION); |
Sander Alewijnse | d8dcb1f | 2014-07-24 15:24:50 +0100 | [diff] [blame] | 303 | params.mDeviceAdminPackageDownloadCookieHeader = props.getProperty( |
| 304 | EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 305 | if ((s = props.getProperty(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM)) != null) { |
| 306 | params.mDeviceAdminPackageChecksum = stringToByteArray(s); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 307 | } |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 308 | String name = props.getProperty( |
| 309 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME); |
| 310 | if (name != null) { |
| 311 | params.mDeviceInitializerComponentName = ComponentName.unflattenFromString(name); |
| 312 | } |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 313 | if ((s = props.getProperty( |
| 314 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE)) != null) { |
| 315 | params.mDeviceInitializerMinVersion = Integer.parseInt(s); |
| 316 | } else { |
| 317 | params.mDeviceInitializerMinVersion = ProvisioningParams.DEFAULT_MINIMUM_VERSION; |
| 318 | } |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 319 | params.mDeviceInitializerPackageDownloadLocation = props.getProperty( |
| 320 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION); |
| 321 | params.mDeviceInitializerPackageDownloadCookieHeader = props.getProperty( |
| 322 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER); |
| 323 | if ((s = props.getProperty( |
| 324 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM)) != null) { |
| 325 | params.mDeviceInitializerPackageChecksum = stringToByteArray(s); |
| 326 | } |
Sander Alewijnse | 885c349 | 2014-04-24 17:30:31 +0100 | [diff] [blame] | 327 | |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 328 | if ((s = props.getProperty(EXTRA_PROVISIONING_LOCAL_TIME)) != null) { |
| 329 | params.mLocalTime = Long.parseLong(s); |
| 330 | } |
| 331 | |
| 332 | if ((s = props.getProperty(EXTRA_PROVISIONING_WIFI_PROXY_PORT)) != null) { |
| 333 | params.mWifiProxyPort = Integer.parseInt(s); |
| 334 | } |
| 335 | |
| 336 | if ((s = props.getProperty(EXTRA_PROVISIONING_WIFI_HIDDEN)) != null) { |
| 337 | params.mWifiHidden = Boolean.parseBoolean(s); |
| 338 | } |
| 339 | |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 340 | if ((s = props.getProperty(EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED)) != null) { |
| 341 | params.mLeaveAllSystemAppsEnabled = Boolean.parseBoolean(s); |
| 342 | } |
Julia Reynolds | 5d47b65 | 2015-02-02 06:47:25 -0500 | [diff] [blame] | 343 | if ((s = props.getProperty(EXTRA_PROVISIONING_SKIP_ENCRYPTION)) != null) { |
| 344 | params.mSkipEncryption = Boolean.parseBoolean(s); |
| 345 | } |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 346 | |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 347 | params.mBluetoothMac = props.getProperty(EXTRA_PROVISIONING_BT_MAC_ADDRESS); |
| 348 | params.mBluetoothUuid = props.getProperty(EXTRA_PROVISIONING_BT_UUID); |
| 349 | params.mBluetoothDeviceIdentifier = props.getProperty(EXTRA_PROVISIONING_BT_DEVICE_ID); |
| 350 | if ((s = props.getProperty(EXTRA_PROVISIONING_BT_USE_PROXY)) != null) { |
| 351 | params.mUseBluetoothProxy = Boolean.parseBoolean(s); |
| 352 | } |
| 353 | |
Andrei Kapishnikov | d75aebb | 2015-02-02 11:22:19 -0500 | [diff] [blame] | 354 | deserializeAdminExtrasBundle(params, props); |
| 355 | |
Sander Alewijnse | 885c349 | 2014-04-24 17:30:31 +0100 | [diff] [blame] | 356 | checkValidityOfProvisioningParams(params); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 357 | return params; |
| 358 | } catch (IOException e) { |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 359 | throw new Utils.IllegalProvisioningArgumentException("Couldn't load payload", e); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 360 | } catch (NumberFormatException e) { |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 361 | throw new Utils.IllegalProvisioningArgumentException("Incorrect numberformat.", e); |
Narayan Kamath | 53ff3c0 | 2014-07-17 14:02:58 +0100 | [diff] [blame] | 362 | } catch (IllformedLocaleException e) { |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 363 | throw new Utils.IllegalProvisioningArgumentException("Invalid locale.", e); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
Andrei Kapishnikov | d75aebb | 2015-02-02 11:22:19 -0500 | [diff] [blame] | 367 | private void deserializeAdminExtrasBundle(ProvisioningParams params, Properties props) |
| 368 | throws IOException { |
| 369 | String serializedExtras = props.getProperty(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE); |
| 370 | if (serializedExtras != null) { |
| 371 | Properties extrasProp = new Properties(); |
| 372 | extrasProp.load(new StringReader(serializedExtras)); |
| 373 | PersistableBundle extrasBundle = new PersistableBundle(extrasProp.size()); |
| 374 | for (String propName : extrasProp.stringPropertyNames()) { |
| 375 | extrasBundle.putString(propName, extrasProp.getProperty(propName)); |
| 376 | } |
| 377 | params.mAdminExtrasBundle = extrasBundle; |
| 378 | } |
| 379 | } |
| 380 | |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 381 | public ProvisioningParams parseNonNfcIntent(Intent intent) |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 382 | throws IllegalProvisioningArgumentException { |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 383 | ProvisionLogger.logi("Processing intent."); |
| 384 | ProvisioningParams params = new ProvisioningParams(); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 385 | |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 386 | params.mTimeZone = intent.getStringExtra(EXTRA_PROVISIONING_TIME_ZONE); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 387 | String localeString = intent.getStringExtra(EXTRA_PROVISIONING_LOCALE); |
| 388 | if (localeString != null) { |
| 389 | params.mLocale = stringToLocale(localeString); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 390 | } |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 391 | params.mWifiSsid = intent.getStringExtra(EXTRA_PROVISIONING_WIFI_SSID); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 392 | params.mWifiSecurityType = intent.getStringExtra(EXTRA_PROVISIONING_WIFI_SECURITY_TYPE); |
| 393 | params.mWifiPassword = intent.getStringExtra(EXTRA_PROVISIONING_WIFI_PASSWORD); |
| 394 | params.mWifiProxyHost = intent.getStringExtra(EXTRA_PROVISIONING_WIFI_PROXY_HOST); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 395 | params.mWifiProxyBypassHosts = intent.getStringExtra(EXTRA_PROVISIONING_WIFI_PROXY_BYPASS); |
| 396 | params.mWifiPacUrl = intent.getStringExtra(EXTRA_PROVISIONING_WIFI_PAC_URL); |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 397 | params.mDeviceAdminComponentName = (ComponentName) intent.getParcelableExtra( |
| 398 | EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME); |
| 399 | params.mDeviceAdminPackageName |
| 400 | = intent.getStringExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME); |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 401 | params.mDeviceAdminMinVersion = intent.getIntExtra( |
| 402 | EXTRA_PROVISIONING_DEVICE_ADMIN_MINIMUM_VERSION_CODE, |
| 403 | ProvisioningParams.DEFAULT_MINIMUM_VERSION); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 404 | params.mDeviceAdminPackageDownloadLocation |
| 405 | = intent.getStringExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION); |
Sander Alewijnse | d8dcb1f | 2014-07-24 15:24:50 +0100 | [diff] [blame] | 406 | params.mDeviceAdminPackageDownloadCookieHeader = intent.getStringExtra( |
| 407 | EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_COOKIE_HEADER); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 408 | String hashString = intent.getStringExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM); |
| 409 | if (hashString != null) { |
| 410 | params.mDeviceAdminPackageChecksum = stringToByteArray(hashString); |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 411 | } |
Rubin Xu | ba6e25d | 2015-03-23 17:26:21 +0000 | [diff] [blame] | 412 | params.mDeviceInitializerComponentName = (ComponentName) intent.getParcelableExtra( |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 413 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_COMPONENT_NAME); |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 414 | params.mDeviceInitializerMinVersion = intent.getIntExtra( |
| 415 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_MINIMUM_VERSION_CODE, |
| 416 | ProvisioningParams.DEFAULT_MINIMUM_VERSION); |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 417 | params.mDeviceInitializerPackageDownloadLocation = intent.getStringExtra( |
| 418 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_LOCATION); |
| 419 | params.mDeviceInitializerPackageDownloadCookieHeader = intent.getStringExtra( |
| 420 | EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_DOWNLOAD_COOKIE_HEADER); |
| 421 | hashString = intent.getStringExtra(EXTRA_PROVISIONING_DEVICE_INITIALIZER_PACKAGE_CHECKSUM); |
| 422 | if (hashString != null) { |
| 423 | params.mDeviceInitializerPackageChecksum = stringToByteArray(hashString); |
| 424 | } |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 425 | |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 426 | params.mLocalTime = intent.getLongExtra(EXTRA_PROVISIONING_LOCAL_TIME, |
| 427 | ProvisioningParams.DEFAULT_LOCAL_TIME); |
| 428 | |
| 429 | params.mWifiProxyPort = intent.getIntExtra(EXTRA_PROVISIONING_WIFI_PROXY_PORT, |
| 430 | ProvisioningParams.DEFAULT_WIFI_PROXY_PORT); |
| 431 | |
| 432 | params.mWifiHidden = intent.getBooleanExtra(EXTRA_PROVISIONING_WIFI_HIDDEN, |
| 433 | ProvisioningParams.DEFAULT_WIFI_HIDDEN); |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 434 | params.mStartedByNfc = intent.getBooleanExtra(EXTRA_PROVISIONING_STARTED_BY_NFC, |
| 435 | false); |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 436 | params.mLeaveAllSystemAppsEnabled = intent.getBooleanExtra( |
| 437 | EXTRA_PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED, |
| 438 | ProvisioningParams.DEFAULT_LEAVE_ALL_SYSTEM_APPS_ENABLED); |
Julia Reynolds | 5d47b65 | 2015-02-02 06:47:25 -0500 | [diff] [blame] | 439 | params.mSkipEncryption = intent.getBooleanExtra( |
| 440 | EXTRA_PROVISIONING_SKIP_ENCRYPTION, |
| 441 | ProvisioningParams.DEFAULT_EXTRA_PROVISIONING_SKIP_ENCRYPTION); |
Sander Alewijnse | 8f9bd13 | 2014-09-08 12:21:26 +0100 | [diff] [blame] | 442 | |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 443 | params.mBluetoothMac = intent.getStringExtra(EXTRA_PROVISIONING_BT_MAC_ADDRESS); |
| 444 | params.mBluetoothUuid = intent.getStringExtra(EXTRA_PROVISIONING_BT_UUID); |
| 445 | params.mBluetoothDeviceIdentifier = intent.getStringExtra(EXTRA_PROVISIONING_BT_DEVICE_ID); |
| 446 | params.mUseBluetoothProxy = intent.getBooleanExtra(EXTRA_PROVISIONING_BT_USE_PROXY, false); |
| 447 | |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 448 | try { |
| 449 | params.mAdminExtrasBundle = (PersistableBundle) intent.getParcelableExtra( |
| 450 | EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE); |
| 451 | } catch (ClassCastException e) { |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 452 | throw new IllegalProvisioningArgumentException("Extra " |
| 453 | + EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE |
| 454 | + " must be of type PersistableBundle.", e); |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 455 | } |
Sander Alewijnse | 9aff140 | 2014-07-18 17:15:32 +0100 | [diff] [blame] | 456 | |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 457 | checkValidityOfProvisioningParams(params); |
| 458 | return params; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /** |
Sander Alewijnse | 885c349 | 2014-04-24 17:30:31 +0100 | [diff] [blame] | 462 | * Check whether necessary fields are set. |
| 463 | */ |
| 464 | private void checkValidityOfProvisioningParams(ProvisioningParams params) |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 465 | throws IllegalProvisioningArgumentException { |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 466 | if (TextUtils.isEmpty(params.mDeviceAdminPackageName) |
| 467 | && params.mDeviceAdminComponentName == null) { |
| 468 | throw new IllegalProvisioningArgumentException("Must provide the name of the device" |
| 469 | + " admin package or component name"); |
| 470 | } |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 471 | if (!TextUtils.isEmpty(params.mDeviceAdminPackageDownloadLocation)) { |
| 472 | if (params.mDeviceAdminPackageChecksum == null || |
| 473 | params.mDeviceAdminPackageChecksum.length == 0) { |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 474 | throw new IllegalProvisioningArgumentException("Checksum of installer file is" |
| 475 | + " required for downloading device admin file, but not provided."); |
Sander Alewijnse | 885c349 | 2014-04-24 17:30:31 +0100 | [diff] [blame] | 476 | } |
Sander Alewijnse | 885c349 | 2014-04-24 17:30:31 +0100 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 480 | public static byte[] stringToByteArray(String s) |
| 481 | throws NumberFormatException { |
Sander Alewijnse | 48fdbe0 | 2014-07-03 14:25:45 +0100 | [diff] [blame] | 482 | try { |
| 483 | return Base64.decode(s, Base64.URL_SAFE); |
| 484 | } catch (IllegalArgumentException e) { |
| 485 | throw new NumberFormatException("Incorrect checksum format."); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 486 | } |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | public static Locale stringToLocale(String s) |
Narayan Kamath | 53ff3c0 | 2014-07-17 14:02:58 +0100 | [diff] [blame] | 490 | throws IllformedLocaleException { |
| 491 | return new Locale.Builder().setLanguageTag(s.replace("_", "-")).build(); |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 492 | } |
Sander Alewijnse | 226d36c | 2014-06-26 16:33:05 +0000 | [diff] [blame] | 493 | } |