android: Spinner added to select the VPN type
[strongswan.git] / src / frontends / android / src / org / strongswan / android / data / VpnType.java
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.data;
17
18 public enum VpnType
19 {
20 /* the order here must match the items in R.array.vpn_types */
21 IKEV2_EAP("ikev2-eap", true, false),
22 IKEV2_CERT("ikev2-cert", false, true);
23
24 private String mIdentifier;
25 private boolean mCertificate;
26 private boolean mUsernamePassword;
27
28 /**
29 * Enum which provides additional information about the supported VPN types.
30 *
31 * @param id identifier used to store and transmit this specific type
32 * @param userpass true if username and password are required
33 * @param certificate true if a client certificate is required
34 */
35 VpnType(String id, boolean userpass, boolean certificate)
36 {
37 mIdentifier = id;
38 mUsernamePassword = userpass;
39 mCertificate = certificate;
40 }
41
42 /**
43 * The identifier used to store this value in the database
44 * @return identifier
45 */
46 public String getIdentifier()
47 {
48 return mIdentifier;
49 }
50
51 /**
52 * Whether username and password are required for this type of VPN.
53 *
54 * @return true if username and password are required
55 */
56 public boolean getRequiresUsernamePassword()
57 {
58 return mUsernamePassword;
59 }
60
61 /**
62 * Whether a certificate is required for this type of VPN.
63 *
64 * @return true if a certificate is required
65 */
66 public boolean getRequiresCertificate()
67 {
68 return mCertificate;
69 }
70
71 /**
72 * Get the enum entry with the given identifier.
73 *
74 * @param identifier get the enum entry with this identifier
75 * @return the enum entry, or the default if not found
76 */
77 public static VpnType fromIdentifier(String identifier)
78 {
79 for (VpnType type : VpnType.values())
80 {
81 if (identifier.equals(type.mIdentifier))
82 {
83 return type;
84 }
85 }
86 return VpnType.IKEV2_EAP;
87 }
88 }