Home | History | Annotate | Download | only in managedprovisioning
      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.content.Context;
     20 import android.accounts.Account;
     21 import android.content.ComponentName;
     22 import android.os.Parcel;
     23 import android.os.Parcelable;
     24 import android.os.PersistableBundle;
     25 
     26 import java.util.Locale;
     27 
     28 /**
     29  * Provisioning Parameters for Device owner and Profile owner Provisioning.
     30  */
     31 public class ProvisioningParams implements Parcelable {
     32     public static final long DEFAULT_LOCAL_TIME = -1;
     33     public static final boolean DEFAULT_WIFI_HIDDEN = false;
     34     public static final boolean DEFAULT_LEAVE_ALL_SYSTEM_APPS_ENABLED = false;
     35     public static final int DEFAULT_WIFI_PROXY_PORT = 0;
     36     public static final boolean DEFAULT_EXTRA_PROVISIONING_SKIP_ENCRYPTION = false;
     37     // Always download packages if no minimum version given.
     38     public static final int DEFAULT_MINIMUM_VERSION = Integer.MAX_VALUE;
     39 
     40     public String timeZone;
     41     public long localTime = DEFAULT_LOCAL_TIME;
     42     public Locale locale;
     43 
     44     // Intent extra used internally for passing data between activities and service.
     45     /* package */ static final String EXTRA_PROVISIONING_PARAMS = "provisioningParams";
     46 
     47     public static class WifiInfo {
     48         public String ssid;
     49         public boolean hidden = DEFAULT_WIFI_HIDDEN;
     50         public String securityType;
     51         public String password;
     52         public String proxyHost;
     53         public int proxyPort = DEFAULT_WIFI_PROXY_PORT;
     54         public String proxyBypassHosts;
     55         public String pacUrl;
     56 
     57         public void writeToParcel(Parcel out) {
     58             out.writeString(ssid);
     59             out.writeInt(hidden ? 1 : 0);
     60             out.writeString(securityType);
     61             out.writeString(password);
     62             out.writeString(proxyHost);
     63             out.writeInt(proxyPort);
     64             out.writeString(proxyBypassHosts);
     65             out.writeString(pacUrl);
     66         }
     67 
     68         public void readFromParcel(Parcel in) {
     69             ssid = in.readString();
     70             hidden = in.readInt() == 1;
     71             securityType = in.readString();
     72             password = in.readString();
     73             proxyHost = in.readString();
     74             proxyPort = in.readInt();
     75             proxyBypassHosts = in.readString();
     76             pacUrl = in.readString();
     77         }
     78     }
     79     public WifiInfo wifiInfo = new WifiInfo();
     80 
     81     // At least one one of deviceAdminPackageName and deviceAdminComponentName should be non-null
     82     public String deviceAdminPackageName; // Package name of the device admin package.
     83     public ComponentName deviceAdminComponentName;
     84     public ComponentName deviceInitializerComponentName;
     85     public Account accountToMigrate;
     86 
     87     private ComponentName inferedDeviceAdminComponentName;
     88 
     89     public static class PackageDownloadInfo {
     90         // Url where the package (.apk) can be downloaded from
     91         public String location;
     92         // Cookie header for http request
     93         public String cookieHeader;
     94         // One of the following two checksums should be non empty.
     95         // SHA-256 or SHA-1 hash of the .apk file, or empty array if not used.
     96         public byte[] packageChecksum = new byte[0];
     97         // SHA-256 hash of the signature in the .apk file, or empty array if not used.
     98         public byte[] signatureChecksum = new byte[0];
     99         public int minVersion;
    100         // If this is false, packageChecksum can only be SHA-256 hash, otherwise SHA-1 is also
    101         // supported.
    102         public boolean packageChecksumSupportsSha1;
    103 
    104         public void writeToParcel(Parcel out) {
    105             out.writeInt(minVersion);
    106             out.writeString(location);
    107             out.writeString(cookieHeader);
    108             out.writeByteArray(packageChecksum);
    109             out.writeByteArray(signatureChecksum);
    110             out.writeInt(packageChecksumSupportsSha1 ? 1 : 0);
    111         }
    112 
    113         public void readFromParcel(Parcel in) {
    114             minVersion = in.readInt();
    115             location = in.readString();
    116             cookieHeader = in.readString();
    117             packageChecksum = in.createByteArray();
    118             signatureChecksum = in.createByteArray();
    119             packageChecksumSupportsSha1 = in.readInt() == 1;
    120         }
    121     }
    122     public PackageDownloadInfo deviceAdminDownloadInfo = new PackageDownloadInfo();
    123     public PackageDownloadInfo deviceInitializerDownloadInfo  = new PackageDownloadInfo();
    124 
    125     public PersistableBundle adminExtrasBundle;
    126 
    127     public boolean startedByNfc; // True iff provisioning flow was started by Nfc bump.
    128 
    129     public boolean leaveAllSystemAppsEnabled;
    130     public boolean skipEncryption;
    131 
    132     public String inferDeviceAdminPackageName() {
    133         if (deviceAdminComponentName != null) {
    134             return deviceAdminComponentName.getPackageName();
    135         }
    136         return deviceAdminPackageName;
    137     }
    138 
    139     public String getDeviceInitializerPackageName() {
    140         if (deviceInitializerComponentName != null) {
    141             return deviceInitializerComponentName.getPackageName();
    142         }
    143         return null;
    144     }
    145 
    146     // This should not be called if the app has not been installed yet.
    147     ComponentName inferDeviceAdminComponentName(Context c)
    148             throws Utils.IllegalProvisioningArgumentException {
    149         if (inferedDeviceAdminComponentName == null) {
    150             inferedDeviceAdminComponentName = Utils.findDeviceAdmin(
    151                     deviceAdminPackageName, deviceAdminComponentName, c);
    152         }
    153         return inferedDeviceAdminComponentName;
    154     }
    155 
    156     @Override
    157     public int describeContents() {
    158         return 0;
    159     }
    160 
    161     @Override
    162     public void writeToParcel(Parcel out, int flags) {
    163         out.writeString(timeZone);
    164         out.writeLong(localTime);
    165         out.writeSerializable(locale);
    166         wifiInfo.writeToParcel(out);
    167         out.writeString(deviceAdminPackageName);
    168         out.writeParcelable(deviceAdminComponentName, 0 /* default */);
    169         deviceAdminDownloadInfo.writeToParcel(out);
    170         out.writeParcelable(deviceInitializerComponentName, 0 /* default */);
    171         deviceInitializerDownloadInfo.writeToParcel(out);
    172         out.writeParcelable(adminExtrasBundle, 0 /* default */);
    173         out.writeInt(startedByNfc ? 1 : 0);
    174         out.writeInt(leaveAllSystemAppsEnabled ? 1 : 0);
    175         out.writeInt(skipEncryption ? 1 : 0);
    176         out.writeParcelable(accountToMigrate, 0 /* default */);
    177     }
    178 
    179     public static final Parcelable.Creator<ProvisioningParams> CREATOR
    180         = new Parcelable.Creator<ProvisioningParams>() {
    181         @Override
    182         public ProvisioningParams createFromParcel(Parcel in) {
    183             ProvisioningParams params = new ProvisioningParams();
    184             params.timeZone = in.readString();
    185             params.localTime = in.readLong();
    186             params.locale = (Locale) in.readSerializable();
    187             params.wifiInfo.readFromParcel(in);
    188             params.deviceAdminPackageName = in.readString();
    189             params.deviceAdminComponentName = (ComponentName)
    190                     in.readParcelable(null /* use default classloader */);
    191             params.deviceAdminDownloadInfo.readFromParcel(in);
    192             params.deviceInitializerComponentName = (ComponentName)
    193                     in.readParcelable(null /* use default classloader */);
    194             params.deviceInitializerDownloadInfo.readFromParcel(in);
    195             params.adminExtrasBundle = in.readParcelable(null /* use default classloader */);
    196             params.startedByNfc = in.readInt() == 1;
    197             params.leaveAllSystemAppsEnabled = in.readInt() == 1;
    198             params.skipEncryption = in.readInt() == 1;
    199             params.accountToMigrate =
    200                     (Account) in.readParcelable(null /* use default classloader */);
    201             return params;
    202         }
    203 
    204         @Override
    205         public ProvisioningParams[] newArray(int size) {
    206             return new ProvisioningParams[size];
    207         }
    208     };
    209 }
    210