Commit 2e1c94d3 authored by akuma's avatar akuma
Browse files

New icon and text for Excluded Apps. Using PreferenceHelper. Test done.

parent f510feb3
Pipeline #26880 failed with stages
......@@ -119,7 +119,7 @@ public class TestGatewaysManager extends InstrumentationTestCase {
eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));
JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE));
JSONObject gateway = new JSONObject(assets.toString(TestConstants.GATEWAY_FILE));
this.gateway = new Gateway(eip_definition, secrets, gateway);
this.gateway = new Gateway(eip_definition, secrets, gateway, context);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -137,7 +137,7 @@ public class TestGatewaysManager extends InstrumentationTestCase {
capabilitiesJson.put("protocols", protocolJsonArray);
gatewayJson.put("protocols", protocolJsonArray);
}
this.gateway = new Gateway(eip_definition, secrets, gateways.getJSONObject(0));
this.gateway = new Gateway(eip_definition, secrets, gateways.getJSONObject(0), context);
} catch (JSONException e) {
e.printStackTrace();
assertFalse(true);
......@@ -153,7 +153,7 @@ public class TestGatewaysManager extends InstrumentationTestCase {
eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE));
JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE).replace("6u6", "7u7"));
JSONObject gateway = new JSONObject(assets.toString(TestConstants.GATEWAY_FILE));
this.gateway = new Gateway(eip_definition, secrets, gateway);
this.gateway = new Gateway(eip_definition, secrets, gateway, context);
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -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";
//////////////////////////////////////////////
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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);
}
}
......@@ -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();
}
}
......@@ -9,33 +9,20 @@
android:layout_width="match_parent"
tools:ignore="RtlCompat"
android:layout_height="match_parent">
<!--
<RelativeLayout
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:background="@drawable/bg_switchbar"
android:paddingStart="@dimen/switchbar_pad"
android:elevation="1dp"
android:paddingEnd="@dimen/switchbar_pad"
tools:ignore="NewApi">
android:gravity="center"
android:textStyle="bold"
android:textColor="@color/colorWarning"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/warning_exclude_apps_message" />
<Switch
android:id="@+id/default_allow"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/default_allow_text"
style="@android:style/TextAppearance.Medium.Inverse"
tools:text="@string/vpn_disallow_radio"
android:layout_toStartOf="@id/default_allow"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content" />
</RelativeLayout>-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
<ListView
android:visibility="gone"
......@@ -46,8 +33,6 @@
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />
<LinearLayout
android:id="@+id/loading_container"
android:orientation="vertical"
......
......@@ -35,4 +35,6 @@
<color name="colorActionBarTitleFont">@color/white</color>
<color name="colorActionBarSubtitleFont">@color/black800</color>
<color name="colorWarning">#B33A3A</color>
</resources>
......@@ -486,5 +486,4 @@
<string name="external_authenticator">External Authenticator</string>
<string name="configure">Configure</string>
<string name="extauth_not_configured">External Authneticator not configured</string>
</resources>
......@@ -32,7 +32,7 @@
<string name="password_mismatch">Passwords do not match</string>
<string name="user_message">User message</string>
<string name="about_fragment_title">About</string>
<string name="allow_apps_fragment_title">Select Apps</string>
<string name="exclude_apps_fragment_title">Exclude apps from VPN</string>
<string name="error_srp_math_error_user_message">Try again: Server math error</string>
<string name="error_bad_user_password_user_message">Incorrect username or password</string>
<string name="error_not_valid_password_user_message">It must be at least 8 characters long</string>
......@@ -111,4 +111,6 @@
<string name="donate_message">LEAP depends on donations and grants. Please donate today if you value secure communication that is easy for both the end-user and the service provider.</string>
<string name="donate_button_remind_later">Remind me later</string>
<string name="donate_button_donate">Donate</string>
<string name="warning_exclude_apps_message">Be careful of excluding apps from VPN. This will reveal your identity and compromise your security.</string>
</resources>
package se.leap.bitmaskclient.eip;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Display;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
......@@ -14,7 +41,12 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import se.leap.bitmaskclient.Provider;
......@@ -74,7 +106,7 @@ public class GatewaySelectorTest {
for (int i = 0; i < gateways.length(); i++) {
JSONObject gw = gateways.getJSONObject(i);
JSONObject secrets = secretsConfiguration();
Gateway aux = new Gateway(eipDefinition, secrets, gw);
Gateway aux = new Gateway(eipDefinition, secrets, gw, null);
gatewayList.add(aux);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment