1 /* 2 * Copyright (C) 2009, 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 android.net.vpn; 18 19 import android.content.Context; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import java.io.IOException; 24 import java.io.Serializable; 25 26 /** 27 * A VPN profile. 28 * {@hide} 29 */ 30 public abstract class VpnProfile implements Parcelable, Serializable { 31 private static final long serialVersionUID = 1L; 32 private String mName; // unique display name 33 private String mId; // unique identifier 34 private String mServerName; // VPN server name 35 private String mDomainSuffices; // space separated list 36 private String mRouteList; // space separated list 37 private String mSavedUsername; 38 private boolean mIsCustomized; 39 private transient VpnState mState = VpnState.IDLE; 40 41 /** Sets a user-friendly name for this profile. */ 42 public void setName(String name) { 43 mName = name; 44 } 45 46 public String getName() { 47 return mName; 48 } 49 50 /** 51 * Sets an ID for this profile. The caller should make sure the 52 * uniqueness of the ID. 53 */ 54 public void setId(String id) { 55 mId = id; 56 } 57 58 public String getId() { 59 return mId; 60 } 61 62 /** 63 * Sets the name of the VPN server. Used for DNS lookup. 64 */ 65 public void setServerName(String name) { 66 mServerName = name; 67 } 68 69 public String getServerName() { 70 return mServerName; 71 } 72 73 /** 74 * Sets the domain suffices for DNS resolution. 75 * 76 * @param entries a comma-separated list of domain suffices 77 */ 78 public void setDomainSuffices(String entries) { 79 mDomainSuffices = entries; 80 } 81 82 public String getDomainSuffices() { 83 return mDomainSuffices; 84 } 85 86 /** 87 * Sets the routing info for this VPN connection. 88 * 89 * @param entries a comma-separated list of routes; each entry is in the 90 * format of "(network address)/(network mask)" 91 */ 92 public void setRouteList(String entries) { 93 mRouteList = entries; 94 } 95 96 public String getRouteList() { 97 return mRouteList; 98 } 99 100 public void setSavedUsername(String name) { 101 mSavedUsername = name; 102 } 103 104 public String getSavedUsername() { 105 return mSavedUsername; 106 } 107 108 public void setState(VpnState state) { 109 mState = state; 110 } 111 112 public VpnState getState() { 113 return ((mState == null) ? VpnState.IDLE : mState); 114 } 115 116 public boolean isIdle() { 117 return (mState == VpnState.IDLE); 118 } 119 120 /** 121 * Returns whether this profile is custom made (as opposed to being 122 * created by provided user interface). 123 */ 124 public boolean isCustomized() { 125 return mIsCustomized; 126 } 127 128 /** 129 * Returns the VPN type of the profile. 130 */ 131 public abstract VpnType getType(); 132 133 void setCustomized(boolean customized) { 134 mIsCustomized = customized; 135 } 136 137 protected void readFromParcel(Parcel in) { 138 mName = in.readString(); 139 mId = in.readString(); 140 mServerName = in.readString(); 141 mDomainSuffices = in.readString(); 142 mRouteList = in.readString(); 143 mSavedUsername = in.readString(); 144 } 145 146 public static final Parcelable.Creator<VpnProfile> CREATOR = 147 new Parcelable.Creator<VpnProfile>() { 148 public VpnProfile createFromParcel(Parcel in) { 149 VpnType type = Enum.valueOf(VpnType.class, in.readString()); 150 boolean customized = in.readInt() > 0; 151 VpnProfile p = new VpnManager(null).createVpnProfile(type, 152 customized); 153 if (p == null) return null; 154 p.readFromParcel(in); 155 return p; 156 } 157 158 public VpnProfile[] newArray(int size) { 159 return new VpnProfile[size]; 160 } 161 }; 162 163 public void writeToParcel(Parcel parcel, int flags) { 164 parcel.writeString(getType().toString()); 165 parcel.writeInt(mIsCustomized ? 1 : 0); 166 parcel.writeString(mName); 167 parcel.writeString(mId); 168 parcel.writeString(mServerName); 169 parcel.writeString(mDomainSuffices); 170 parcel.writeString(mRouteList); 171 parcel.writeString(mSavedUsername); 172 } 173 174 public int describeContents() { 175 return 0; 176 } 177 } 178