summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-03-13 14:22:25 +0100
committerParménides GV <parmegv@sdf.org>2015-03-13 14:22:25 +0100
commit6738a3f17cb38febfa1c698d6b420aed9e17ad74 (patch)
treebcdcfd266741d27d5e42cb1473b75c0a101a41f0 /app/src
parent06b98e2c28f93f2294f3e6f88ba3812e8b8751e4 (diff)
Show user session status separately.
Switching orientation doesn't hide that information, now we have two places to avoid it.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java100
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java179
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Provider.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/User.java41
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java65
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java3
-rw-r--r--app/src/main/res/layout/dashboard.xml15
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java26
10 files changed, 309 insertions, 153 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
index fa923948..9ce0e99f 100644
--- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -49,8 +49,8 @@ public class ProviderAPI extends IntentService {
TAG = ProviderAPI.class.getSimpleName(),
SET_UP_PROVIDER = "setUpProvider",
DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
- SRP_REGISTER = "srpRegister",
- SRP_AUTH = "srpAuth",
+ SIGN_UP = "srpRegister",
+ LOG_IN = "srpAuth",
LOG_OUT = "logOut",
DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
PARAMETERS = "parameters",
@@ -118,11 +118,11 @@ public class ProviderAPI extends IntentService {
return "{ \"" + ERRORS + "\" : \""+getResources().getString(toast_string_id)+"\" }";
}
- @Override
- protected void onHandleIntent(Intent command) {
- final ResultReceiver receiver = command.getParcelableExtra(RECEIVER_KEY);
- String action = command.getAction();
- Bundle parameters = command.getBundleExtra(PARAMETERS);
+ @Override
+ protected void onHandleIntent(Intent command) {
+ final ResultReceiver receiver = command.getParcelableExtra(RECEIVER_KEY);
+ String action = command.getAction();
+ Bundle parameters = command.getBundleExtra(PARAMETERS);
if(provider_api_url == null) {
try {
JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "no provider"));
@@ -133,42 +133,48 @@ public class ProviderAPI extends IntentService {
}
}
- if(action.equalsIgnoreCase(SET_UP_PROVIDER)) {
- Bundle result = setUpProvider(parameters);
- if(go_ahead) {
- if(result.getBoolean(RESULT_KEY)) {
- receiver.send(PROVIDER_OK, result);
- } else {
- receiver.send(PROVIDER_NOK, result);
- }
- }
- } else if (action.equalsIgnoreCase(SRP_REGISTER)) {
- Bundle session_id_bundle = tryToRegister(parameters);
- if(session_id_bundle.getBoolean(RESULT_KEY)) {
- receiver.send(SUCCESSFUL_SIGNUP, session_id_bundle);
- } else {
- receiver.send(FAILED_SIGNUP, session_id_bundle);
- }
- } else if (action.equalsIgnoreCase(SRP_AUTH)) {
- Bundle session_id_bundle = tryToAuthenticate(parameters);
- if(session_id_bundle.getBoolean(RESULT_KEY)) {
- receiver.send(SUCCESSFUL_LOGIN, session_id_bundle);
- } else {
- receiver.send(FAILED_LOGIN, session_id_bundle);
- }
- } else if (action.equalsIgnoreCase(LOG_OUT)) {
- if(logOut()) {
- receiver.send(SUCCESSFUL_LOGOUT, Bundle.EMPTY);
- } else {
- receiver.send(LOGOUT_FAILED, Bundle.EMPTY);
- }
- } else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
- if(updateVpnCertificate()) {
- receiver.send(CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
- } else {
- receiver.send(INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
- }
- } else if(action.equalsIgnoreCase(DOWNLOAD_EIP_SERVICE)) {
+ if(action.equalsIgnoreCase(SET_UP_PROVIDER)) {
+ Bundle result = setUpProvider(parameters);
+ if(go_ahead) {
+ if(result.getBoolean(RESULT_KEY)) {
+ receiver.send(PROVIDER_OK, result);
+ } else {
+ receiver.send(PROVIDER_NOK, result);
+ }
+ }
+ } else if (action.equalsIgnoreCase(SIGN_UP)) {
+ Bundle result = tryToRegister(parameters);
+ if(result.getBoolean(RESULT_KEY)) {
+ receiver.send(SUCCESSFUL_SIGNUP, result);
+ } else {
+ receiver.send(FAILED_SIGNUP, result);
+ }
+ } else if (action.equalsIgnoreCase(LOG_IN)) {
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_IN);
+ Bundle result = tryToAuthenticate(parameters);
+ if(result.getBoolean(RESULT_KEY)) {
+ receiver.send(SUCCESSFUL_LOGIN, result);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_IN);
+ } else {
+ receiver.send(FAILED_LOGIN, result);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.NOT_LOGGED_IN);
+ }
+ } else if (action.equalsIgnoreCase(LOG_OUT)) {
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_OUT);
+ if(logOut()) {
+ receiver.send(SUCCESSFUL_LOGOUT, Bundle.EMPTY);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_OUT);
+ } else {
+ receiver.send(LOGOUT_FAILED, Bundle.EMPTY);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.DIDNT_LOG_OUT);
+ }
+ } else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
+ if(updateVpnCertificate()) {
+ receiver.send(CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
+ } else {
+ receiver.send(INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
+ }
+ } else if(action.equalsIgnoreCase(DOWNLOAD_EIP_SERVICE)) {
Bundle result = getAndSetEipServiceJson();
if(result.getBoolean(RESULT_KEY)) {
receiver.send(CORRECTLY_DOWNLOADED_EIP_SERVICE, result);
@@ -176,13 +182,13 @@ public class ProviderAPI extends IntentService {
receiver.send(INCORRECTLY_DOWNLOADED_EIP_SERVICE, result);
}
}
- }
+ }
private Bundle tryToRegister(Bundle task) {
Bundle result = new Bundle();
int progress = 0;
- String username = task.getString(SessionDialog.USERNAME);
+ String username = User.userName();
String password = task.getString(SessionDialog.PASSWORD);
if(validUserLoginData(username, password)) {
@@ -231,8 +237,8 @@ public class ProviderAPI extends IntentService {
private Bundle tryToAuthenticate(Bundle task) {
Bundle result = new Bundle();
int progress = 0;
-
- String username = task.getString(SessionDialog.USERNAME);
+
+ String username = User.userName();
String password = task.getString(SessionDialog.PASSWORD);
if(validUserLoginData(username, password)) {
result = authenticate(username, password);
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 04385ddd..c6ac2477 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -28,6 +28,7 @@ import android.widget.*;
import org.jetbrains.annotations.NotNull;
import org.json.*;
import java.net.*;
+import java.util.*;
import butterknife.*;
import de.blinkt.openvpn.activities.*;
@@ -40,7 +41,7 @@ import se.leap.bitmaskclient.eip.*;
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author parmegv
*/
-public class Dashboard extends Activity implements SessionDialog.SessionDialogInterface, ProviderAPIResultReceiver.Receiver {
+public class Dashboard extends Activity implements SessionDialog.SessionDialogInterface, ProviderAPIResultReceiver.Receiver, Observer {
protected static final int CONFIGURE_LEAP = 0;
protected static final int SWITCH_PROVIDER = 1;
@@ -60,46 +61,63 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
@InjectView(R.id.providerName)
TextView provider_name;
+ @InjectView(R.id.user_session_status)
+ TextView user_session_status_text_view;
EipFragment eip_fragment;
private Provider provider;
+ private UserSessionStatus user_session_status;
public ProviderAPIResultReceiver providerAPI_result_receiver;
private boolean switching_provider;
@Override
protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- app = this;
+ super.onCreate(savedInstanceState);
- PRNGFixes.apply();
+ app = this;
+ user_session_status = UserSessionStatus.getInstance();
+ user_session_status.addObserver(this);
- preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
- handleVersion();
+ PRNGFixes.apply();
- provider = getSavedProvider(savedInstanceState);
+ preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
+ fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
+ handleVersion();
+
+ restoreProvider(savedInstanceState);
if (provider == null || provider.getName().isEmpty())
- startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
- else
- buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
+ startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
+ else {
+ buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
+ restoreSessionStatus(savedInstanceState);
+ }
+ }
+
+ private void restoreProvider(Bundle savedInstanceState) {
+ if (savedInstanceState != null) {
+ if(savedInstanceState.containsKey(Provider.KEY))
+ provider = savedInstanceState.getParcelable(Provider.KEY);
+ if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
+ provider = getSavedProviderFromSharedPreferences();
+ }
+ }
+
+ private void restoreSessionStatus(Bundle savedInstanceState) {
+ if (savedInstanceState != null)
+ if(savedInstanceState.containsKey(UserSessionStatus.TAG)) {
+ UserSessionStatus.SessionStatus status = (UserSessionStatus.SessionStatus) savedInstanceState.getSerializable(UserSessionStatus.TAG);
+ user_session_status.updateStatus(status);
+ }
}
@Override
protected void onSaveInstanceState(@NotNull Bundle outState) {
if(provider != null)
outState.putParcelable(Provider.KEY, provider);
- super.onSaveInstanceState(outState);
- }
+ if(user_session_status_text_view != null && user_session_status_text_view.getVisibility() == TextView.VISIBLE)
+ outState.putSerializable(UserSessionStatus.TAG, user_session_status.sessionStatus());
- private Provider getSavedProvider(Bundle savedInstanceState) {
- Provider provider = null;
- if(savedInstanceState != null)
- provider = savedInstanceState.getParcelable(Provider.KEY);
- else if(preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
- provider = getSavedProviderFromSharedPreferences();
-
- return provider;
+ super.onSaveInstanceState(outState);
}
private Provider getSavedProviderFromSharedPreferences() {
@@ -107,9 +125,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
try {
provider = new Provider(new URL(preferences.getString(Provider.MAIN_URL, "")));
provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (JSONException e) {
+ } catch (MalformedURLException | JSONException e) {
e.printStackTrace();
}
@@ -136,8 +152,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
- if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
- if ( resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) {
+ if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
+ if ( resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) {
provider = data.getParcelableExtra(Provider.KEY);
providerToPreferences(provider);
@@ -147,13 +163,13 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
sessionDialog(Bundle.EMPTY);
}
- } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) {
+ } else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) {
finish();
- } else
- configErrorDialog();
- } else if(requestCode == EIP.DISCONNECT) {
- EipStatus.getInstance().setConnectedOrDisconnected();
- }
+ } else
+ configErrorDialog();
+ } else if(requestCode == EIP.DISCONNECT) {
+ EipStatus.getInstance().setConnectedOrDisconnected();
+ }
}
@SuppressLint("CommitPrefEdits")
@@ -190,55 +206,39 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
* service dependent UI elements to include.
*/
private void buildDashboard(boolean hide_and_turn_on_eip) {
- setContentView(R.layout.dashboard);
+ setContentView(R.layout.dashboard);
ButterKnife.inject(this);
- provider_name.setText(provider.getDomain());
- if ( provider.hasEIP()){
+ provider_name.setText(provider.getDomain());
+ if ( provider.hasEIP()){
fragment_manager.removePreviousFragment(EipFragment.TAG);
eip_fragment = new EipFragment();
- if (hide_and_turn_on_eip) {
- preferences.edit().remove(Dashboard.START_ON_BOOT).apply();
- Bundle arguments = new Bundle();
- arguments.putBoolean(EipFragment.START_ON_BOOT, true);
+ if (hide_and_turn_on_eip) {
+ preferences.edit().remove(Dashboard.START_ON_BOOT).apply();
+ Bundle arguments = new Bundle();
+ arguments.putBoolean(EipFragment.START_ON_BOOT, true);
if(eip_fragment != null) eip_fragment.setArguments(arguments);
- }
+ }
fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipFragment.TAG);
- if (hide_and_turn_on_eip) {
- onBackPressed();
- }
- }
+ if (hide_and_turn_on_eip) {
+ onBackPressed();
+ }
+ }
+ handleNewUserSessionStatus(user_session_status);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- JSONObject provider_json;
- try {
- String provider_json_string = preferences.getString(Provider.KEY, "");
- if(!provider_json_string.isEmpty()) {
- provider_json = new JSONObject(provider_json_string);
- JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
- boolean allow_registered_eip = service_description.getBoolean(Provider.ALLOW_REGISTRATION);
- preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, allow_registered_eip).apply();
-
- if(allow_registered_eip) {
- if(LeapSRPSession.loggedIn()) {
- menu.findItem(R.id.login_button).setVisible(false);
- menu.findItem(R.id.logout_button).setVisible(true);
- } else {
- menu.findItem(R.id.login_button).setVisible(true);
- menu.findItem(R.id.logout_button).setVisible(false);
- }
- menu.findItem(R.id.signup_button).setVisible(true);
- }
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
+ if(provider.allowsRegistration()) {
+ menu.findItem(R.id.signup_button).setVisible(true);
+
+ boolean logged_in = User.loggedIn();
+ menu.findItem(R.id.login_button).setVisible(!logged_in);
+ menu.findItem(R.id.logout_button).setVisible(logged_in);
+ }
+ return true;
}
@Override
@@ -282,25 +282,50 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
public void showLog() {
Intent startLW = new Intent(getAppContext(), LogWindow.class);
- //startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(startLW);
}
@Override
public void signUp(String username, String password) {
- Bundle parameters = bundleParameters(username, password);
- providerApiCommand(parameters, R.string.signingup_message, ProviderAPI.SRP_REGISTER);
+ User.setUserName(username);
+ Bundle parameters = bundlePassword(password);
+ providerApiCommand(parameters, R.string.signingup_message, ProviderAPI.SIGN_UP);
}
@Override
public void logIn(String username, String password) {
- Bundle parameters = bundleParameters(username, password);
- providerApiCommand(parameters, R.string.authenticating_message, ProviderAPI.SRP_AUTH);
+ User.setUserName(username);
+ Bundle parameters = bundlePassword(password);
+ providerApiCommand(parameters, R.string.authenticating_message, ProviderAPI.LOG_IN);
}
public void logOut() {
providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT);
}
+
+ @Override
+ public void update (Observable observable, Object data) {
+ if(observable instanceof UserSessionStatus) {
+ UserSessionStatus status = (UserSessionStatus) observable;
+ handleNewUserSessionStatus(status);
+ }
+ }
+
+ private void handleNewUserSessionStatus(UserSessionStatus status) {
+ user_session_status = status;
+ if(provider.allowsRegistration())
+ changeSessionStatusMessage(user_session_status.toString());
+ }
+
+ private void changeSessionStatusMessage(final String message) {
+ Log.d(TAG, message);
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ user_session_status_text_view.setText(message);
+ }
+ });
+ }
protected void downloadVpnCertificate() {
boolean is_authenticated = LeapSRPSession.loggedIn();
@@ -312,10 +337,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
- private Bundle bundleParameters(String username, String password) {
+ private Bundle bundlePassword(String password) {
Bundle parameters = new Bundle();
- if(!username.isEmpty())
- parameters.putString(SessionDialog.USERNAME, username);
if(!password.isEmpty())
parameters.putString(SessionDialog.PASSWORD, password);
return parameters;
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 6dbdf961..e152df46 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -23,6 +23,8 @@ import android.util.*;
import android.view.*;
import android.widget.*;
+import org.jetbrains.annotations.NotNull;
+
import java.util.*;
import butterknife.*;
@@ -80,18 +82,20 @@ public class EipFragment extends Fragment implements Observer {
Bundle arguments = getArguments();
if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT))
startEipFromScratch();
+ if(savedInstanceState != null) restoreState(savedInstanceState);
- if (savedInstanceState != null) {
- status_message.setText(savedInstanceState.getString(STATUS_MESSAGE));
- if(savedInstanceState.getBoolean(IS_PENDING))
- eip_status.setConnecting();
- else if(savedInstanceState.getBoolean(IS_CONNECTED)) {
- eip_status.setConnectedOrDisconnected();
- }
- }
return view;
}
+ private void restoreState(@NotNull Bundle savedInstanceState) {
+ if(savedInstanceState.getBoolean(IS_PENDING))
+ eip_status.setConnecting();
+ else if(savedInstanceState.getBoolean(IS_CONNECTED))
+ eip_status.setConnectedOrDisconnected();
+ else
+ status_message.setText(savedInstanceState.getString(STATUS_MESSAGE));
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -103,14 +107,12 @@ public class EipFragment extends Fragment implements Observer {
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(IS_PENDING, eip_status.isConnecting());
outState.putBoolean(IS_CONNECTED, eip_status.isConnected());
- Log.d(TAG, "status message onSaveInstanceState = " + status_message.getText().toString());
outState.putString(STATUS_MESSAGE, status_message.getText().toString());
super.onSaveInstanceState(outState);
}
protected void saveStatus() {
boolean is_on = eip_switch.isChecked();
- Log.d(TAG, "saveStatus: is_on = " + is_on);
Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit();
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java
index 09855baf..49c115ae 100644
--- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java
+++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java
@@ -44,7 +44,8 @@ public class LeapSRPSession {
final public static String TOKEN = "token";
final public static String AUTHORIZATION_HEADER= "Authorization";
final public static String TAG= "Leap SRP session class tag";
-
+
+ private User user;
private SRPParameters params;
private String username;
private String password;
diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java
index d7ff6633..ef25c5d2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java
@@ -172,6 +172,14 @@ public final class Provider implements Parcelable {
return false;
}
+ public boolean allowsRegistration() {
+ try {
+ return definition.getJSONObject(Provider.SERVICE).getBoolean(Provider.ALLOW_REGISTRATION);
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+
@Override
public int describeContents() {
return 0;
diff --git a/app/src/main/java/se/leap/bitmaskclient/User.java b/app/src/main/java/se/leap/bitmaskclient/User.java
new file mode 100644
index 00000000..e05a0573
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/User.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2013 LEAP Encryption Access Project and contributers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package se.leap.bitmaskclient;
+
+public class User {
+ private static String user_name = "The user";
+ private static User user;
+
+ public static User getInstance() {
+ if(user == null) {
+ user = new User();
+ }
+ return user;
+ }
+
+ public static void setUserName(String user_name) {
+ User.user_name = user_name;
+ }
+
+ private User() { }
+
+ public static String userName() { return user_name; }
+
+ public static boolean loggedIn() {
+ return LeapSRPSession.loggedIn();
+ }
+}
diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java
new file mode 100644
index 00000000..bab57d04
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright (c) 2013 LEAP Encryption Access Project and contributers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package se.leap.bitmaskclient;
+
+import android.os.*;
+
+import java.util.*;
+
+public class UserSessionStatus extends Observable {
+ public static String TAG = UserSessionStatus.class.getSimpleName();
+ private static UserSessionStatus current_status;
+
+ public enum SessionStatus {
+ LOGGED_IN,
+ LOGGED_OUT,
+ NOT_LOGGED_IN,
+ DIDNT_LOG_OUT,
+ LOGGING_IN,
+ LOGGING_OUT
+ }
+
+ private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN;
+
+ public static UserSessionStatus getInstance() {
+ if(current_status == null) {
+ current_status = new UserSessionStatus();
+ }
+ return current_status;
+ }
+
+ private UserSessionStatus() { }
+
+ private void sessionStatus(SessionStatus session_status) {
+ this.session_status = session_status;
+ }
+
+ public SessionStatus sessionStatus() { return session_status; }
+
+ public static void updateStatus(SessionStatus session_status) {
+ current_status = getInstance();
+ current_status.sessionStatus(session_status);
+ current_status.setChanged();
+ current_status.notifyObservers();
+ }
+
+ @Override
+ public String toString() {
+ return User.userName() + " is "
+ + session_status.toString().toLowerCase().replaceAll("_", " ");
+ }
+}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index 0c773208..0a707ab1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -42,7 +42,8 @@ public class VoidVpnService extends VpnService {
public static boolean stop() {
try {
- fd.close();
+ if(fd != null)
+ fd.close();
return true;
} catch (IOException | NullPointerException e) {
android.util.Log.d(TAG, "VoidVpnService didn't stop");
diff --git a/app/src/main/res/layout/dashboard.xml b/app/src/main/res/layout/dashboard.xml
index 67a1122f..4a9dd502 100644
--- a/app/src/main/res/layout/dashboard.xml
+++ b/app/src/main/res/layout/dashboard.xml
@@ -16,7 +16,6 @@
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:ellipsize="marquee"
- android:fadingEdge="horizontal"
android:singleLine="true"
android:text="@string/provider_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
@@ -28,18 +27,22 @@
android:textSize="28sp"
android:layout_marginLeft="10dp"
android:ellipsize="marquee"
- android:fadingEdge="horizontal"
android:singleLine="true"
android:text="@string/provider_label_none"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
- <View
+ <TextView
+ android:id="@+id/user_session_status"
android:layout_width="wrap_content"
- android:layout_height="2dp"
- android:layout_marginBottom="15dp"
- android:background="@android:drawable/divider_horizontal_bright" />
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="10dp"
+ android:ellipsize="marquee"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ />
<LinearLayout
android:id="@+id/servicesCollection"
diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
index c8efe0de..184173b2 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -31,8 +31,8 @@ import javax.net.ssl.*;
import org.apache.http.client.ClientProtocolException;
import org.json.*;
+import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
import se.leap.bitmaskclient.eip.*;
-
/**
* Implements HTTP api methods used to manage communications with the provider server.
*
@@ -48,8 +48,8 @@ public class ProviderAPI extends IntentService {
TAG = ProviderAPI.class.getSimpleName(),
SET_UP_PROVIDER = "setUpProvider",
DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
- SRP_REGISTER = "srpRegister",
- SRP_AUTH = "srpAuth",
+ SIGN_UP = "srpRegister",
+ LOG_IN = "srpAuth",
LOG_OUT = "logOut",
DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
PARAMETERS = "parameters",
@@ -137,25 +137,31 @@ public class ProviderAPI extends IntentService {
receiver.send(PROVIDER_NOK, result);
}
}
- } else if (action.equalsIgnoreCase(SRP_REGISTER)) {
+ } else if (action.equalsIgnoreCase(SIGN_UP)) {
Bundle result = tryToRegister(parameters);
if(result.getBoolean(RESULT_KEY)) {
receiver.send(SUCCESSFUL_SIGNUP, result);
} else {
receiver.send(FAILED_SIGNUP, result);
}
- } else if (action.equalsIgnoreCase(SRP_AUTH)) {
+ } else if (action.equalsIgnoreCase(LOG_IN)) {
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_IN);
Bundle result = tryToAuthenticate(parameters);
if(result.getBoolean(RESULT_KEY)) {
- receiver.send(SUCCESSFUL_LOGIN, result);
+ receiver.send(SUCCESSFUL_LOGIN, result);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_IN);
} else {
- receiver.send(FAILED_LOGIN, result);
+ receiver.send(FAILED_LOGIN, result);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.NOT_LOGGED_IN);
}
} else if (action.equalsIgnoreCase(LOG_OUT)) {
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGING_OUT);
if(logOut()) {
receiver.send(SUCCESSFUL_LOGOUT, Bundle.EMPTY);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.LOGGED_OUT);
} else {
receiver.send(LOGOUT_FAILED, Bundle.EMPTY);
+ UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.DIDNT_LOG_OUT);
}
} else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
if(updateVpnCertificate()) {
@@ -177,7 +183,7 @@ public class ProviderAPI extends IntentService {
Bundle result = new Bundle();
int progress = 0;
- String username = task.getString(SessionDialog.USERNAME);
+ String username = User.userName();
String password = task.getString(SessionDialog.PASSWORD);
if(validUserLoginData(username, password)) {
@@ -228,8 +234,8 @@ public class ProviderAPI extends IntentService {
Bundle result = new Bundle();
int progress = 0;
- String username = (String) task.get(SessionDialog.USERNAME);
- String password = (String) task.get(SessionDialog.PASSWORD);
+ String username = User.userName();
+ String password = task.getString(SessionDialog.PASSWORD);
if(validUserLoginData(username, password)) {
result = authenticate(username, password);
broadcastProgress(progress++);