summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/ProfileManager.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-04-27 23:24:49 +0200
committerArne Schwabe <arne@rfc2549.org>2012-04-27 23:24:49 +0200
commit031186e74c9f174d05a09c4059def7bcbc558ac6 (patch)
tree8506351e5a3e9904c70c881b1d13b2a1d1030383 /src/de/blinkt/openvpn/ProfileManager.java
parent817812066576fb1e2fd627927ad5cfc7bf7c79d5 (diff)
it is not getIntent() nor savedState nor other fancy stuff, getArgument() is what I want
Diffstat (limited to 'src/de/blinkt/openvpn/ProfileManager.java')
-rw-r--r--src/de/blinkt/openvpn/ProfileManager.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/de/blinkt/openvpn/ProfileManager.java b/src/de/blinkt/openvpn/ProfileManager.java
new file mode 100644
index 00000000..078403e1
--- /dev/null
+++ b/src/de/blinkt/openvpn/ProfileManager.java
@@ -0,0 +1,96 @@
+package de.blinkt.openvpn;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.StreamCorruptedException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+
+public class ProfileManager {
+ private static final String PREFS_NAME = "VPNList";
+
+
+
+ private static ProfileManager instance;
+ private HashMap<String,VpnProfile> profiles=new HashMap<String, VpnProfile>();
+
+ public static VpnProfile get(String key) {
+ checkInstance();
+ return instance.profiles.get(key);
+
+ }
+
+ private ProfileManager() { }
+
+ private static void checkInstance() {
+ if(instance == null)
+ instance = new ProfileManager();
+ }
+
+ public static ProfileManager getInstance() {
+ checkInstance();
+ return instance;
+ }
+
+
+
+ public Collection<VpnProfile> getProfiles() {
+ return profiles.values();
+ }
+
+ public VpnProfile getProfileByName(String name) {
+ for (VpnProfile vpnp : profiles.values()) {
+ if(vpnp.getName().equals(name)) {
+ return vpnp;
+ }
+ }
+ return null;
+ }
+
+ public void saveProfileList(Activity activity) {
+ SharedPreferences sharedprefs = activity.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE);
+ Editor editor = sharedprefs.edit();
+ editor.putStringSet("vpnlist", profiles.keySet());
+ editor.commit();
+ }
+
+ public void addProfile(VpnProfile profile) {
+ profiles.put(profile.getUUID().toString(),profile);
+
+ }
+ void loadVPNList(Context context) {
+ profiles = new HashMap<String, VpnProfile>();
+ SharedPreferences settings =context.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE);
+ Set<String> vlist = settings.getStringSet("vpnlist", null);
+ if(vlist==null){
+ vlist = new HashSet<String>();
+ }
+
+ for (String vpnentry : vlist) {
+ try {
+ ObjectInputStream vpnfile = new ObjectInputStream(context.openFileInput(vpnentry + ".vp"));
+ VpnProfile vp = ((VpnProfile) vpnfile.readObject());
+
+ profiles.put(vp.getUUID().toString(), vp);
+
+ } catch (StreamCorruptedException e) {
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}