From f1f81cb19b57310ce433badf75719891243c3071 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Tue, 2 Dec 2014 22:26:31 +0100 Subject: really fix per app vpn settings (hopefully) this time --HG-- extra : rebase_source : 328abb8724c5582c5c9de7ed55e38a937b636ea7 --- .../openvpn/fragments/Settings_Allowed_Apps.java | 52 ++++++++++++---------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'main/src') 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 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 apps= new Vector(); + Vector apps = new Vector(); 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); -- cgit v1.2.3