• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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. */
setName(String name)42     public void setName(String name) {
43         mName = name;
44     }
45 
getName()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      */
setId(String id)54     public void setId(String id) {
55         mId = id;
56     }
57 
getId()58     public String getId() {
59         return mId;
60     }
61 
62     /**
63      * Sets the name of the VPN server. Used for DNS lookup.
64      */
setServerName(String name)65     public void setServerName(String name) {
66         mServerName = name;
67     }
68 
getServerName()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      */
setDomainSuffices(String entries)78     public void setDomainSuffices(String entries) {
79         mDomainSuffices = entries;
80     }
81 
getDomainSuffices()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      */
setRouteList(String entries)92     public void setRouteList(String entries) {
93         mRouteList = entries;
94     }
95 
getRouteList()96     public String getRouteList() {
97         return mRouteList;
98     }
99 
setSavedUsername(String name)100     public void setSavedUsername(String name) {
101         mSavedUsername = name;
102     }
103 
getSavedUsername()104     public String getSavedUsername() {
105         return mSavedUsername;
106     }
107 
setState(VpnState state)108     public void setState(VpnState state) {
109         mState = state;
110     }
111 
getState()112     public VpnState getState() {
113         return ((mState == null) ? VpnState.IDLE : mState);
114     }
115 
isIdle()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      */
isCustomized()124     public boolean isCustomized() {
125         return mIsCustomized;
126     }
127 
128     /**
129      * Returns the VPN type of the profile.
130      */
getType()131     public abstract VpnType getType();
132 
setCustomized(boolean customized)133     void setCustomized(boolean customized) {
134         mIsCustomized = customized;
135     }
136 
readFromParcel(Parcel in)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 
writeToParcel(Parcel parcel, int flags)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 
describeContents()174     public int describeContents() {
175         return 0;
176     }
177 }
178