diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-04-06 19:46:07 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-04-06 19:46:07 +0200 |
commit | bde3a3f780cc668619076df96147b76be1c4ab64 (patch) | |
tree | 0c47b7894df388844ef3b9a806711b704c227b3d /src/de/blinkt/openvpn/api/ExternalAppDatabase.java | |
parent | ad2256b6fe9c211d06321d99590cb457427d8e7d (diff) |
Add external API with security.
Diffstat (limited to 'src/de/blinkt/openvpn/api/ExternalAppDatabase.java')
-rw-r--r-- | src/de/blinkt/openvpn/api/ExternalAppDatabase.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/de/blinkt/openvpn/api/ExternalAppDatabase.java b/src/de/blinkt/openvpn/api/ExternalAppDatabase.java new file mode 100644 index 00000000..ca348152 --- /dev/null +++ b/src/de/blinkt/openvpn/api/ExternalAppDatabase.java @@ -0,0 +1,58 @@ +package de.blinkt.openvpn.api; + +import java.util.HashSet; +import java.util.Set; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.preference.PreferenceManager; + +public class ExternalAppDatabase { + + Context mContext; + + public ExternalAppDatabase(Context c) { + mContext =c; + } + + private final String PREFERENCES_KEY = "PREFERENCES_KEY"; + + boolean isAllowed(String packagename) { + Set<String> allowedapps = getExtAppList(); + + return allowedapps.contains(packagename); + + } + + Set<String> getExtAppList() { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); + Set<String> allowedapps = prefs.getStringSet(PREFERENCES_KEY, new HashSet<String>()); + return allowedapps; + } + + void addApp(String packagename) + { + Set<String> allowedapps = getExtAppList(); + allowedapps.add(packagename); + saveExtAppList(allowedapps); + } + + private void saveExtAppList( Set<String> allowedapps) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); + Editor prefedit = prefs.edit(); + prefedit.putStringSet(PREFERENCES_KEY, allowedapps); + prefedit.apply(); + } + + void clearAllApiApps() { + saveExtAppList(new HashSet<String>()); + } + + public void removeApp(String packagename) { + Set<String> allowedapps = getExtAppList(); + allowedapps.remove(packagename); + saveExtAppList(allowedapps); + } + +} |