summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-12-02 22:26:31 +0100
committerArne Schwabe <arne@rfc2549.org>2014-12-02 22:26:31 +0100
commitf1f81cb19b57310ce433badf75719891243c3071 (patch)
treed34f208e97c65b26d99efcef25bc7cb55fd77012 /main
parentbabbf3105ada7a67477064a0b3aa7435432b0da5 (diff)
really fix per app vpn settings (hopefully) this time
--HG-- extra : rebase_source : 328abb8724c5582c5c9de7ed55e38a937b636ea7
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java52
1 files changed, 29 insertions, 23 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java
index 309f5447..d3277a85 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java
@@ -12,6 +12,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -34,7 +35,7 @@ import de.blinkt.openvpn.core.ProfileManager;
/**
* Created by arne on 16.11.14.
*/
-public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnItemClickListener {
+public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnItemClickListener, CompoundButton.OnCheckedChangeListener {
private ListView mListView;
private VpnProfile mProfile;
private TextView mDefaultAllowTextView;
@@ -69,16 +70,31 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
//holder.disabled = (TextView) convertView.findViewById(R.id.app_disabled);
holder.checkBox = (CompoundButton) convertView.findViewById(R.id.app_selected);
convertView.setTag(holder);
+
+
return holder;
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
- return (AppViewHolder)convertView.getTag();
+ return (AppViewHolder) convertView.getTag();
}
}
}
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ String packageName = (String) buttonView.getTag();
+ if (isChecked) {
+ Log.d("openvpn", "adding to allowed apps" + packageName);
+ mProfile.mAllowedAppsVpn.add(packageName);
+ } else {
+ Log.d("openvpn", "removing from allowed apps" + packageName);
+ mProfile.mAllowedAppsVpn.remove(packageName);
+ }
+
+ }
+
class PackageAdapter extends BaseAdapter {
private final List<ApplicationInfo> mPackages;
@@ -93,9 +109,9 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
// Remove apps not using Internet
- int androidSystemUid=0;
+ int androidSystemUid = 0;
ApplicationInfo system = null;
- Vector<ApplicationInfo> apps= new Vector<ApplicationInfo>();
+ Vector<ApplicationInfo> apps = new Vector<ApplicationInfo>();
try {
system = mPm.getApplicationInfo("android", PackageManager.GET_META_DATA);
@@ -105,7 +121,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
}
- for (ApplicationInfo app:installedPackages) {
+ for (ApplicationInfo app : installedPackages) {
if (mPm.checkPermission(Manifest.permission.INTERNET, app.packageName) == PackageManager.PERMISSION_GRANTED &&
app.uid != androidSystemUid) {
@@ -114,13 +130,10 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
}
}
-
-
-
Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(mPm));
- mPackages=apps;
-
+ mPackages = apps;
}
+
@Override
public int getCount() {
return mPackages.size();
@@ -144,24 +157,17 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
final ApplicationInfo mInfo = mPackages.get(position);
- CharSequence appName = mInfo.loadLabel(mPm);
+ CharSequence appName = mInfo.loadLabel(mPm);
if (TextUtils.isEmpty(appName))
appName = mInfo.packageName;
viewHolder.appName.setText(appName);
viewHolder.appIcon.setImageDrawable(mInfo.loadIcon(mPm));
+ viewHolder.checkBox.setTag(mInfo.packageName);
+ viewHolder.checkBox.setOnCheckedChangeListener(Settings_Allowed_Apps.this);
viewHolder.checkBox.setChecked(mProfile.mAllowedAppsVpn.contains(mInfo.packageName));
- viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked)
- mProfile.mAllowedAppsVpn.remove(mInfo.packageName);
- else
- mProfile.mAllowedAppsVpn.add(mInfo.packageName);
- }
- });
return viewHolder.rootView;
}
}
@@ -176,7 +182,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
super.onCreate(savedInstanceState);
String profileUuid = getArguments().getString(getActivity().getPackageName() + ".profileUUID");
- mProfile= ProfileManager.get(getActivity(), profileUuid);
+ mProfile = ProfileManager.get(getActivity(), profileUuid);
getActivity().setTitle(getString(R.string.edit_profile_title, mProfile.getName()));
}
@@ -194,7 +200,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
changeDisallowText(isChecked);
- mProfile.mAllowedAppsVpnAreDisallowed=isChecked;
+ mProfile.mAllowedAppsVpnAreDisallowed = isChecked;
}
});
@@ -211,7 +217,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte
}
private void changeDisallowText(boolean selectedAreDisallowed) {
- if(selectedAreDisallowed)
+ if (selectedAreDisallowed)
mDefaultAllowTextView.setText(R.string.vpn_disallow_radio);
else
mDefaultAllowTextView.setText(R.string.vpn_allow_radio);