Commit 9b832c43 authored by cyberta's avatar cyberta

first shot gatewayselection

parent 1f5095b5
......@@ -216,31 +216,31 @@ def processFileInplace(file, Closure processText) {
task copyIcsOpenVPNClasses( type: Copy ) {
println "copyIcsOpenVPNClasses"
from ('../ics-openvpn/main/') {
include '**/LaunchVPN.java'
include '**/OpenVPNSservice.java'
include '**/VpnProfile.java'
include '**/DisconnectVPN.java'
include '**/VpnProfile.java'
include '**/SeekBarTicks.java'
include '**/core/**.java'
include '**/activities/BaseActivity.java'
include '**/APIVpnProfile.java'
include '**/aidl/**/api/**.aidl'
include '**/aidl/**/core/**.aidl'
includeEmptyDirs = false
filter {
line -> line.replaceAll('de.blinkt.openvpn.R', 'se.leap.bitmaskclient.R')
}
filter {
line -> line.replaceAll('de.blinkt.openvpn.BuildConfig', 'se.leap.bitmaskclient.BuildConfig')
}
filter {
line -> line.replace('package de.blinkt.openvpn;', 'package de.blinkt.openvpn;\n\nimport se.leap.bitmaskclient.R;')
}
} into '.'
// from ('../ics-openvpn/main/') {
// include '**/LaunchVPN.java'
// include '**/OpenVPNSservice.java'
// include '**/VpnProfile.java'
// include '**/DisconnectVPN.java'
// include '**/VpnProfile.java'
// include '**/SeekBarTicks.java'
// include '**/core/**.java'
// include '**/activities/BaseActivity.java'
// include '**/APIVpnProfile.java'
// include '**/aidl/**/api/**.aidl'
// include '**/aidl/**/core/**.aidl'
//
// includeEmptyDirs = false
//
// filter {
// line -> line.replaceAll('de.blinkt.openvpn.R', 'se.leap.bitmaskclient.R')
// }
// filter {
// line -> line.replaceAll('de.blinkt.openvpn.BuildConfig', 'se.leap.bitmaskclient.BuildConfig')
// }
// filter {
// line -> line.replace('package de.blinkt.openvpn;', 'package de.blinkt.openvpn;\n\nimport se.leap.bitmaskclient.R;')
// }
// } into '.'
}
task copyIcsOpenVPNXml( type: Copy ) {
......@@ -262,31 +262,31 @@ task copyIcsOpenVPNXml( type: Copy ) {
task copyIcsOpenVPNImages( type: Copy ) {
println "copyIcsOpenVPNImages"
from ('../ics-openvpn/main/') {
include '**/ic_filter*.png'
include '**/ic_delete*.png'
include '**/ic_share*.png'
include '**/ic_close*.png'
include '**/ic_edit*.png'
include '**/ic_check*.png'
include '**/ic_pause*.png'
include '**/ic_play*.png'
include '**/ic_content_copy_white_*.png'
include '**/ic_add_circle_outline_white_*.png'
include '**/ic_warning_black_*.png'
include '**/ic_add_circle_outline_grey600_*.png'
include '**/ic_archive_grey600_*.png'
include '**/ic_receipt_white_*.png'
include '**/ic_sort_white_*.png'
include '**/ic_content_copy_white_*.png'
include '**/ic_archive_white_*.png'
include '**/ic_menu_archive*.png'
include '**/vpn_item_settings*.png'
include '**/ic_menu_log*.png'
include '**/ic_menu_copy_holo_light*.png'
includeEmptyDirs = false
} into '.'
// from ('../ics-openvpn/main/') {
// include '**/ic_filter*.png'
// include '**/ic_delete*.png'
// include '**/ic_share*.png'
// include '**/ic_close*.png'
// include '**/ic_edit*.png'
// include '**/ic_check*.png'
// include '**/ic_pause*.png'
// include '**/ic_play*.png'
// include '**/ic_content_copy_white_*.png'
// include '**/ic_add_circle_outline_white_*.png'
// include '**/ic_warning_black_*.png'
// include '**/ic_add_circle_outline_grey600_*.png'
// include '**/ic_archive_grey600_*.png'
// include '**/ic_receipt_white_*.png'
// include '**/ic_sort_white_*.png'
// include '**/ic_content_copy_white_*.png'
// include '**/ic_archive_white_*.png'
// include '**/ic_menu_archive*.png'
// include '**/vpn_item_settings*.png'
// include '**/ic_menu_log*.png'
// include '**/ic_menu_copy_holo_light*.png'
//
// includeEmptyDirs = false
// } into '.'
}
// thanks to http://pleac.sourceforge.net/pleac_groovy/fileaccess.html
......
......@@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18"/>
......
......@@ -214,6 +214,7 @@ public class VpnStatus {
}
public interface StateListener {
String STATE_CONNECTRETRY = "CONNECTRETRY";
void updateState(String state, String logmessage, int localizedResId, ConnectionStatus level);
void setConnectedVPN(String uuid);
......@@ -267,10 +268,12 @@ public class VpnStatus {
public synchronized static void addStateListener(StateListener sl) {
if (!stateListener.contains(sl)) {
stateListener.add(sl);
if (mLaststate != null)
sl.updateState(mLaststate, mLaststatemsg, mLastStateresid, mLastLevel);
synchronized (stateListener) {
if (!stateListener.contains(sl)) {
stateListener.add(sl);
if (mLaststate != null)
sl.updateState(mLaststate, mLaststatemsg, mLastStateresid, mLastLevel);
}
}
}
......@@ -351,7 +354,9 @@ public class VpnStatus {
public synchronized static void removeStateListener(StateListener sl) {
stateListener.remove(sl);
synchronized (stateListener) {
stateListener.remove(sl);
}
}
......@@ -384,8 +389,10 @@ public class VpnStatus {
mLastLevel = level;
for (StateListener sl : stateListener) {
sl.updateState(state, msg, resid, level);
synchronized (stateListener) {
for (StateListener sl : stateListener) {
sl.updateState(state, msg, resid, level);
}
}
//newLogItem(new LogItem((LogLevel.DEBUG), String.format("New OpenVPN Status (%s->%s): %s",state,level.toString(),msg)));
}
......
/*
* Copyright (c) 2012-2014 Arne Schwabe
* Copyright (c) 2012-2016 Arne Schwabe
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
*/
......
package se.leap.bitmaskclient;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.support.multidex.MultiDexApplication;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import static android.content.Intent.CATEGORY_DEFAULT;
import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT;
import static se.leap.bitmaskclient.Constants.BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT;
import static se.leap.bitmaskclient.Constants.BROADCAST_PROVIDER_API_EVENT;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.utils.PreferenceHelper.getSavedProviderFromSharedPreferences;
/**
* Created by cyberta on 24.10.17.
*/
public class BitmaskApp extends MultiDexApplication {
private final static String TAG = BitmaskApp.class.getSimpleName();
private RefWatcher refWatcher;
private ProviderObservable providerObservable;
private SharedPreferences preferences;
@Override
public void onCreate() {
......@@ -25,6 +40,10 @@ public class BitmaskApp extends MultiDexApplication {
refWatcher = LeakCanary.install(this);
// Normal app init code...*/
PRNGFixes.apply();
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
providerObservable = ProviderObservable.getInstance();
providerObservable.updateProvider(getSavedProviderFromSharedPreferences(preferences));
EipSetupObserver.init(this, preferences);
}
/**
......
......@@ -51,6 +51,7 @@ public interface Constants {
String EIP_RESTART_ON_BOOT = "EIP.RESTART_ON_BOOT";
String EIP_IS_ALWAYS_ON = "EIP.EIP_IS_ALWAYS_ON";
String EIP_EARLY_ROUTES = "EIP.EARLY_ROUTES";
String EIP_N_CLOSEST_GATEWAY = "EIP.N_CLOSEST_GATEWAY";
//////////////////////////////////////////////
......@@ -64,6 +65,7 @@ public interface Constants {
String PROVIDER_KEY = "Constants.PROVIDER_KEY";
String PROVIDER_CONFIGURED = "Constants.PROVIDER_CONFIGURED";
String PROVIDER_EIP_DEFINITION = "Constants.EIP_DEFINITION";
String PROVIDER_PROFILE_UUID = "Constants.PROVIDER_PROFILE_UUID";
//////////////////////////////////////////////
// CREDENTIAL CONSTANTS
......@@ -84,6 +86,7 @@ public interface Constants {
String BROADCAST_EIP_EVENT = "BROADCAST.EIP_EVENT";
String BROADCAST_PROVIDER_API_EVENT = "BROADCAST.PROVIDER_API_EVENT";
String BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT = "BROADCAST.GATEWAY_SETUP_WATCHER_EVENT";
String BROADCAST_RESULT_CODE = "BROADCAST.RESULT_CODE";
String BROADCAST_RESULT_KEY = "BROADCAST.RESULT_KEY";
......
......@@ -27,6 +27,7 @@ import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
......@@ -35,10 +36,13 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Observable;
import java.util.Observer;
......@@ -58,17 +62,20 @@ import se.leap.bitmaskclient.views.VpnStateImage;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
import static se.leap.bitmaskclient.Constants.DEFAULT_BITMASK;
import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_LOG_IN;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.EipSetupObserver.connectionRetry;
import static se.leap.bitmaskclient.EipSetupObserver.gatewayOrder;
import static se.leap.bitmaskclient.EipSetupObserver.reconnectingWithDifferentGateway;
import static se.leap.bitmaskclient.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.ProviderAPI.USER_MESSAGE;
import static se.leap.bitmaskclient.R.string.vpn_certificate_user_message;
import static se.leap.bitmaskclient.utils.ConfigHelper.isDefaultBitmask;
import static se.leap.bitmaskclient.utils.ViewHelper.convertDimensionToPx;
public class EipFragment extends Fragment implements Observer {
......@@ -94,6 +101,8 @@ public class EipFragment extends Fragment implements Observer {
@InjectView(R.id.vpn_route)
AppCompatTextView vpnRoute;
private EipStatus eipStatus;
//---saved Instance -------
......@@ -193,7 +202,6 @@ public class EipFragment extends Fragment implements Observer {
if (activity != null) {
getActivity().unbindService(openVpnConnection);
}
Log.d(TAG, "broadcast unregistered");
}
@Override
......@@ -289,7 +297,7 @@ public class EipFragment extends Fragment implements Observer {
Log.e(TAG, "context is null when trying to start VPN");
return;
}
EipCommand.startVPN(context, false);
EipCommand.startVPN(context.getApplicationContext(), false);
vpnStateImage.showProgress();
routedText.setVisibility(GONE);
vpnRoute.setVisibility(GONE);
......@@ -302,7 +310,7 @@ public class EipFragment extends Fragment implements Observer {
Log.e(TAG, "context is null when trying to stop EIP");
return;
}
EipCommand.stopVPN(context);
EipCommand.stopVPN(context.getApplicationContext());
}
private void askPendingStartCancellation() {
......@@ -378,6 +386,8 @@ public class EipFragment extends Fragment implements Observer {
} else {
Log.e("EipFragment", "activity is null");
}
} else if (observable instanceof ProviderObservable) {
provider = ((ProviderObservable) observable).getCurrentProvider();
}
}
......@@ -388,13 +398,16 @@ public class EipFragment extends Fragment implements Observer {
return;
}
if (eipStatus.isConnecting()) {
mainButton.setText(activity.getString(android.R.string.cancel));
vpnStateImage.setStateIcon(R.drawable.vpn_connecting);
vpnStateImage.showProgress();
routedText.setVisibility(GONE);
vpnRoute.setVisibility(GONE);
colorBackgroundALittle();
Log.d(TAG, "eip fragment eipStatus state: " + eipStatus.getState() + " - level: " + eipStatus.getLevel() + " - is reconnecting: " + eipStatus.isReconnecting());
if (eipStatus.isConnecting() ) {
showConnectingLayout(activity);
Log.d(TAG, "eip show connecting layout");
if (eipStatus.isReconnecting()) {
Log.d(TAG, "eip show reconnecting toast!");
showReconnectToast(activity);
}
} else if (eipStatus.isConnected() ) {
mainButton.setText(activity.getString(R.string.vpn_button_turn_off));
vpnStateImage.setStateIcon(R.drawable.vpn_connected);
......@@ -413,7 +426,11 @@ public class EipFragment extends Fragment implements Observer {
vpnRoute.setVisibility(VISIBLE);
setVpnRouteText();
colorBackgroundALittle();
} else {
} else if (eipStatus.isDisconnected() && reconnectingWithDifferentGateway()) {
showConnectingLayout(activity);
showRetryToast(activity);
}
else {
mainButton.setText(activity.getString(R.string.vpn_button_turn_on));
vpnStateImage.setStateIcon(R.drawable.vpn_disconnected);
vpnStateImage.stopProgress(false);
......@@ -423,6 +440,48 @@ public class EipFragment extends Fragment implements Observer {
}
}
private void showToast(Activity activity, String message, boolean vibrateLong) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) activity.findViewById(R.id.custom_toast_container));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(message);
Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrateLong) {
v.vibrate(100);
v.vibrate(200);
} else {
v.vibrate(100);
}
Toast toast = new Toast(activity.getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, convertDimensionToPx(this.getContext(), R.dimen.stdpadding));
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
private void showReconnectToast(Activity activity) {
String message = (String.format("Retry %d of %d before the next closest gateway will be selected.", connectionRetry()+1, 5));
showToast(activity, message, false);
}
private void showRetryToast(Activity activity) {
int nClosestGateway = gatewayOrder();
String message = String.format("Server number " + nClosestGateway + " not reachable. Trying next gateway.");
showToast(activity, message, true );
}
private void showConnectingLayout(Context activity) {
mainButton.setText(activity.getString(android.R.string.cancel));
vpnStateImage.setStateIcon(R.drawable.vpn_connecting);
vpnStateImage.showProgress();
routedText.setVisibility(GONE);
vpnRoute.setVisibility(GONE);
colorBackgroundALittle();
}
private boolean isOpenVpnRunningWithoutNetwork() {
boolean isRunning = false;
try {
......
package se.leap.bitmaskclient;
import android.content.Intent;
/**
* Created by cyberta on 05.12.18.
*/
public interface EipSetupListener {
void handleEipEvent(Intent intent);
void handleProviderApiEvent(Intent intent);
}
This diff is collapsed.
package se.leap.bitmaskclient;
import java.util.Observable;
import se.leap.bitmaskclient.utils.PreferenceHelper;
/**
* Created by cyberta on 05.12.18.
*/
public class ProviderObservable extends Observable {
private static ProviderObservable instance;
private Provider currentProvider;
public static ProviderObservable getInstance() {
if (instance == null) {
instance = new ProviderObservable();
}
return instance;
}
public synchronized void updateProvider(Provider provider) {
instance.currentProvider = provider;
instance.setChanged();
instance.notifyObservers();
}
public Provider getCurrentProvider() {
return instance.currentProvider;
}
}
......@@ -25,16 +25,17 @@ import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.Log;
import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import de.blinkt.openvpn.core.Preferences;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.userstatus.User;
import se.leap.bitmaskclient.utils.ConfigHelper;
import se.leap.bitmaskclient.utils.PreferenceHelper;
import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
import static se.leap.bitmaskclient.Constants.DEFAULT_BITMASK;
import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT;
import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION;
import static se.leap.bitmaskclient.Constants.PROVIDER_EIP_DEFINITION;
......@@ -99,6 +100,9 @@ public class StartActivity extends Activity{
VpnStatus.initLogCache(getApplicationContext().getCacheDir());
User.init(getString(R.string.default_username));
fakeSetup();
prepareEIP();
}
......@@ -184,7 +188,7 @@ public class StartActivity extends Activity{
} else {
Log.d(TAG, "vpn provider is configured");
if (getIntent() != null && getIntent().getBooleanExtra(EIP_RESTART_ON_BOOT, false)) {
EipCommand.startVPN(this, true);
EipCommand.startVPN(this.getApplicationContext(), true);
finish();
return;
}
......@@ -213,7 +217,8 @@ public class StartActivity extends Activity{
if (resultCode == RESULT_OK && data != null && data.hasExtra(Provider.KEY)) {
Provider provider = data.getParcelableExtra(Provider.KEY);
storeProviderInPreferences(preferences, provider);
EipCommand.startVPN(this, false);
ProviderObservable.getInstance().updateProvider(provider);
EipCommand.startVPN(this.getApplicationContext(), false);
showMainActivity();
} else if (resultCode == RESULT_CANCELED) {
finish();
......@@ -229,4 +234,145 @@ public class StartActivity extends Activity{
finish();
}
private void fakeSetup() {
PreferenceHelper.putString(this, "Constants.EIP_DEFINITION.riseup.net", getRiseupEipJson());
PreferenceHelper.putString(this, "Constants.EIP_DEFINITION", getRiseupEipJson());
SharedPreferences prefs = Preferences.getDefaultSharedPreferences(this);
SharedPreferences.Editor prefsedit = prefs.edit();
prefsedit.remove("lastConnectedProfile").commit();
File f = new File(this.getCacheDir().getAbsolutePath() + "/android.conf");
if (f.exists()) {
Log.d(TAG, "android.conf exists -> delete:" + f.delete());
}
File filesDirectory = new File(this.getFilesDir().getAbsolutePath());
if (filesDirectory.exists() && filesDirectory.isDirectory()) {
File[] filesInDirectory = filesDirectory.listFiles();
for (File file : filesInDirectory) {
Log.d(TAG, "delete profile: " + file.getName() + ": "+ file.delete());
}
} else Log.d(TAG, "file folder doesn't exist");
Log.d(TAG, "faked eipjson: " + PreferenceHelper.getString(this, "Constants.EIP_DEFINITION", ""));
Log.d(TAG, "lastConnectedProfile is emty: " + (prefs.getString("lastConnectedProfile", null) == null));
}
private String getRiseupEipJson() {
return "{\n" +
" \"gateways\":[\n" +
" {\n" +
" \"capabilities\":{\n" +
" \"adblock\":false,\n" +
" \"filter_dns\":false,\n" +
" \"limited\":false,\n" +
" \"ports\":[\n" +
" \"443\"\n" +
" ],\n" +
" \"protocols\":[\n" +
" \"tcp\"\n" +
" ],\n" +
" \"transport\":[\n" +
" \"openvpn\"\n" +
" ],\n" +
" \"user_ips\":false\n" +
" },\n" +
" \"host\":\"garza.riseup.net\",\n" +
" \"ip_address\":\"198.252.153.28\",\n" +
" \"location\":\"seattle\"\n" +
" },\n" +
" {\n" +
" \"capabilities\":{\n" +
" \"adblock\":false,\n" +
" \"filter_dns\":false,\n" +
" \"limited\":false,\n" +
" \"ports\":[\n" +
" \"443\"\n" +
" ],\n" +
" \"protocols\":[\n" +
" \"tcp\"\n" +
" ],\n" +
" \"transport\":[\n" +
" \"openvpn\"\n" +
" ],\n" +
" \"user_ips\":false\n" +
" },\n" +
" \"host\":\"no.giraffe.riseup.net\",\n" +
" \"ip_address\":\"37.218.242.212\",\n" +
" \"location\":\"amsterdam\"\n" +
" },\n" +
" {\n" +
" \"capabilities\":{\n" +
" \"adblock\":false,\n" +
" \"filter_dns\":false,\n" +
" \"limited\":false,\n" +
" \"ports\":[\n" +
" \"443\"\n" +
" ],\n" +
" \"protocols\":[\n" +
" \"tcp\"\n" +
" ],\n" +
" \"transport\":[\n" +
" \"openvpn\"\n" +
" ],\n" +
" \"user_ips\":false\n" +
" },\n" +
" \"host\":\"no.tenca.riseup.net\",\n" +
" \"ip_address\":\"5.79.86.181\",\n" +
" \"location\":\"amsterdam\"\n" +
" },\n" +
" {\n" +
" \"capabilities\":{\n" +
" \"adblock\":false,\n" +
" \"filter_dns\":false,\n" +
" \"limited\":false,\n" +
" \"ports\":[\n" +
" \"443\"\n" +
" ],\n" +
" \"protocols\":[\n" +
" \"tcp\"\n" +
" ],\n" +
" \"transport\":[\n" +
" \"openvpn\"\n" +
" ],\n" +
" \"user_ips\":false\n" +
" },\n" +
" \"host\":\"yal.riseup.net\",\n" +
" \"ip_address\":\"199.58.81.145\",\n" +
" \"location\":\"montreal\"\n" +
" }\n" +
" ],\n" +
" \"locations\":{\n" +
" \"amsterdam\":{\n" +
" \"country_code\":\"NL\",\n" +
" \"hemisphere\":\"N\",\n" +
" \"name\":\"Amsterdam\",\n" +
" \"timezone\":\"+2\"\n" +
" },\n" +
" \"montreal\":{\n" +
" \"country_code\":\"CA\",\n" +
" \"hemisphere\":\"N\",\n" +
" \"name\":\"Montreal\",\n" +
" \"timezone\":\"-5\"\n" +
" },\n" +
" \"seattle\":{\n" +
" \"country_code\":\"US\",\n" +
" \"hemisphere\":\"N\",\n" +
" \"name\":\"Seattle\",\n" +
" \"timezone\":\"-7\"\n" +
" }\n" +
" },\n" +
" \"openvpn_configuration\":{\n" +
" \"auth\":\"SHA1\",\n" +
" \"cipher\":\"AES-128-CBC\",\n" +
" \"keepalive\":\"10 30\",\n" +
" \"tls-cipher\":\"DHE-RSA-AES128-SHA\",\n" +
" \"tun-ipv6\":true\n" +
" },\n" +
" \"serial\":1,\n" +
" \"version\":1\n" +
"}";
}
}
......@@ -53,7 +53,9 @@ import se.leap.bitmaskclient.OnBootReceiver;
import static android.app.Activity.RESULT_CANCELED;
import static android.app.Activity.RESULT_OK;
import static android.content.Intent.CATEGORY_DEFAULT;
import static de.blinkt.openvpn.LaunchVPN.EXTRA_TEMP_VPN_PROFILE;
import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT;
import static se.leap.bitmaskclient.Constants.BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT;
import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_CODE;
import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_KEY;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY;
......@@ -63,6 +65,7 @@ import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_VPN;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP_BLOCKING_VPN;
import static se.leap.bitmaskclient.Constants.EIP_EARLY_ROUTES;
import static se.leap.bitmaskclient.Constants.EIP_N_CLOSEST_GATEWAY;
import static se.leap.bitmaskclient.Constants.EIP_RECEIVER;
import static se.leap.bitmaskclient.Constants.EIP_REQUEST;
import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT;
......@@ -150,10 +153,12 @@ public final class EIP extends JobIntentService implements Observer {
if (intent.getParcelableExtra(EIP_RECEIVER) != null) {
mResultRef = new WeakReference<>((ResultReceiver) intent.getParcelableExtra(EIP_RECEIVER));
}
int nClosestGateway;
switch (action) {
case EIP_ACTION_START:
boolean earlyRoutes = intent.getBooleanExtra(EIP_EARLY_ROUTES, true);
startEIP(earlyRoutes);
nClosestGateway = intent.getIntExtra(EIP_N_CLOSEST_GATEWAY, 0);
startEIP(earlyRoutes, nClosestGateway);
break;
case EIP_ACTION_START_ALWAYS_ON_VPN:
startEIPAlwaysOnVpn();
......@@ -170,13 +175,17 @@ public final class EIP extends JobIntentService implements Observer {
}
}
/**
* Initiates an EIP connection by selecting a gateway and preparing and sending an
* Intent to {@link de.blinkt.openvpn.LaunchVPN}.
* It also sets up early routes.
* @param earlyRoutes if true, a void vpn gets set up
* @param nClosestGateway the gateway that is the n nearest one to the users place
*/
@SuppressLint("ApplySharedPref")