diff options
author | akuma <akuma> | 2019-09-08 20:40:29 +0200 |
---|---|---|
committer | akuma <akuma> | 2019-09-08 20:40:29 +0200 |
commit | 2e1c94d3f51dc6d667435b2a2bbd81a036d57bae (patch) | |
tree | 43590440908ce85ef286487bb5c44155b3de1f8e /app/src/main/java/se | |
parent | f510feb3130f7f28a5b9116c903a33e92d37ba5c (diff) |
New icon and text for Excluded Apps. Using PreferenceHelper. Test done.
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/Constants.java | 1 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java | 11 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java | 11 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java | 2 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java (renamed from app/src/main/java/se/leap/bitmaskclient/fragments/Settings_Allowed_Apps.java) | 51 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java | 19 |
6 files changed, 43 insertions, 52 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java index 42df6d1d..18338a73 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -13,6 +13,7 @@ public interface Constants { String ALWAYS_ON_SHOW_DIALOG = "DIALOG.ALWAYS_ON_SHOW_DIALOG"; String CLEARLOG = "clearlogconnect"; String LAST_USED_PROFILE = "last_used_profile"; + String EXCLUDED_APPS = "excluded_apps"; ////////////////////////////////////////////// diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index 99dfb890..a604c536 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -59,7 +59,7 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.fragments.AboutFragment; import se.leap.bitmaskclient.fragments.AlwaysOnDialog; import se.leap.bitmaskclient.fragments.LogFragment; -import se.leap.bitmaskclient.fragments.Settings_Allowed_Apps; +import se.leap.bitmaskclient.fragments.ExcludeAppsFragment; import static android.content.Context.MODE_PRIVATE; import static se.leap.bitmaskclient.BitmaskApp.getRefWatcher; @@ -78,11 +78,10 @@ import static se.leap.bitmaskclient.DrawerSettingsAdapter.LOG; import static se.leap.bitmaskclient.DrawerSettingsAdapter.SELECT_APPS; import static se.leap.bitmaskclient.DrawerSettingsAdapter.SWITCH_PROVIDER; import static se.leap.bitmaskclient.R.string.about_fragment_title; -import static se.leap.bitmaskclient.R.string.allow_apps_fragment_title; +import static se.leap.bitmaskclient.R.string.exclude_apps_fragment_title; import static se.leap.bitmaskclient.R.string.donate_title; import static se.leap.bitmaskclient.R.string.log_fragment_title; import static se.leap.bitmaskclient.R.string.switch_provider_menu_option; -import static se.leap.bitmaskclient.R.string.allow_apps_fragment_title; import static se.leap.bitmaskclient.utils.ConfigHelper.isDefaultBitmask; import static se.leap.bitmaskclient.utils.PreferenceHelper.getProviderName; import static se.leap.bitmaskclient.utils.PreferenceHelper.getSaveBattery; @@ -272,12 +271,12 @@ public class NavigationDrawerFragment extends Fragment { if (isDefaultBitmask()) { settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(switch_provider_menu_option), R.drawable.ic_switch_provider_36, SWITCH_PROVIDER)); } + settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(exclude_apps_fragment_title), R.drawable.ic_shield_remove_grey600_36dp, SELECT_APPS)); settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(log_fragment_title), R.drawable.ic_log_36, LOG)); if (ENABLE_DONATION) { settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(donate_title), R.drawable.ic_donate_36, DONATE)); } settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(about_fragment_title), R.drawable.ic_about_36, ABOUT)); - settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(allow_apps_fragment_title), R.drawable.ic_about_36, SELECT_APPS)); } private ActionBar setupActionBar() { @@ -500,8 +499,8 @@ public class NavigationDrawerFragment extends Fragment { startActivity(browserIntent); break; case SELECT_APPS: - fragment = new Settings_Allowed_Apps(); - setActionBarTitle(allow_apps_fragment_title); + fragment = new ExcludeAppsFragment(); + setActionBarTitle(exclude_apps_fragment_title); break; default: break; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 77666378..09b33845 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -32,6 +32,7 @@ import java.util.Set; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; import se.leap.bitmaskclient.BitmaskApp; +import se.leap.bitmaskclient.utils.PreferenceHelper; /** * Gateway provides objects defining gateways and their metadata. @@ -71,8 +72,14 @@ public class Gateway { System.out.println("###########" + mName + "###########"); mVpnProfile.mName = mName; - SharedPreferences allow_apps = context.getSharedPreferences("BITMASK", Context.MODE_MULTI_PROCESS); - mVpnProfile.mAllowedAppsVpn = new HashSet<String>(allow_apps.getStringSet("ALLOW_APPS", new HashSet<String>())); + Set<String> excludedAppsVpn = PreferenceHelper.getExcludedApps(context); + if (excludedAppsVpn != null) { + mVpnProfile.mAllowedAppsVpn = new HashSet<>(excludedAppsVpn); + } + else { + mVpnProfile.mAllowedAppsVpn = null; + } + } private JSONObject getGeneralConfiguration(JSONObject eip_definition) { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 8edf81ef..6bd7b4a3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -93,7 +93,7 @@ public class GatewaysManager { JSONObject gw = gatewaysDefined.getJSONObject(i); if (isOpenVpnGateway(gw)) { JSONObject secrets = secretsConfiguration(); - Gateway aux = new Gateway(eipDefinition, secrets, gw, context); + Gateway aux = new Gateway(eipDefinition, secrets, gw, this.context); if (!gateways.contains(aux)) { addGateway(aux); } diff --git a/app/src/main/java/se/leap/bitmaskclient/fragments/Settings_Allowed_Apps.java b/app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java index a563978a..066c9636 100644 --- a/app/src/main/java/se/leap/bitmaskclient/fragments/Settings_Allowed_Apps.java +++ b/app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java @@ -28,7 +28,6 @@ import android.widget.Filterable; import android.widget.ImageView; import android.widget.ListView; import android.widget.SearchView; -import android.widget.Switch; import android.widget.TextView; import java.util.Collections; @@ -41,14 +40,14 @@ import java.util.Vector; import de.blinkt.openvpn.VpnProfile; import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.utils.PreferenceHelper; /** * Created by arne on 16.11.14. */ -public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnItemClickListener, CompoundButton.OnCheckedChangeListener, View.OnClickListener { +public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemClickListener, CompoundButton.OnCheckedChangeListener, View.OnClickListener { private ListView mListView; private VpnProfile mProfile; - private TextView mDefaultAllowTextView; private PackageAdapter mListAdapter; private SharedPreferences allow_apps; @@ -85,8 +84,6 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte holder.rootView = convertView; holder.appName = (TextView) convertView.findViewById(R.id.app_name); holder.appIcon = (ImageView) convertView.findViewById(R.id.app_icon); - //holder.appSize = (TextView) convertView.findViewById(R.id.app_size); - //holder.disabled = (TextView) convertView.findViewById(R.id.app_disabled); holder.checkBox = (CompoundButton) convertView.findViewById(R.id.app_selected); convertView.setTag(holder); @@ -111,13 +108,11 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte } else { Log.d("openvpn", "removing from allowed apps" + packageName); - //Log.d("eneko", this.getContext().getSharedPreferences("BITMASK", Context.MODE_MULTI_PROCESS).getString("ALLOW_APPS", "")); apps.remove(packageName); } - allow_apps_editor.clear(); - allow_apps_editor.putStringSet("ALLOW_APPS", apps); - allow_apps_editor.apply(); + + PreferenceHelper.setExcludedApps(this.getContext(), apps); } @@ -235,7 +230,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte @Override public View getView(int position, View convertView, ViewGroup parent) { AppViewHolder viewHolder = AppViewHolder.createOrRecycle(mInflater, convertView, parent); - convertView = viewHolder.rootView; + viewHolder.mInfo = mFilteredData.get(position); final ApplicationInfo mInfo = mFilteredData.get(position); @@ -247,11 +242,9 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte viewHolder.appName.setText(appName); viewHolder.appIcon.setImageDrawable(mInfo.loadIcon(mPm)); viewHolder.checkBox.setTag(mInfo.packageName); - viewHolder.checkBox.setOnCheckedChangeListener(Settings_Allowed_Apps.this); + viewHolder.checkBox.setOnCheckedChangeListener(ExcludeAppsFragment.this); viewHolder.checkBox.setChecked(apps.contains(mInfo.packageName)); - - // viewHolder.checkBox.setChecked(mProfile.mAllowedAppsVpn.contains(mInfo.packageName)); return viewHolder.rootView; } @@ -264,20 +257,14 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte @Override public void onResume() { super.onResume(); -// changeDisallowText(mProfile.mAllowedAppsVpnAreDisallowed); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - allow_apps = this.getContext().getSharedPreferences("BITMASK", Context.MODE_MULTI_PROCESS); - allow_apps_editor = allow_apps.edit(); - apps = allow_apps.getStringSet("ALLOW_APPS", new HashSet<String>()); + apps = PreferenceHelper.getExcludedApps(this.getContext()); -// /String profileUuid = getArguments().getString(getActivity().getPackageName() + ".profileUUID"); -// mProfile = EipSetupObserver.getProfile(); -// getActivity().setTitle(getString(R.string.edit_profile_title, mProfile.getName())); setHasOptionsMenu(true); } @@ -321,23 +308,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.allowed_vpn_apps, container, false); -// mDefaultAllowTextView = (TextView) v.findViewById(R.id.default_allow_text); - - -// Switch vpnOnDefaultSwitch = (Switch) v.findViewById(R.id.default_allow); -// -// vpnOnDefaultSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { -// @Override -// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { -// -// changeDisallowText(isChecked); -// mProfile.mAllowedAppsVpnAreDisallowed = isChecked; -// } -// }); - -// vpnOnDefaultSwitch.setChecked(mProfile.mAllowedAppsVpnAreDisallowed); - - mListView = (ListView) v.findViewById(android.R.id.list); + mListView = v.findViewById(android.R.id.list); mListAdapter = new PackageAdapter(getActivity(), mProfile); mListView.setAdapter(mListAdapter); @@ -355,10 +326,4 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte return v; } - private void changeDisallowText(boolean selectedAreDisallowed) { - if (selectedAreDisallowed) - mDefaultAllowTextView.setText(R.string.vpn_disallow_radio); - else - mDefaultAllowTextView.setText(R.string.vpn_allow_radio); - } } diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java index f5cf590b..9eb4c972 100644 --- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java @@ -12,9 +12,11 @@ import org.json.JSONObject; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import de.blinkt.openvpn.VpnProfile; import se.leap.bitmaskclient.Provider; @@ -29,6 +31,7 @@ import static se.leap.bitmaskclient.Constants.PROVIDER_EIP_DEFINITION; import static se.leap.bitmaskclient.Constants.PROVIDER_PRIVATE_KEY; import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; +import static se.leap.bitmaskclient.Constants.EXCLUDED_APPS; /** * Created by cyberta on 18.03.18. @@ -256,6 +259,21 @@ public class PreferenceHelper { return result; } + public static void setExcludedApps(Context context, Set<String> apps) { + SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + SharedPreferences.Editor prefsedit = prefs.edit(); + prefsedit.putStringSet(EXCLUDED_APPS, apps); + prefsedit.apply(); + } + + public static Set<String> getExcludedApps(Context context) { + if (context == null) { + return null; + } + SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + return preferences.getStringSet(EXCLUDED_APPS, new HashSet<>()); + } + public static String getString(Context context, String key, String defValue) { SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); return preferences.getString(key, defValue); @@ -266,4 +284,5 @@ public class PreferenceHelper { preferences.edit().putString(key, value).apply(); } + } |