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 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 import android.os.PersistableBundle; 22 import android.util.Base64; 23 import java.util.Locale; 24 25 26 /** 27 * Provisioning Parameters for DeviceOwner Provisioning 28 */ 29 public class ProvisioningParams implements Parcelable { 30 public static final long DEFAULT_LOCAL_TIME = -1; 31 public static final boolean DEFAULT_WIFI_HIDDEN = false; 32 public static final boolean DEFAULT_LEAVE_ALL_SYSTEM_APPS_ENABLED = false; 33 public static final int DEFAULT_WIFI_PROXY_PORT = 0; 34 35 public String mTimeZone; 36 public long mLocalTime = DEFAULT_LOCAL_TIME; 37 public Locale mLocale; 38 39 public String mWifiSsid; 40 public boolean mWifiHidden = DEFAULT_WIFI_HIDDEN; 41 public String mWifiSecurityType; 42 public String mWifiPassword; 43 public String mWifiProxyHost; 44 public int mWifiProxyPort = DEFAULT_WIFI_PROXY_PORT; 45 public String mWifiProxyBypassHosts; 46 public String mWifiPacUrl; 47 48 public String mDeviceAdminPackageName; // Package name of the device admin package. 49 50 public String mDeviceAdminPackageDownloadLocation; // Url of the device admin .apk 51 public String mDeviceAdminPackageDownloadCookieHeader; // Cookie header for http request 52 public byte[] mDeviceAdminPackageChecksum = new byte[0]; // SHA-1 sum of the .apk file. 53 54 public PersistableBundle mAdminExtrasBundle; 55 56 public boolean mStartedByNfc; // True iff provisioning flow was started by Nfc bump. 57 58 public boolean mLeaveAllSystemAppsEnabled; 59 getLocaleAsString()60 public String getLocaleAsString() { 61 if (mLocale != null) { 62 return mLocale.getLanguage() + "_" + mLocale.getCountry(); 63 } else { 64 return null; 65 } 66 } 67 getDeviceAdminPackageChecksumAsString()68 public String getDeviceAdminPackageChecksumAsString() { 69 return Base64.encodeToString(mDeviceAdminPackageChecksum, 70 Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP); 71 } 72 73 @Override describeContents()74 public int describeContents() { 75 return 0; 76 } 77 78 @Override writeToParcel(Parcel out, int flags)79 public void writeToParcel(Parcel out, int flags) { 80 out.writeString(mTimeZone); 81 out.writeLong(mLocalTime); 82 out.writeSerializable(mLocale); 83 out.writeString(mWifiSsid); 84 out.writeInt(mWifiHidden ? 1 : 0); 85 out.writeString(mWifiSecurityType); 86 out.writeString(mWifiPassword); 87 out.writeString(mWifiProxyHost); 88 out.writeInt(mWifiProxyPort); 89 out.writeString(mWifiProxyBypassHosts); 90 out.writeString(mDeviceAdminPackageName); 91 out.writeString(mDeviceAdminPackageDownloadLocation); 92 out.writeString(mDeviceAdminPackageDownloadCookieHeader); 93 out.writeInt(mDeviceAdminPackageChecksum.length); 94 out.writeByteArray(mDeviceAdminPackageChecksum); 95 out.writeParcelable(mAdminExtrasBundle, 0 /* default */); 96 out.writeInt(mStartedByNfc ? 1 : 0); 97 out.writeInt(mLeaveAllSystemAppsEnabled ? 1 : 0); 98 } 99 100 public static final Parcelable.Creator<ProvisioningParams> CREATOR 101 = new Parcelable.Creator<ProvisioningParams>() { 102 @Override 103 public ProvisioningParams createFromParcel(Parcel in) { 104 ProvisioningParams params = new ProvisioningParams(); 105 params.mTimeZone = in.readString(); 106 params.mLocalTime = in.readLong(); 107 params.mLocale = (Locale) in.readSerializable(); 108 params.mWifiSsid = in.readString(); 109 params.mWifiHidden = in.readInt() == 1; 110 params.mWifiSecurityType = in.readString(); 111 params.mWifiPassword = in.readString(); 112 params.mWifiProxyHost = in.readString(); 113 params.mWifiProxyPort = in.readInt(); 114 params.mWifiProxyBypassHosts = in.readString(); 115 params.mDeviceAdminPackageName = in.readString(); 116 params.mDeviceAdminPackageDownloadLocation = in.readString(); 117 params.mDeviceAdminPackageDownloadCookieHeader = in.readString(); 118 int checksumLength = in.readInt(); 119 params.mDeviceAdminPackageChecksum = new byte[checksumLength]; 120 in.readByteArray(params.mDeviceAdminPackageChecksum); 121 params.mAdminExtrasBundle = in.readParcelable(null /* use default classloader */); 122 params.mStartedByNfc = in.readInt() == 1; 123 params.mLeaveAllSystemAppsEnabled = in.readInt() == 1; 124 return params; 125 } 126 127 @Override 128 public ProvisioningParams[] newArray(int size) { 129 return new ProvisioningParams[size]; 130 } 131 }; 132 } 133