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 | |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 19 | import android.content.Context; |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 20 | import android.content.ComponentName; |
Sander Alewijnse | d704385 | 2014-06-17 15:50:48 +0100 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Sander Alewijnse | f88f709 | 2014-08-20 16:26:09 +0100 | [diff] [blame] | 23 | import android.os.PersistableBundle; |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 24 | import android.text.TextUtils; |
Sander Alewijnse | 48fdbe0 | 2014-07-03 14:25:45 +0100 | [diff] [blame] | 25 | import android.util.Base64; |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 26 | |
Sander Alewijnse | 63254f4 | 2014-03-21 15:31:12 +0000 | [diff] [blame] | 27 | import java.util.Locale; |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 28 | |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Provisioning Parameters for DeviceOwner Provisioning |
| 31 | */ |
Sander Alewijnse | d704385 | 2014-06-17 15:50:48 +0100 | [diff] [blame] | 32 | public class ProvisioningParams implements Parcelable { |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 33 | public static final long DEFAULT_LOCAL_TIME = -1; |
| 34 | public static final boolean DEFAULT_WIFI_HIDDEN = false; |
Sander Alewijnse | fd13487 | 2014-11-18 13:28:06 +0000 | [diff] [blame] | 35 | public static final boolean DEFAULT_LEAVE_ALL_SYSTEM_APPS_ENABLED = false; |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 36 | public static final int DEFAULT_WIFI_PROXY_PORT = 0; |
Julia Reynolds | 5d47b65 | 2015-02-02 06:47:25 -0500 | [diff] [blame] | 37 | public static final boolean DEFAULT_EXTRA_PROVISIONING_SKIP_ENCRYPTION = false; |
Julia Reynolds | f3a5b3b | 2015-03-20 09:34:37 -0400 | [diff] [blame] | 38 | // Always download packages if no minimum version given. |
| 39 | public static final int DEFAULT_MINIMUM_VERSION = Integer.MAX_VALUE; |
Sander Alewijnse | 56f7157 | 2014-06-23 16:21:33 +0100 | [diff] [blame] | 40 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 41 | public String timeZone; |
| 42 | public long localTime = DEFAULT_LOCAL_TIME; |
| 43 | public Locale locale; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 44 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 45 | public static class WifiInfo { |
| 46 | public String ssid; |
| 47 | public boolean hidden = DEFAULT_WIFI_HIDDEN; |
| 48 | public String securityType; |
| 49 | public String password; |
| 50 | public String proxyHost; |
| 51 | public int proxyPort = DEFAULT_WIFI_PROXY_PORT; |
| 52 | public String proxyBypassHosts; |
| 53 | public String pacUrl; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 54 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 55 | public void writeToParcel(Parcel out) { |
| 56 | out.writeString(ssid); |
| 57 | out.writeInt(hidden ? 1 : 0); |
| 58 | out.writeString(securityType); |
| 59 | out.writeString(password); |
| 60 | out.writeString(proxyHost); |
| 61 | out.writeInt(proxyPort); |
| 62 | out.writeString(proxyBypassHosts); |
| 63 | out.writeString(pacUrl); |
| 64 | } |
Sander Alewijnse | af8413e | 2014-03-19 11:37:44 +0000 | [diff] [blame] | 65 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 66 | public void readFromParcel(Parcel in) { |
| 67 | ssid = in.readString(); |
| 68 | hidden = in.readInt() == 1; |
| 69 | securityType = in.readString(); |
| 70 | password = in.readString(); |
| 71 | proxyHost = in.readString(); |
| 72 | proxyPort = in.readInt(); |
| 73 | proxyBypassHosts = in.readString(); |
| 74 | pacUrl = in.readString(); |
| 75 | } |
| 76 | }; |
| 77 | public WifiInfo wifiInfo = new WifiInfo(); |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 78 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 79 | // At least one one of deviceAdminPackageName and deviceAdminComponentName should be non-null |
| 80 | public String deviceAdminPackageName; // Package name of the device admin package. |
| 81 | public ComponentName deviceAdminComponentName; |
| 82 | public ComponentName deviceInitializerComponentName; |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 83 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 84 | private ComponentName inferedDeviceAdminComponentName; |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 85 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 86 | public static class PackageDownloadInfo { |
| 87 | // Url where the package (.apk) can be downloaded from |
| 88 | public String location; |
| 89 | // Cookie header for http request |
| 90 | public String cookieHeader; |
Sander Alewijnse | 3efa83a | 2015-04-14 14:46:18 +0100 | [diff] [blame] | 91 | // One of the following two checksums should be non empty. |
| 92 | // SHA-1 hash of the .apk file, or empty array if not used. |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 93 | public byte[] packageChecksum = new byte[0]; |
Sander Alewijnse | 3efa83a | 2015-04-14 14:46:18 +0100 | [diff] [blame] | 94 | // SHA-1 hash of the certificate in the .apk file, or empty array if not used. |
| 95 | public byte[] certificateChecksum = new byte[0]; |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 96 | public int minVersion; |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 97 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 98 | public void writeToParcel(Parcel out) { |
| 99 | out.writeInt(minVersion); |
| 100 | out.writeString(location); |
| 101 | out.writeString(cookieHeader); |
| 102 | out.writeByteArray(packageChecksum); |
Sander Alewijnse | 3efa83a | 2015-04-14 14:46:18 +0100 | [diff] [blame] | 103 | out.writeByteArray(certificateChecksum); |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 104 | } |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 105 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 106 | public void readFromParcel(Parcel in) { |
| 107 | minVersion = in.readInt(); |
| 108 | location = in.readString(); |
| 109 | cookieHeader = in.readString(); |
| 110 | packageChecksum = in.createByteArray(); |
Sander Alewijnse | 3efa83a | 2015-04-14 14:46:18 +0100 | [diff] [blame] | 111 | certificateChecksum = in.createByteArray(); |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | public PackageDownloadInfo deviceAdminDownloadInfo = new PackageDownloadInfo(); |
| 115 | public PackageDownloadInfo deviceInitializerDownloadInfo = new PackageDownloadInfo(); |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 116 | |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 117 | public PersistableBundle adminExtrasBundle; |
| 118 | public PersistableBundle frpChallengeBundle; |
| 119 | |
| 120 | public boolean startedByNfc; // True iff provisioning flow was started by Nfc bump. |
| 121 | |
| 122 | public boolean leaveAllSystemAppsEnabled; |
| 123 | public boolean skipEncryption; |
| 124 | |
| 125 | public static class BluetoothInfo { |
| 126 | public String mac; |
| 127 | public String uuid; |
| 128 | public String deviceIdentifier; |
| 129 | public boolean useProxy; |
| 130 | |
| 131 | public void writeToParcel(Parcel out) { |
| 132 | out.writeString(mac); |
| 133 | out.writeString(uuid); |
| 134 | out.writeString(deviceIdentifier); |
| 135 | out.writeInt(useProxy ? 1 : 0); |
| 136 | } |
| 137 | |
| 138 | public void readFromParcel(Parcel in) { |
| 139 | mac = in.readString(); |
| 140 | uuid = in.readString(); |
| 141 | deviceIdentifier = in.readString(); |
| 142 | useProxy = in.readInt() == 1; |
| 143 | } |
| 144 | }; |
| 145 | public BluetoothInfo bluetoothInfo = new BluetoothInfo(); |
Craig Lafayette | 2fe9d99 | 2015-03-24 12:42:05 -0400 | [diff] [blame] | 146 | |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 147 | public String inferDeviceAdminPackageName() { |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 148 | if (deviceAdminComponentName != null) { |
| 149 | return deviceAdminComponentName.getPackageName(); |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 150 | } |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 151 | return deviceAdminPackageName; |
| 152 | } |
| 153 | |
| 154 | public String getDeviceInitializerPackageName() { |
| 155 | if (deviceInitializerComponentName != null) { |
| 156 | return deviceInitializerComponentName.getPackageName(); |
| 157 | } |
| 158 | return null; |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // This should not be called if the app has not been installed yet. |
| 162 | ComponentName inferDeviceAdminComponentName(Context c) |
| 163 | throws Utils.IllegalProvisioningArgumentException { |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 164 | if (inferedDeviceAdminComponentName == null) { |
| 165 | inferedDeviceAdminComponentName = Utils.findDeviceAdmin( |
| 166 | deviceAdminPackageName, deviceAdminComponentName, c); |
Nicolas Prevot | 668d65f | 2015-03-10 17:58:15 +0000 | [diff] [blame] | 167 | } |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 168 | return inferedDeviceAdminComponentName; |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Sander Alewijnse | d704385 | 2014-06-17 15:50:48 +0100 | [diff] [blame] | 171 | @Override |
| 172 | public int describeContents() { |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public void writeToParcel(Parcel out, int flags) { |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 178 | out.writeString(timeZone); |
| 179 | out.writeLong(localTime); |
| 180 | out.writeSerializable(locale); |
| 181 | wifiInfo.writeToParcel(out); |
| 182 | out.writeString(deviceAdminPackageName); |
| 183 | out.writeParcelable(deviceAdminComponentName, 0 /* default */); |
| 184 | deviceAdminDownloadInfo.writeToParcel(out); |
| 185 | out.writeParcelable(deviceInitializerComponentName, 0 /* default */); |
| 186 | deviceInitializerDownloadInfo.writeToParcel(out); |
| 187 | out.writeParcelable(adminExtrasBundle, 0 /* default */); |
| 188 | out.writeInt(startedByNfc ? 1 : 0); |
| 189 | out.writeInt(leaveAllSystemAppsEnabled ? 1 : 0); |
| 190 | out.writeInt(skipEncryption ? 1 : 0); |
| 191 | bluetoothInfo.writeToParcel(out); |
| 192 | out.writeParcelable(frpChallengeBundle, 0 /* default */); |
Sander Alewijnse | d704385 | 2014-06-17 15:50:48 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | public static final Parcelable.Creator<ProvisioningParams> CREATOR |
| 196 | = new Parcelable.Creator<ProvisioningParams>() { |
| 197 | @Override |
| 198 | public ProvisioningParams createFromParcel(Parcel in) { |
| 199 | ProvisioningParams params = new ProvisioningParams(); |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 200 | params.timeZone = in.readString(); |
| 201 | params.localTime = in.readLong(); |
| 202 | params.locale = (Locale) in.readSerializable(); |
| 203 | params.wifiInfo.readFromParcel(in); |
| 204 | params.deviceAdminPackageName = in.readString(); |
| 205 | params.deviceAdminComponentName = (ComponentName) |
Nicolas Prevot | 0b44725 | 2015-03-09 14:59:02 +0000 | [diff] [blame] | 206 | in.readParcelable(null /* use default classloader */); |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 207 | params.deviceAdminDownloadInfo.readFromParcel(in); |
| 208 | params.deviceInitializerComponentName = (ComponentName) |
Julia Reynolds | 3f4eb37 | 2015-02-11 13:46:42 -0500 | [diff] [blame] | 209 | in.readParcelable(null /* use default classloader */); |
Sander Alewijnse | 74d6c14 | 2015-04-13 11:51:19 +0100 | [diff] [blame] | 210 | params.deviceInitializerDownloadInfo.readFromParcel(in); |
| 211 | params.adminExtrasBundle = in.readParcelable(null /* use default classloader */); |
| 212 | params.startedByNfc = in.readInt() == 1; |
| 213 | params.leaveAllSystemAppsEnabled = in.readInt() == 1; |
| 214 | params.skipEncryption = in.readInt() == 1; |
| 215 | params.bluetoothInfo.readFromParcel(in); |
| 216 | params.frpChallengeBundle = in.readParcelable(null /* use default classloader */); |
Sander Alewijnse | d704385 | 2014-06-17 15:50:48 +0100 | [diff] [blame] | 217 | return params; |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public ProvisioningParams[] newArray(int size) { |
| 222 | return new ProvisioningParams[size]; |
| 223 | } |
| 224 | }; |
Sander Alewijnse | ed0883b | 2014-03-18 15:01:13 +0000 | [diff] [blame] | 225 | } |