summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java12
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java28
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/MainActivity.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java12
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java112
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java70
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderManager.java50
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/StartActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java6
16 files changed, 153 insertions, 234 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java b/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java
index f9e45b79..15fd85f8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BitmaskApp.java
@@ -1,7 +1,7 @@
package se.leap.bitmaskclient;
-import android.app.Application;
import android.content.Context;
+import android.support.multidex.MultiDexApplication;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
@@ -10,7 +10,7 @@ import com.squareup.leakcanary.RefWatcher;
* Created by cyberta on 24.10.17.
*/
-public class BitmaskApp extends Application {
+public class BitmaskApp extends MultiDexApplication {
private RefWatcher refWatcher;
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index a4db5f84..78ec3fd2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -459,11 +459,11 @@ public class Dashboard extends ButterKnifeActivity {
String password = resultData.getString(SessionDialog.PASSWORD);
dashboard.user_status_fragment.logIn(username, password);
} else if (resultCode == ProviderAPI.FAILED_SIGNUP) {
- MainActivity.sessionDialog(resultData);
+ //MainActivity.sessionDialog(resultData);
} else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) {
Dashboard.downloadVpnCertificate();
} else if (resultCode == ProviderAPI.FAILED_LOGIN) {
- MainActivity.sessionDialog(resultData);
+ //MainActivity.sessionDialog(resultData);
} else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) {
if (switching_provider) dashboard.switchProvider();
} else if (resultCode == ProviderAPI.LOGOUT_FAILED) {
diff --git a/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java b/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
index 52c797a4..57ff1fd8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DefaultedURL.java
@@ -1,6 +1,7 @@
package se.leap.bitmaskclient;
-import java.net.*;
+import java.net.MalformedURLException;
+import java.net.URL;
public class DefaultedURL {
private URL DEFAULT_URL;
@@ -8,7 +9,7 @@ public class DefaultedURL {
private URL url;
- public DefaultedURL() {
+ DefaultedURL() {
try {
DEFAULT_URL = new URL(default_url);
url = DEFAULT_URL;
diff --git a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
index 527ce1a7..dde71642 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
@@ -16,12 +16,12 @@
*/
package se.leap.bitmaskclient;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
-import android.support.v4.app.DialogFragment;
+import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
import org.json.JSONObject;
@@ -134,12 +134,12 @@ public class DownloadFailedDialog extends DialogFragment {
DownloadFailedDialogInterface interface_with_ConfigurationWizard;
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
+ public void onAttach(Context context) {
+ super.onAttach(context);
try {
- interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity;
+ interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) context;
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
+ throw new ClassCastException(context.toString()
+ " must implement NoticeDialogListener");
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 414b1f2a..c0e2c21e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -53,6 +53,7 @@ import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.VoidVpnService;
+import se.leap.bitmaskclient.userstatus.SessionDialog;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
@@ -73,10 +74,12 @@ import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
public class EipFragment extends Fragment implements Observer {
- public static String TAG = EipFragment.class.getSimpleName();
+ public final static String TAG = EipFragment.class.getSimpleName();
protected static final String IS_CONNECTED = TAG + ".is_connected";
public static final String START_EIP_ON_BOOT = "start on boot";
+ public static final String ASK_TO_CANCEL_VPN = "ask_to_cancel_vpn";
+
private SharedPreferences preferences;
@@ -121,6 +124,7 @@ public class EipFragment extends Fragment implements Observer {
};
+ @Override
public void onAttach(Context context) {
super.onAttach(context);
downloadEIPServiceConfig();
@@ -130,19 +134,23 @@ public class EipFragment extends Fragment implements Observer {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
eipStatus = EipStatus.getInstance();
- eipStatus.addObserver(this);
eipReceiver = new EIPReceiver(new Handler());
preferences = getActivity().getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ eipStatus.addObserver(this);
View view = inflater.inflate(R.layout.eip_service_fragment, container, false);
ButterKnife.inject(this, view);
Bundle arguments = getArguments();
- if (arguments != null && arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) {
- startEipFromScratch();
+ if (arguments != null) {
+ if (arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) {
+ startEipFromScratch();
+ } else if (arguments.containsKey(ASK_TO_CANCEL_VPN) && arguments.getBoolean(ASK_TO_CANCEL_VPN)) {
+ askToStopEIP();
+ }
}
return view;
}
@@ -163,6 +171,12 @@ public class EipFragment extends Fragment implements Observer {
}
@Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ eipStatus.deleteObserver(this);
+ }
+
+ @Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(IS_CONNECTED, eipStatus.isConnected());
super.onSaveInstanceState(outState);
@@ -199,8 +213,10 @@ public class EipFragment extends Fragment implements Observer {
startEipFromScratch();
else if (canLogInToStartEIP()) {
wantsToConnect = true;
- Bundle bundle = new Bundle();
- MainActivity.sessionDialog(bundle);
+ /*Bundle bundle = new Bundle();
+ seionDialogCallback.onSessionDialog(bundle);*/
+ Log.w(TAG, "TODO: implement login from here");
+ //FIXME: implement login from here
} else {
Log.d(TAG, "WHAT IS GOING ON HERE?!");
// TODO: implement a fallback: check if vpncertificate was not downloaded properly or give
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
index 7629f0b7..186c2928 100644
--- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
@@ -15,12 +15,11 @@ import se.leap.bitmaskclient.userstatus.SessionDialog;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.EipFragment.ASK_TO_CANCEL_VPN;
public class MainActivity extends AppCompatActivity {
- private static Provider provider = new Provider();
- private static FragmentManagerEnhanced fragmentManager;
private SharedPreferences preferences;
public final static String ACTION_SHOW_VPN_FRAGMENT = "action_show_vpn_fragment";
@@ -40,7 +39,6 @@ public class MainActivity extends AppCompatActivity {
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- fragmentManager = new FragmentManagerEnhanced(getSupportFragmentManager());
// Set up the drawer.
navigationDrawerFragment.setUp(
R.id.navigation_drawer,
@@ -49,15 +47,6 @@ public class MainActivity extends AppCompatActivity {
handleIntentAction(getIntent());
}
- public static void sessionDialog(Bundle resultData) {
- try {
- FragmentTransaction transaction = fragmentManager.removePreviousFragment(SessionDialog.TAG);
- SessionDialog.getInstance(provider, resultData).show(transaction, SessionDialog.TAG);
- } catch (IllegalStateException e) {
- e.printStackTrace();
- }
- }
-
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@@ -71,17 +60,21 @@ public class MainActivity extends AppCompatActivity {
}
Fragment fragment = null;
-
switch (intent.getAction()) {
case ACTION_SHOW_VPN_FRAGMENT:
fragment = new EipFragment();
+ if (intent.hasExtra(ASK_TO_CANCEL_VPN)) {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(ASK_TO_CANCEL_VPN, true);
+ fragment.setArguments(bundle);
+ }
break;
default:
break;
}
if (fragment != null) {
- fragmentManager.beginTransaction()
+ new FragmentManagerEnhanced(getSupportFragmentManager()).beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
@@ -100,5 +93,4 @@ public class MainActivity extends AppCompatActivity {
}
}
}
-
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index ae329cd1..5ff1949c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -309,4 +309,12 @@ public final class Provider implements Parcelable {
this.caCert = cert;
}
+ public boolean isDefault() {
+ return getMainUrl().isDefault() &&
+ getApiUrl().isDefault() &&
+ certificatePin.isEmpty() &&
+ certificatePinEncoding.isEmpty() &&
+ caCert.isEmpty();
+ }
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
index cfc6e49d..8117fb99 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
@@ -163,12 +163,16 @@ public abstract class ProviderApiManagerBase {
if (action.equals(UPDATE_PROVIDER_DETAILS)) {
resetProviderDetails();
Bundle task = new Bundle();
- task.putString(MAIN_URL, lastProviderMainUrl);
+ String mainUrl = parameters.getString(Provider.MAIN_URL);
+ if (mainUrl == null) {
+ mainUrl = lastProviderMainUrl;
+ }
+ task.putString(MAIN_URL, mainUrl);
Bundle result = setUpProvider(task);
if (result.getBoolean(RESULT_KEY)) {
- receiver.send(PROVIDER_OK, result);
+ sendToReceiverOrBroadcast(receiver, PROVIDER_OK, result);
} else {
- receiver.send(PROVIDER_NOK, result);
+ sendToReceiverOrBroadcast(receiver, PROVIDER_NOK, result);
}
} else if (action.equalsIgnoreCase(SET_UP_PROVIDER)) {
Bundle result = setUpProvider(parameters);
@@ -222,7 +226,7 @@ public abstract class ProviderApiManagerBase {
} else if (action.equalsIgnoreCase(PROVIDER_SET_UP)) {
if(EIP_SERVICE_JSON_DOWNLOADED && CA_CERT_DOWNLOADED && PROVIDER_JSON_DOWNLOADED ) {
if(receiver!= null) {
- receiver.send(PROVIDER_OK, Bundle.EMPTY);
+ sendToReceiverOrBroadcast(receiver, PROVIDER_OK, Bundle.EMPTY);
}
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
index 4a34caa0..6672c575 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -1,119 +1,15 @@
package se.leap.bitmaskclient;
-import android.view.*;
+import android.view.LayoutInflater;
-import com.pedrogomez.renderers.*;
-
-import java.util.*;
+import com.pedrogomez.renderers.AdapteeCollection;
+import com.pedrogomez.renderers.RendererAdapter;
+import com.pedrogomez.renderers.RendererBuilder;
public class ProviderListAdapter extends RendererAdapter<Provider> {
- private static boolean[] hidden = null;
-
- public void hide(int position) {
- hidden[getRealPosition(position)] = true;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void unHide(int position) {
- hidden[getRealPosition(position)] = false;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void showAllProviders() {
- for (int i = 0; i < hidden.length; i++)
- hidden[i] = false;
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- public void hideAllBut(int position) {
- for (int i = 0; i < hidden.length; i++) {
- if (i != position)
- hidden[i] = true;
- else
- hidden[i] = false;
- }
- notifyDataSetChanged();
- notifyDataSetInvalidated();
- }
-
- private int getRealPosition(int position) {
- int hElements = getHiddenCountUpTo(position);
- int diff = 0;
- for (int i = 0; i < hElements; i++) {
- diff++;
- if (hidden[position + diff])
- i--;
- }
- return (position + diff);
- }
-
- private int getHiddenCount() {
- int count = 0;
- for (int i = 0; i < hidden.length; i++)
- if (hidden[i])
- count++;
- return count;
- }
-
- private int getHiddenCountUpTo(int location) {
- int count = 0;
- for (int i = 0; i <= location; i++) {
- if (hidden[i])
- count++;
- }
- return count;
- }
-
- @Override
- public int getCount() {
- return (hidden.length - getHiddenCount());
- }
-
public ProviderListAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder,
AdapteeCollection<Provider> collection) {
super(layoutInflater, rendererBuilder, collection);
- hidden = new boolean[collection.size()];
- for (int i = 0; i < collection.size(); i++)
- hidden[i] = false;
- }
-
- @Override
- public void add(Provider item) {
- super.add(item);
- if (getCollection().size() > hidden.length) {
- boolean[] new_hidden = new boolean[hidden.length + 1];
- System.arraycopy(hidden, 0, new_hidden, 0, hidden.length);
- new_hidden[hidden.length] = false;
- hidden = new_hidden;
- }
- }
-
- @Override
- public void remove(Provider item) {
- super.remove(item);
- boolean[] new_hidden = new boolean[hidden.length - 1];
- System.arraycopy(hidden, 0, new_hidden, 0, hidden.length - 1);
- hidden = new_hidden;
- }
-
- protected int indexOf(Provider item) {
- int index = 0;
- ProviderManager provider_manager = (ProviderManager) getCollection();
- Set<Provider> providers = provider_manager.providers();
- for (Provider provider : providers) {
- if (provider.equals(item)) {
- break;
- } else index++;
- }
- return index;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- return super.getView(getRealPosition(position), convertView, parent);
}
public void saveProviders() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
index bab8aa47..fdf8df3c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java
@@ -27,7 +27,6 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
-import android.view.MenuItem;
import android.widget.ListView;
import com.pedrogomez.renderers.Renderer;
@@ -168,7 +167,6 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
isActivityShowing = true;
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) {
showProgressBar();
- adapter.hideAllBut(adapter.indexOf(provider));
checkProviderSetUp();
} else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) {
showDownloadFailedDialog();
@@ -210,7 +208,6 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
private void setUpProviderAPIResultReceiver() {
providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), this);
providerAPIBroadcastReceiver = new ProviderAPIBroadcastReceiver();
-
IntentFilter updateIntentFilter = new IntentFilter(PROVIDER_API_EVENT);
updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter);
@@ -274,10 +271,15 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
}
//TODO Code 2 pane view
- mConfigState.setAction(SETTING_UP_PROVIDER);
provider = adapter.getItem(position);
- showProgressBar();
- onItemSelectedLogic();
+ if (provider != null && !provider.isDefault()) {
+ //TODO Code 2 pane view
+ mConfigState.setAction(SETTING_UP_PROVIDER);
+ showProgressBar();
+ onItemSelectedLogic();
+ } else {
+ addAndSelectNewProvider();
+ }
}
@Override
@@ -302,7 +304,6 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
public void cancelSettingUpProvider() {
hideProgressBar();
mConfigState.setAction(PROVIDER_NOT_SET);
- adapter.showAllProviders();
preferences.edit().remove(Provider.KEY).remove(PROVIDER_ALLOW_ANONYMOUS).remove(PROVIDER_KEY).apply();
}
@@ -410,24 +411,9 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
return true;
}
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.about_leap:
- startActivityForResult(new Intent(this, AboutFragment.class), 0);
- return true;
- case R.id.new_provider:
- addAndSelectNewProvider();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
public void cancelAndShowAllProviders() {
mConfigState.setAction(PROVIDER_NOT_SET);
provider = null;
- adapter.showAllProviders();
}
public class ProviderAPIBroadcastReceiver extends BroadcastReceiver {
@@ -452,31 +438,35 @@ public abstract class ProviderListBaseActivity extends ConfigWizardBaseActivity
String providerDomain = ConfigHelper.getProviderDomain(handledProvider);
//FIXME: remove that lines as soon as Provider gets sent via broadcast
+ // and make sure providers are the same - remove providersMatch
if (resultCode == PROVIDER_OK && handledProvider == null) {
providerName = ConfigHelper.getProviderName(preferences);
providerDomain = ConfigHelper.getProviderDomain(preferences);
}
+ boolean providersMatch = true;
+ if (providerDomain != null) {
+ providersMatch = providerDomain.equalsIgnoreCase(provider.getDomain());
+ }
+ if (providerName != null && !providersMatch) {
+ providersMatch = providerName.equalsIgnoreCase(provider.getName());
+ }
+
- if (providerName != null && providerName.equalsIgnoreCase(provider.getName()) &&
- providerDomain != null &&
- providerDomain.equalsIgnoreCase(provider.getDomain())) {
- switch (resultCode) {
- case PROVIDER_OK:
+ switch (resultCode) {
+ case PROVIDER_OK:
+ if (providersMatch)
handleProviderSetUp();
- break;
- case PROVIDER_NOK:
+ break;
+ case PROVIDER_NOK:
+ if(providersMatch)
handleProviderSetupFailed(resultData);
- break;
- }
- } else {
- switch (resultCode) {
- case CORRECTLY_DOWNLOADED_CERTIFICATE:
- handleCorrectlyDownloadedCertificate();
- break;
- case INCORRECTLY_DOWNLOADED_CERTIFICATE:
- handleIncorrectlyDownloadedCertificate();
- break;
- }
+ break;
+ case CORRECTLY_DOWNLOADED_CERTIFICATE:
+ handleCorrectlyDownloadedCertificate();
+ break;
+ case INCORRECTLY_DOWNLOADED_CERTIFICATE:
+ handleIncorrectlyDownloadedCertificate();
+ break;
}
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
index 62c04c1a..ed41be67 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderManager.java
@@ -15,9 +15,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
/**
@@ -25,15 +27,14 @@ import java.util.Set;
*/
public class ProviderManager implements AdapteeCollection<Provider> {
- private static final String TAG = ProviderManager.class.getName();
- private AssetManager assets_manager;
+ private AssetManager assetsManager;
private File externalFilesDir;
private Set<Provider> defaultProviders;
private Set<Provider> customProviders;
private static ProviderManager instance;
- final protected static String URLS = "urls";
+ final private static String URLS = "urls";
public static ProviderManager getInstance(AssetManager assetsManager, File externalFilesDir) {
if (instance == null)
@@ -42,8 +43,8 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return instance;
}
- public ProviderManager(AssetManager assetManager, File externalFilesDir) {
- this.assets_manager = assetManager;
+ private ProviderManager(AssetManager assetManager, File externalFilesDir) {
+ this.assetsManager = assetManager;
addDefaultProviders(assetManager);
addCustomProviders(externalFilesDir);
}
@@ -57,7 +58,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
}
private Set<Provider> providersFromAssets(String directory, String[] relativeFilePaths) {
- Set<Provider> providers = new HashSet<Provider>();
+ Set<Provider> providers = new HashSet<>();
for (String file : relativeFilePaths) {
String mainUrl = null;
@@ -65,10 +66,10 @@ public class ProviderManager implements AdapteeCollection<Provider> {
String providerDefinition = null;
try {
String provider = file.substring(0, file.length() - ".url".length());
- InputStream provider_file = assets_manager.open(directory + "/" + file);
+ InputStream provider_file = assetsManager.open(directory + "/" + file);
mainUrl = extractMainUrlFromInputStream(provider_file);
- certificate = ConfigHelper.loadInputStreamAsString(assets_manager.open(provider + ".pem"));
- providerDefinition = ConfigHelper.loadInputStreamAsString(assets_manager.open(provider + ".json"));
+ certificate = ConfigHelper.loadInputStreamAsString(assetsManager.open(provider + ".pem"));
+ providerDefinition = ConfigHelper.loadInputStreamAsString(assetsManager.open(provider + ".json"));
} catch (IOException e) {
e.printStackTrace();
}
@@ -91,11 +92,11 @@ public class ProviderManager implements AdapteeCollection<Provider> {
}
private Set<Provider> providersFromFiles(String[] files) {
- Set<Provider> providers = new HashSet<Provider>();
+ Set<Provider> providers = new HashSet<>();
try {
for (String file : files) {
- String main_url = extractMainUrlFromInputStream(new FileInputStream(externalFilesDir.getAbsolutePath() + "/" + file));
- providers.add(new Provider(new URL(main_url)));
+ String mainUrl = extractMainUrlFromInputStream(new FileInputStream(externalFilesDir.getAbsolutePath() + "/" + file));
+ providers.add(new Provider(new URL(mainUrl)));
}
} catch (MalformedURLException | FileNotFoundException e) {
e.printStackTrace();
@@ -104,12 +105,12 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return providers;
}
- private String extractMainUrlFromInputStream(InputStream input_stream) {
+ private String extractMainUrlFromInputStream(InputStream inputStream) {
String mainUrl = "";
- JSONObject file_contents = inputStreamToJson(input_stream);
- if (file_contents != null)
- mainUrl = file_contents.optString(Provider.MAIN_URL);
+ JSONObject fileContents = inputStreamToJson(inputStream);
+ if (fileContents != null)
+ mainUrl = fileContents.optString(Provider.MAIN_URL);
return mainUrl;
}
@@ -126,12 +127,13 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return json;
}
- public Set<Provider> providers() {
- Set<Provider> all_providers = new HashSet<Provider>();
- all_providers.addAll(defaultProviders);
+ public List<Provider> providers() {
+ List<Provider> allProviders = new ArrayList<>();
+ allProviders.addAll(defaultProviders);
if(customProviders != null)
- all_providers.addAll(customProviders);
- return all_providers;
+ allProviders.addAll(customProviders);
+ allProviders.add(new Provider());
+ return allProviders;
}
@Override
@@ -151,9 +153,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
@Override
public boolean add(Provider element) {
- if (!defaultProviders.contains(element))
- return customProviders.add(element);
- else return true;
+ return !defaultProviders.contains(element) || customProviders.add(element);
}
@Override
@@ -179,7 +179,7 @@ public class ProviderManager implements AdapteeCollection<Provider> {
customProviders.clear();
}
- protected void saveCustomProvidersToFile() {
+ void saveCustomProvidersToFile() {
try {
for (Provider provider : customProviders) {
File providerFile = new File(externalFilesDir, provider.getName() + ".json");
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
index 4a5d0db1..5b3e5728 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderRenderer.java
@@ -45,7 +45,11 @@ public class ProviderRenderer extends Renderer<Provider> {
@Override
public void render() {
Provider provider = getContent();
- name.setText(provider.getName());
- domain.setText(provider.getDomain());
+ if (!provider.isDefault()) {
+ name.setText(provider.getName());
+ domain.setText(provider.getDomain());
+ } else {
+ domain.setText(R.string.add_provider);
+ }
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
index f5991538..2d107c27 100644
--- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
@@ -15,6 +15,7 @@ import java.lang.annotation.RetentionPolicy;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.userstatus.User;
+import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
@@ -187,6 +188,7 @@ public class StartActivity extends Activity {
private void showMainActivity() {
Intent intent = new Intent(this, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(MainActivity.ACTION_SHOW_VPN_FRAGMENT);
startActivity(intent);
finish();
diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java b/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java
index 5b089524..459f337b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java
@@ -44,6 +44,8 @@ import static android.text.TextUtils.isEmpty;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP_BLOCKING_VPN;
+import static se.leap.bitmaskclient.EipFragment.ASK_TO_CANCEL_VPN;
+import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
/**
* Created by cyberta on 14.01.18.
@@ -86,7 +88,7 @@ public class VpnNotificationManager {
VoidVpnService.NOTIFICATION_CHANNEL_NEWSTATUS_ID,
PRIORITY_MAX,
0,
- getDashboardIntent(),
+ getMainActivityIntent(),
actionBuilder.build());
}
@@ -122,7 +124,7 @@ public class VpnNotificationManager {
if (status == LEVEL_WAITING_FOR_USER_INPUT)
contentIntent = getUserInputIntent(msg);
else
- contentIntent = getDashboardIntent();
+ contentIntent = getMainActivityIntent();
int priority;
if (OpenVPNService.NOTIFICATION_CHANNEL_NEWSTATUS_ID.equals(notificationChannelNewstatusId)) {
@@ -254,11 +256,9 @@ public class VpnNotificationManager {
lastNotificationChannel = notificationChannelNewstatusId;
}
- private PendingIntent getDashboardIntent() {
- Intent startDashboard = new Intent(context, Dashboard.class);
- startDashboard.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
- Intent.FLAG_ACTIVITY_SINGLE_TOP);
- return PendingIntent.getActivity(context, 0, startDashboard, PendingIntent.FLAG_CANCEL_CURRENT);
+ private PendingIntent getMainActivityIntent() {
+ Intent startActivity = new Intent(context, StartActivity.class);
+ return PendingIntent.getActivity(context, 0, startActivity, PendingIntent.FLAG_CANCEL_CURRENT);
}
private PendingIntent getStopVoidVpnIntent() {
@@ -268,10 +268,10 @@ public class VpnNotificationManager {
}
private PendingIntent getDisconnectIntent() {
- Intent disconnectVPN = new Intent(context, Dashboard.class);
- disconnectVPN.setAction(Intent.ACTION_MAIN); //needs to be set that actual action can get triggered
- disconnectVPN.putExtra(Dashboard.ACTION_ASK_TO_CANCEL_VPN, true);
- disconnectVPN.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ Intent disconnectVPN = new Intent(context, MainActivity.class);
+ disconnectVPN.setAction(ACTION_SHOW_VPN_FRAGMENT);
+ disconnectVPN.putExtra(ASK_TO_CANCEL_VPN, true);
+ disconnectVPN.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
return PendingIntent.getActivity(context, 0, disconnectVPN, PendingIntent.FLAG_CANCEL_CURRENT);
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
index eca5b881..23b4f2de 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -27,6 +27,8 @@ import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
+import java.lang.ref.WeakReference;
+
import de.blinkt.openvpn.LaunchVPN;
import se.leap.bitmaskclient.OnBootReceiver;
@@ -57,12 +59,12 @@ public final class EIP extends IntentService {
public final static String TAG = EIP.class.getSimpleName();
public final static String SERVICE_API_PATH = "config/eip-service.json";
- private static ResultReceiver mReceiver;
- private static SharedPreferences preferences;
+ private WeakReference<ResultReceiver> mReceiverRef = new WeakReference<>(null);
+ private SharedPreferences preferences;
- private static JSONObject eipDefinition;
+ private JSONObject eipDefinition;
private GatewaysManager gatewaysManager = new GatewaysManager();
- private static Gateway gateway;
+ private Gateway gateway;
public EIP() {
super(TAG);
@@ -80,7 +82,9 @@ public final class EIP extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
String action = intent.getAction();
- mReceiver = intent.getParcelableExtra(EIP_RECEIVER);
+ if (intent.getParcelableExtra(EIP_RECEIVER) != null) {
+ mReceiverRef = new WeakReference<>((ResultReceiver) intent.getParcelableExtra(EIP_RECEIVER));
+ }
if (action == null) {
return;
@@ -241,10 +245,10 @@ public final class EIP extends IntentService {
}
private void tellToReceiver(String action, int resultCode) {
- if (mReceiver != null) {
- Bundle resultData = new Bundle();
- resultData.putString(EIP_REQUEST, action);
- mReceiver.send(resultCode, resultData);
+ Bundle resultData = new Bundle();
+ resultData.putString(EIP_REQUEST, action);
+ if (mReceiverRef.get() != null) {
+ mReceiverRef.get().send(resultCode, resultData);
}
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
index 0f1d0cdb..4b8ce55d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
@@ -3,6 +3,7 @@ package se.leap.bitmaskclient.userstatus;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -26,7 +27,7 @@ import se.leap.bitmaskclient.R;
public class UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface {
- public static String TAG = UserStatusFragment.class.getSimpleName();
+ public final static String TAG = UserStatusFragment.class.getSimpleName();
private ProviderAPIResultReceiver providerAPI_result_receiver;
@InjectView(R.id.user_status_username)
@@ -88,7 +89,8 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia
if(status.isLoggedIn())
logOut();
else if(status.isLoggedOut())
- MainActivity.sessionDialog(Bundle.EMPTY);
+ Log.w(TAG, "implement login from here?");
+ //MainActivity.sessionDialog(Bundle.EMPTY);
else if(status.inProgress())
cancelLoginOrSignup();
}