92e590634e2d69a4a4db7ba344db39fe5b7e8b75
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / data / VpnProfile.java
1 /*
2 * Copyright (C) 2012-2017 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * HSR Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.data;
19
20
21 import java.util.UUID;
22
23 public class VpnProfile implements Cloneable
24 {
25 /* While storing this as EnumSet would be nicer this simplifies storing it in a database */
26 public static final int SPLIT_TUNNELING_BLOCK_IPV4 = 1;
27 public static final int SPLIT_TUNNELING_BLOCK_IPV6 = 2;
28
29 private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
30 private String mRemoteId, mLocalId, mExcludedSubnets, mIncludedSubnets, mSelectedApps;
31 private Integer mMTU, mPort, mSplitTunneling;
32 private SelectedAppsHandling mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
33 private VpnType mVpnType;
34 private UUID mUUID;
35 private long mId = -1;
36
37 public enum SelectedAppsHandling
38 {
39 SELECTED_APPS_DISABLE(0),
40 SELECTED_APPS_EXCLUDE(1),
41 SELECTED_APPS_ONLY(2);
42
43 private Integer mValue;
44
45 SelectedAppsHandling(int value)
46 {
47 mValue = value;
48 }
49
50 public Integer getValue()
51 {
52 return mValue;
53 }
54 }
55
56 public VpnProfile()
57 {
58 this.mUUID = UUID.randomUUID();
59 }
60
61 public long getId()
62 {
63 return mId;
64 }
65
66 public void setId(long id)
67 {
68 this.mId = id;
69 }
70
71 public void setUUID(UUID uuid)
72 {
73 this.mUUID = uuid;
74 }
75
76 public UUID getUUID()
77 {
78 return mUUID;
79 }
80
81 public String getName()
82 {
83 return mName;
84 }
85
86 public void setName(String name)
87 {
88 this.mName = name;
89 }
90
91 public String getGateway()
92 {
93 return mGateway;
94 }
95
96 public void setGateway(String gateway)
97 {
98 this.mGateway = gateway;
99 }
100
101 public VpnType getVpnType()
102 {
103 return mVpnType;
104 }
105
106 public void setVpnType(VpnType type)
107 {
108 this.mVpnType = type;
109 }
110
111 public String getUsername()
112 {
113 return mUsername;
114 }
115
116 public void setUsername(String username)
117 {
118 this.mUsername = username;
119 }
120
121 public String getPassword()
122 {
123 return mPassword;
124 }
125
126 public void setPassword(String password)
127 {
128 this.mPassword = password;
129 }
130
131 public String getCertificateAlias()
132 {
133 return mCertificate;
134 }
135
136 public void setCertificateAlias(String alias)
137 {
138 this.mCertificate = alias;
139 }
140
141 public String getUserCertificateAlias()
142 {
143 return mUserCertificate;
144 }
145
146 public void setUserCertificateAlias(String alias)
147 {
148 this.mUserCertificate = alias;
149 }
150
151 public String getLocalId()
152 {
153 return mLocalId;
154 }
155
156 public void setLocalId(String localId)
157 {
158 this.mLocalId = localId;
159 }
160
161 public String getRemoteId()
162 {
163 return mRemoteId;
164 }
165
166 public void setRemoteId(String remoteId)
167 {
168 this.mRemoteId = remoteId;
169 }
170
171 public Integer getMTU()
172 {
173 return mMTU;
174 }
175
176 public void setMTU(Integer mtu)
177 {
178 this.mMTU = mtu;
179 }
180
181 public Integer getPort()
182 {
183 return mPort;
184 }
185
186 public void setPort(Integer port)
187 {
188 this.mPort = port;
189 }
190
191 public void setExcludedSubnets(String excludedSubnets)
192 {
193 this.mExcludedSubnets = excludedSubnets;
194 }
195
196 public String getExcludedSubnets()
197 {
198 return mExcludedSubnets;
199 }
200
201 public void setIncludedSubnets(String includedSubnets)
202 {
203 this.mIncludedSubnets = includedSubnets;
204 }
205 public String getIncludedSubnets()
206 {
207 return mIncludedSubnets;
208 }
209
210 public void setSelectedApps(String selectedApps)
211 {
212 this.mSelectedApps = selectedApps;
213 }
214
215 public String getSelectedApps()
216 {
217 return mSelectedApps;
218 }
219
220 public void setSelectedAppsHandling(SelectedAppsHandling selectedAppsHandling)
221 {
222 this.mSelectedAppsHandling = selectedAppsHandling;
223 }
224
225 public void setSelectedAppsHandling(Integer value)
226 {
227 mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE;
228 for (SelectedAppsHandling handling : SelectedAppsHandling.values())
229 {
230 if (handling.mValue.equals(value))
231 {
232 mSelectedAppsHandling = handling;
233 break;
234 }
235 }
236 }
237
238 public SelectedAppsHandling getSelectedAppsHandling()
239 {
240 return mSelectedAppsHandling;
241 }
242
243 public Integer getSplitTunneling()
244 {
245 return mSplitTunneling;
246 }
247
248 public void setSplitTunneling(Integer splitTunneling)
249 {
250 this.mSplitTunneling = splitTunneling;
251 }
252
253 @Override
254 public String toString()
255 {
256 return mName;
257 }
258
259 @Override
260 public boolean equals(Object o)
261 {
262 if (o != null && o instanceof VpnProfile)
263 {
264 VpnProfile other = (VpnProfile)o;
265 if (this.mUUID != null && other.getUUID() != null)
266 {
267 return this.mUUID.equals(other.getUUID());
268 }
269 return this.mId == other.getId();
270 }
271 return false;
272 }
273
274 @Override
275 public VpnProfile clone()
276 {
277 try
278 {
279 return (VpnProfile)super.clone();
280 }
281 catch (CloneNotSupportedException e)
282 {
283 throw new AssertionError();
284 }
285 }
286 }