summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/fragments/GeneralSettings.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-04-07 14:05:05 +0200
committerArne Schwabe <arne@rfc2549.org>2013-04-07 14:05:05 +0200
commit195b0a10d96ad358d956381d8a0e423a8dd913c7 (patch)
tree5f62da8410bc08b50e8784ff94231cccbfcb8fb1 /src/de/blinkt/openvpn/fragments/GeneralSettings.java
parent3b68ac89cd679f134681204e0d1bb40d6dbf7879 (diff)
Allow clearing of external apps
Diffstat (limited to 'src/de/blinkt/openvpn/fragments/GeneralSettings.java')
-rw-r--r--src/de/blinkt/openvpn/fragments/GeneralSettings.java110
1 files changed, 93 insertions, 17 deletions
diff --git a/src/de/blinkt/openvpn/fragments/GeneralSettings.java b/src/de/blinkt/openvpn/fragments/GeneralSettings.java
index 4ac0a8ac..bf391d29 100644
--- a/src/de/blinkt/openvpn/fragments/GeneralSettings.java
+++ b/src/de/blinkt/openvpn/fragments/GeneralSettings.java
@@ -1,31 +1,107 @@
package de.blinkt.openvpn.fragments;
import java.io.File;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import de.blinkt.openvpn.R;
+import de.blinkt.openvpn.api.ExternalAppDatabase;
-public class GeneralSettings extends PreferenceFragment {
+public class GeneralSettings extends PreferenceFragment implements OnPreferenceClickListener, OnClickListener {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
+ private ExternalAppDatabase mExtapp;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+
+ // Load the preferences from an XML resource
+ addPreferencesFromResource(R.xml.general_settings);
+
+ Preference loadtun = findPreference("loadTunModule");
+ if(!isTunModuleAvailable())
+ loadtun.setEnabled(false);
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.general_settings);
- Preference loadtun = findPreference("loadTunModule");
- if(!isTunModuleAvailable())
- loadtun.setEnabled(false);
+ mExtapp = new ExternalAppDatabase(getActivity());
+ Preference clearapi = findPreference("clearapi");
+ clearapi.setOnPreferenceClickListener(this);
+
+ setClearApiSummary();
+ }
+
+ private void setClearApiSummary() {
+ Preference clearapi = findPreference("clearapi");
+
+ if(mExtapp.getExtAppList().isEmpty()) {
+ clearapi.setEnabled(false);
+ clearapi.setSummary(R.string.no_external_app_allowed);
+ } else {
+ clearapi.setEnabled(true);
+ clearapi.setSummary(getString(R.string.allowed_apps,getExtAppList(", ")));
}
+ }
+
+ private String getExtAppList(String delim) {
+ ApplicationInfo app;
+ PackageManager pm = getActivity().getPackageManager();
+
+ String applist=null;
+ for (String packagename : mExtapp.getExtAppList()) {
+ try {
+ app = pm.getApplicationInfo(packagename, 0);
+ if (applist==null)
+ applist = "";
+ else
+ applist += delim;
+ applist+=app.loadLabel(pm);
- private boolean isTunModuleAvailable() {
- // Check if the tun module exists on the file system
- if(new File("/system/lib/modules/tun.ko").length() > 10)
- return true;
- return false;
+ } catch (NameNotFoundException e) {
+ // App not found. Remove it from the list
+ mExtapp.removeApp(packagename);
+ }
}
-
- } \ No newline at end of file
+ return applist;
+ }
+
+ private boolean isTunModuleAvailable() {
+ // Check if the tun module exists on the file system
+ if(new File("/system/lib/modules/tun.ko").length() > 10)
+ return true;
+ return false;
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if(preference.getKey().equals("clearapi")){
+ Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setPositiveButton(R.string.clear, this);
+ builder.setNegativeButton(android.R.string.cancel, null);
+ builder.setMessage(getString(R.string.clearappsdialog,getExtAppList("\n")));
+ builder.show();
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if( which == Dialog.BUTTON_POSITIVE){
+ mExtapp.clearAllApiApps();
+ setClearApiSummary();
+ }
+ }
+
+
+
+} \ No newline at end of file