From bb2a944265da15eeba35106f2e2bcda288855527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 15:07:55 +0100 Subject: Show browser warning on disconnect. Also reindent some code. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 2 +- .../java/se/leap/bitmaskclient/EipFragment.java | 428 +++++++++++---------- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 144 +++---- app/src/main/res/values/strings.xml | 1 + 4 files changed, 298 insertions(+), 277 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index face6ced..a8f6e110 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -407,7 +407,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } private void switchProvider() { - if (provider.hasEIP()) eip_fragment.askToStopEIP(); + if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); preferences.edit().clear().apply(); switching_provider = false; diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 2057a80b..5e5b76b2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -1,6 +1,6 @@ /** * 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 @@ -32,7 +32,7 @@ import de.blinkt.openvpn.activities.*; import se.leap.bitmaskclient.eip.*; public class EipFragment extends Fragment implements Observer { - + public static String TAG = EipFragment.class.getSimpleName(); protected static final String IS_PENDING = TAG + ".is_pending"; @@ -55,36 +55,36 @@ public class EipFragment extends Fragment implements Observer { @Override public void onAttach(Activity activity) { - super.onAttach(activity); + super.onAttach(activity); dashboard = (Dashboard) activity; dashboard.providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.DOWNLOAD_EIP_SERVICE); } - + @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - eip_status = EipStatus.getInstance(); - eip_status.addObserver(this); - mEIPReceiver = new EIPReceiver(new Handler()); + super.onCreate(savedInstanceState); + eip_status = EipStatus.getInstance(); + eip_status.addObserver(this); + mEIPReceiver = new EIPReceiver(new Handler()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.eip_service_fragment, container, false); + View view = inflater.inflate(R.layout.eip_service_fragment, container, false); ButterKnife.inject(this, view); - if (eip_status.isConnecting()) - eip_switch.setVisibility(View.VISIBLE); + if (eip_status.isConnecting()) + eip_switch.setVisibility(View.VISIBLE); - Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked()); + Log.d(TAG, "onCreateView, eip_switch is checked? " + eip_switch.isChecked()); Bundle arguments = getArguments(); - if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) - startEipFromScratch(); - if(savedInstanceState != null) restoreState(savedInstanceState); + if(arguments != null && arguments.containsKey(START_ON_BOOT) && arguments.getBoolean(START_ON_BOOT)) + startEipFromScratch(); + if(savedInstanceState != null) restoreState(savedInstanceState); - return view; + return view; } private void restoreState(@NotNull Bundle savedInstanceState) { @@ -98,22 +98,22 @@ public class EipFragment extends Fragment implements Observer { @Override public void onResume() { - super.onResume(); - eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); - handleNewState(eip_status); + super.onResume(); + eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); + handleNewState(eip_status); } - + @Override public void onSaveInstanceState(Bundle outState) { - outState.putBoolean(IS_PENDING, eip_status.isConnecting()); - outState.putBoolean(IS_CONNECTED, eip_status.isConnected()); - outState.putString(STATUS_MESSAGE, status_message.getText().toString()); - super.onSaveInstanceState(outState); + outState.putBoolean(IS_PENDING, eip_status.isConnecting()); + outState.putBoolean(IS_CONNECTED, eip_status.isConnected()); + outState.putString(STATUS_MESSAGE, status_message.getText().toString()); + super.onSaveInstanceState(outState); } protected void saveStatus() { - boolean is_on = eip_switch.isChecked(); - Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); + boolean is_on = eip_switch.isChecked(); + Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, is_on).commit(); } void handleNewVpnCertificate() { @@ -122,251 +122,271 @@ public class EipFragment extends Fragment implements Observer { @OnCheckedChanged(R.id.eipSwitch) void handleSwitch(boolean isChecked) { - if(isChecked) - handleSwitchOn(); - else - handleSwitchOff(); - - saveStatus(); + if(isChecked) + handleSwitchOn(); + else + handleSwitchOff(); + + saveStatus(); } private void handleSwitchOn() { - if(canStartEIP()) - startEipFromScratch(); - else if(canLogInToStartEIP()) { - wants_to_connect = true; - Bundle bundle = new Bundle(); - bundle.putBoolean(IS_PENDING, true); - dashboard.sessionDialog(bundle); - } - } - + if(canStartEIP()) + startEipFromScratch(); + else if(canLogInToStartEIP()) { + wants_to_connect = true; + Bundle bundle = new Bundle(); + bundle.putBoolean(IS_PENDING, true); + dashboard.sessionDialog(bundle); + } + } + private boolean canStartEIP() { - boolean certificateExists = !Dashboard.preferences.getString(Constants.CERTIFICATE, "").isEmpty(); - boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); - return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); + boolean certificateExists = !Dashboard.preferences.getString(Constants.CERTIFICATE, "").isEmpty(); + boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); + return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); } - + private boolean canLogInToStartEIP() { - boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.ALLOWED_REGISTERED, false); - boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); - Log.d(TAG, "Allow registered? " + isAllowedRegistered); - Log.d(TAG, "Is logged in? " + isLoggedIn); - return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); + boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.ALLOWED_REGISTERED, false); + boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); + Log.d(TAG, "Allow registered? " + isAllowedRegistered); + Log.d(TAG, "Is logged in? " + isLoggedIn); + return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } private void handleSwitchOff() { - if(eip_status.isConnecting()) { - askPendingStartCancellation(); - } else if(eip_status.isConnected()) { - askToStopEIP(); - } else - setDisconnectedUI(); - } - - private void askPendingStartCancellation() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); - alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) - .setMessage(dashboard.getString(R.string.eip_cancel_connect_text)) - .setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - askToStopEIP(); - } - }) - .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - eip_switch.setChecked(true); - } - }) - .show(); + if(eip_status.isConnecting()) { + askPendingStartCancellation(); + } else if(eip_status.isConnected()) { + askToStopEIP(); + } else + setDisconnectedUI(); + } + + private void askPendingStartCancellation() { + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); + alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) + .setMessage(dashboard.getString(R.string.eip_cancel_connect_text)) + .setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + askToStopEIP(); + } + }) + .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + eip_switch.setChecked(true); + } + }) + .show(); } public void startEipFromScratch() { wants_to_connect = false; is_starting_to_connect = true; progress_bar.setVisibility(View.VISIBLE); - eip_switch.setVisibility(View.VISIBLE); - String status = dashboard.getString(R.string.eip_status_start_pending); - status_message.setText(status); - - if(!eip_switch.isChecked()) { - eip_switch.setChecked(true); - } + eip_switch.setVisibility(View.VISIBLE); + String status = dashboard.getString(R.string.eip_status_start_pending); + status_message.setText(status); + + if(!eip_switch.isChecked()) { + eip_switch.setChecked(true); + } saveStatus(); - eipCommand(Constants.ACTION_START_EIP); + eipCommand(Constants.ACTION_START_EIP); } - private void stopEIP() { - if(eip_status.isConnecting()) - VoidVpnService.stop(); - disconnect(); + private void stop() { + if(eip_status.isConnecting()) + VoidVpnService.stop(); + disconnect(); } private void disconnect() { - Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); - dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); - eip_status.setDisconnecting(); + Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); + dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); + eip_status.setDisconnecting(); } - protected void askToStopEIP() { + protected void stopEipIfPossible() { + hideProgressBar(); - String message = dashboard.getString(R.string.eip_state_not_connected); - status_message.setText(message); + String message = dashboard.getString(R.string.eip_state_not_connected); + status_message.setText(message); + + eipCommand(Constants.ACTION_STOP_EIP); + } - eipCommand(Constants.ACTION_STOP_EIP); + private void askToStopEIP() { + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); + alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) + .setMessage(dashboard.getString(R.string.eip_warning_browser_inconsistency)) + .setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + stopEipIfPossible(); + } + }) + .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + eip_switch.setChecked(true); + } + }) + .show(); } protected void updateEipService() { eipCommand(Constants.ACTION_UPDATE_EIP_SERVICE); } - + /** * Send a command to EIP - * + * * @param action A valid String constant from EIP class representing an Intent * filter for the EIP class */ private void eipCommand(String action){ - // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? - Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); - vpn_intent.setAction(action); - vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver); - dashboard.startService(vpn_intent); + // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? + Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); + vpn_intent.setAction(action); + vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver); + dashboard.startService(vpn_intent); } - + @Override public void update (Observable observable, Object data) { - if(observable instanceof EipStatus) { - eip_status = (EipStatus) observable; - final EipStatus eip_status = (EipStatus) observable; - dashboard.runOnUiThread(new Runnable() { - @Override - public void run() { - handleNewState(eip_status); - } - }); - } + if(observable instanceof EipStatus) { + eip_status = (EipStatus) observable; + final EipStatus eip_status = (EipStatus) observable; + dashboard.runOnUiThread(new Runnable() { + @Override + public void run() { + handleNewState(eip_status); + } + }); + } } private void handleNewState(EipStatus eip_status) { - if(eip_status.wantsToDisconnect()) - setDisconnectedUI(); - else if(eip_status.isConnecting() || is_starting_to_connect) - setInProgressUI(eip_status); - else if (eip_status.isConnected()) - setConnectedUI(); - else if (eip_status.isDisconnected() && !eip_status.isConnecting()) - setDisconnectedUI(); + if(eip_status.wantsToDisconnect()) + setDisconnectedUI(); + else if(eip_status.isConnecting() || is_starting_to_connect) + setInProgressUI(eip_status); + else if (eip_status.isConnected()) + setConnectedUI(); + else if (eip_status.isDisconnected() && !eip_status.isConnecting()) + setDisconnectedUI(); } private void setConnectedUI() { - hideProgressBar(); - Log.d(TAG, "setConnectedUi? " + eip_status.isConnected()); - adjustSwitch(); - is_starting_to_connect = false; - status_message.setText(dashboard.getString(R.string.eip_state_connected)); + hideProgressBar(); + Log.d(TAG, "setConnectedUi? " + eip_status.isConnected()); + adjustSwitch(); + is_starting_to_connect = false; + status_message.setText(dashboard.getString(R.string.eip_state_connected)); } private void setDisconnectedUI(){ - hideProgressBar(); - adjustSwitch(); - String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); - if((last_log_message.contains("error") || last_log_message.contains("ERROR")) - && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ - dashboard.showLog(); - } + hideProgressBar(); + adjustSwitch(); + String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); + if((last_log_message.contains("error") || last_log_message.contains("ERROR")) + && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ + dashboard.showLog(); + } status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { - if(eip_status.isConnected() || eip_status.isConnecting() || is_starting_to_connect) { - Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked"); - if(!eip_switch.isChecked()) { - eip_switch.setChecked(true); - } - } else { - Log.d(TAG, "adjustSwitch, !isConnected && !isConnecting? " + eip_status.toString()); + if(eip_status.isConnected() || eip_status.isConnecting() || is_starting_to_connect) { + Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked"); + if(!eip_switch.isChecked()) { + eip_switch.setChecked(true); + } + } else { + Log.d(TAG, "adjustSwitch, !isConnected && !isConnecting? " + eip_status.toString()); - if(eip_switch.isChecked()) { - eip_switch.setChecked(false); - } - } + if(eip_switch.isChecked()) { + eip_switch.setChecked(false); + } + } } private void setInProgressUI(EipStatus eip_status) { - int localizedResId = eip_status.getLocalizedResId(); - String logmessage = eip_status.getLogMessage(); - String prefix = dashboard.getString(localizedResId); + int localizedResId = eip_status.getLocalizedResId(); + String logmessage = eip_status.getLogMessage(); + String prefix = dashboard.getString(localizedResId); - showProgressBar(); - status_message.setText(prefix + " " + logmessage); + showProgressBar(); + status_message.setText(prefix + " " + logmessage); is_starting_to_connect = false; - adjustSwitch(); + adjustSwitch(); } private void updatingCertificateUI() { - showProgressBar(); + showProgressBar(); status_message.setText(getString(R.string.updating_certificate_message)); } private void showProgressBar() { - if(progress_bar != null) - progress_bar.setVisibility(View.VISIBLE); + if(progress_bar != null) + progress_bar.setVisibility(View.VISIBLE); } private void hideProgressBar() { - if(progress_bar != null) - progress_bar.setVisibility(View.GONE); - } - - protected class EIPReceiver extends ResultReceiver { - - protected EIPReceiver(Handler handler){ - super(handler); - } - - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - super.onReceiveResult(resultCode, resultData); - - String request = resultData.getString(Constants.REQUEST_TAG); - - if (request.equals(Constants.ACTION_START_EIP)) { - switch (resultCode){ - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - - break; - } - } else if (request.equals(Constants.ACTION_STOP_EIP)) { - switch (resultCode){ - case Activity.RESULT_OK: - stopEIP(); - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.EIP_NOTIFICATION)) { - switch (resultCode){ - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { - switch (resultCode) { - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - updatingCertificateUI(); - dashboard.downloadVpnCertificate(); - break; - } - } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { + if(progress_bar != null) + progress_bar.setVisibility(View.GONE); + } + +protected class EIPReceiver extends ResultReceiver { + + protected EIPReceiver(Handler handler){ + super(handler); + } + + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + super.onReceiveResult(resultCode, resultData); + + String request = resultData.getString(Constants.REQUEST_TAG); + + if (request.equals(Constants.ACTION_START_EIP)) { + switch (resultCode){ + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + + break; + } + } else if (request.equals(Constants.ACTION_STOP_EIP)) { + switch (resultCode){ + case Activity.RESULT_OK: + stop(); + break; + case Activity.RESULT_CANCELED: + break; + } + } else if (request.equals(Constants.EIP_NOTIFICATION)) { + switch (resultCode){ + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + break; + } + } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + updatingCertificateUI(); + dashboard.downloadVpnCertificate(); + break; + } + } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { switch (resultCode) { case Activity.RESULT_OK: if(wants_to_connect) @@ -377,11 +397,11 @@ public class EipFragment extends Fragment implements Observer { break; } } - } } +} public static EIPReceiver getReceiver() { - return mEIPReceiver; + return mEIPReceiver; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 6f260f55..5f5dcabd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -1,6 +1,6 @@ /** * 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 @@ -37,79 +37,79 @@ public class VpnConfigGenerator { private final String new_line = System.getProperty("line.separator"); // Platform new line public VpnConfigGenerator(JSONObject general_configuration, JSONObject secrets, JSONObject gateway) { - this.general_configuration = general_configuration; - this.gateway = gateway; + this.general_configuration = general_configuration; + this.gateway = gateway; this.secrets = secrets; } - + public String generate() { - return - generalConfiguration() - + new_line - + gatewayConfiguration() - + new_line - + secretsConfiguration() - + new_line - + androidCustomizations(); + return + generalConfiguration() + + new_line + + gatewayConfiguration() + + new_line + + secretsConfiguration() + + new_line + + androidCustomizations(); } private String generalConfiguration() { - String common_options = ""; - try { - Iterator keys = general_configuration.keys(); - while ( keys.hasNext() ){ - String key = keys.next().toString(); - - common_options += key + " "; - for ( String word : general_configuration.getString(key).split(" ") ) - common_options += word + " "; - common_options += new_line; - - } - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - common_options += "client"; - - return common_options; + String common_options = ""; + try { + Iterator keys = general_configuration.keys(); + while ( keys.hasNext() ){ + String key = keys.next().toString(); + + common_options += key + " "; + for (String word : general_configuration.getString(key).split(" ")) + common_options += word + " "; + common_options += new_line; + + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + common_options += "client"; + + return common_options; } - + private String gatewayConfiguration() { - String remotes = ""; - - String ip_address_keyword = "ip_address"; - String remote_keyword = "remote"; - String ports_keyword = "ports"; - String protocol_keyword = "protocols"; - String capabilities_keyword = "capabilities"; - String udp = "udp"; - - try { - String ip_address = gateway.getString(ip_address_keyword); - JSONObject capabilities = gateway.getJSONObject(capabilities_keyword); - JSONArray ports = capabilities.getJSONArray(ports_keyword); - for (int i=0; iInitiating connection Cancel connection? There is a connection attempt in progress. Do you wish to cancel it? + In order to avoid leaking your personal information, please close your browser and start a private window after disconnecting the Encrypted VPN Internet Access. Thanks. Yes No "Not running! Connection not secure!" -- cgit v1.2.3 From 6dfae9951be275ccf33a05f4980a977b5b634e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 15:27:28 +0100 Subject: Don't show user session progress in the eip fragment --- app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java | 1 + app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 6 +++--- app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java | 3 ++- app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index 9ce0e99f..47451a70 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -143,6 +143,7 @@ public class ProviderAPI extends IntentService { } } } else if (action.equalsIgnoreCase(SIGN_UP)) { + UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.SIGNING_UP); Bundle result = tryToRegister(parameters); if(result.getBoolean(RESULT_KEY)) { receiver.send(SUCCESSFUL_SIGNUP, result); diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index a8f6e110..c043821f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -291,18 +291,18 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void signUp(String username, String password) { User.setUserName(username); Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, R.string.signingup_message, ProviderAPI.SIGN_UP); + providerApiCommand(parameters, 0, ProviderAPI.SIGN_UP); } @Override public void logIn(String username, String password) { User.setUserName(username); Bundle parameters = bundlePassword(password); - providerApiCommand(parameters, R.string.authenticating_message, ProviderAPI.LOG_IN); + providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); } public void logOut() { - providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT); + providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java index f533819b..db432a82 100644 --- a/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/UserSessionStatus.java @@ -30,7 +30,8 @@ public class UserSessionStatus extends Observable { NOT_LOGGED_IN, DIDNT_LOG_OUT, LOGGING_IN, - LOGGING_OUT + LOGGING_OUT, + SIGNING_UP } private static SessionStatus session_status = SessionStatus.NOT_LOGGED_IN; diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java index 184173b2..3117ea6f 100644 --- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java @@ -138,6 +138,7 @@ public class ProviderAPI extends IntentService { } } } else if (action.equalsIgnoreCase(SIGN_UP)) { + UserSessionStatus.updateStatus(UserSessionStatus.SessionStatus.SIGNING_UP); Bundle result = tryToRegister(parameters); if(result.getBoolean(RESULT_KEY)) { receiver.send(SUCCESSFUL_SIGNUP, result); -- cgit v1.2.3 From 2c44ba2678c6b3367a119d1e857dd5d5723f7681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 15:56:30 +0100 Subject: Warn riseup users about credentials, as an error in the username field. I haven't still decided how to show that warning, I'm talking to gus about it. This is just the first idea, but the core mechanism is implemented at least. --- app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java | 8 ++++---- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 2 ++ app/src/main/java/se/leap/bitmaskclient/SessionDialog.java | 13 +++++++++---- app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java | 8 ++++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java index 47451a70..57c4d067 100644 --- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java @@ -199,11 +199,11 @@ public class ProviderAPI extends IntentService { if(!wellFormedPassword(password)) { result.putBoolean(RESULT_KEY, false); result.putString(SessionDialog.USERNAME, username); - result.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); + result.putBoolean(SessionDialog.ERRORS.PASSWORD_INVALID_LENGTH.toString(), true); } if(!validUsername(username)) { result.putBoolean(RESULT_KEY, false); - result.putBoolean(SessionDialog.USERNAME_MISSING, true); + result.putBoolean(SessionDialog.ERRORS.USERNAME_MISSING.toString(), true); } } @@ -248,11 +248,11 @@ public class ProviderAPI extends IntentService { if(!wellFormedPassword(password)) { result.putBoolean(RESULT_KEY, false); result.putString(SessionDialog.USERNAME, username); - result.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); + result.putBoolean(SessionDialog.ERRORS.PASSWORD_INVALID_LENGTH.toString(), true); } if(!validUsername(username)) { result.putBoolean(RESULT_KEY, false); - result.putBoolean(SessionDialog.USERNAME_MISSING, true); + result.putBoolean(SessionDialog.ERRORS.USERNAME_MISSING.toString(), true); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index c043821f..14d79bc0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -426,6 +426,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { downloadVpnCertificate(); } else if(resultCode == ProviderAPI.FAILED_LOGIN) { + if(provider.getName().equalsIgnoreCase("riseup")) + resultData.putBoolean(SessionDialog.ERRORS.CONFUSING_CREDENTIALS.toString(), true); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { if(switching_provider) switchProvider(); diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index 9025564b..e32bca8e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -48,8 +48,11 @@ public class SessionDialog extends DialogFragment{ final public static String USERNAME = "username"; final public static String PASSWORD = "password"; - final public static String USERNAME_MISSING = "username missing"; - final public static String PASSWORD_INVALID_LENGTH = "password_invalid_length"; + public static enum ERRORS { + USERNAME_MISSING, + PASSWORD_INVALID_LENGTH, + CONFUSING_CREDENTIALS + } @InjectView(R.id.user_message) TextView user_message; @@ -105,13 +108,15 @@ public class SessionDialog extends DialogFragment{ private void setUp(Bundle arguments) { is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); - if (arguments.containsKey(PASSWORD_INVALID_LENGTH)) + if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) password_field.setError(getString(R.string.error_not_valid_password_user_message)); + else if(arguments.containsKey(ERRORS.CONFUSING_CREDENTIALS.toString())) + username_field.setError("Perhaps you used your non LEAP credentials"); if (arguments.containsKey(USERNAME)) { String username = arguments.getString(USERNAME); username_field.setText(username); } - if (arguments.containsKey(USERNAME_MISSING)) { + if (arguments.containsKey(ERRORS.USERNAME_MISSING.toString())) { username_field.setError(getString(R.string.username_ask)); } if(arguments.containsKey(getString(R.string.user_message))) diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java index 3117ea6f..c8fd0251 100644 --- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java @@ -194,11 +194,11 @@ public class ProviderAPI extends IntentService { if(!wellFormedPassword(password)) { result.putBoolean(RESULT_KEY, false); result.putString(SessionDialog.USERNAME, username); - result.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); + result.putBoolean(SessionDialog.ERRORS.PASSWORD_INVALID_LENGTH.toString(), true); } if(!validUsername(username)) { result.putBoolean(RESULT_KEY, false); - result.putBoolean(SessionDialog.USERNAME_MISSING, true); + result.putBoolean(SessionDialog.ERRORS.USERNAME_MISSING.toString(), true); } } @@ -244,11 +244,11 @@ public class ProviderAPI extends IntentService { if(!wellFormedPassword(password)) { result.putBoolean(RESULT_KEY, false); result.putString(SessionDialog.USERNAME, username); - result.putBoolean(SessionDialog.PASSWORD_INVALID_LENGTH, true); + result.putBoolean(SessionDialog.ERRORS.PASSWORD_INVALID_LENGTH.toString(), true); } if(!validUsername(username)) { result.putBoolean(RESULT_KEY, false); - result.putBoolean(SessionDialog.USERNAME_MISSING, true); + result.putBoolean(SessionDialog.ERRORS.USERNAME_MISSING.toString(), true); } } -- cgit v1.2.3 From d18be7ed1dfc645bd378c2eb0c152f7e0eda42e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 19 Mar 2015 16:56:32 +0100 Subject: Show gus message just for riseup login. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 34 ++++++++++++---------- .../java/se/leap/bitmaskclient/SessionDialog.java | 13 ++++----- app/src/main/res/values/strings.xml | 3 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 14d79bc0..7c5e5421 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -1,6 +1,6 @@ /** * 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 @@ -37,7 +37,7 @@ import se.leap.bitmaskclient.eip.*; /** * The main user facing Activity of Bitmask Android, consisting of status, controls, * and access to preferences. - * + * * @author Sean Leonard * @author parmegv */ @@ -202,7 +202,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn }) .show(); } - + /** * Inflates permanent UI elements of the View and contains logic for what * service dependent UI elements to include. @@ -248,7 +248,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn getMenuInflater().inflate(R.menu.client_dashboard, menu); return true; } - + @Override public boolean onOptionsItemSelected(MenuItem item){ switch (item.getItemId()){ @@ -279,7 +279,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void showAbout() { Intent intent = new Intent(this, AboutActivity.class); - startActivity(intent); + startActivity(intent); } public void showLog() { @@ -300,11 +300,11 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn Bundle parameters = bundlePassword(password); providerApiCommand(parameters, 0, ProviderAPI.LOG_IN); } - + public void logOut() { providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.LOG_OUT); } - + @Override public void update (Observable observable, Object data) { if(observable instanceof UserSessionStatus) { @@ -374,7 +374,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE); setStatusMessage(progressbar_message_resId); } - + Intent command = prepareProviderAPICommand(parameters, providerApi_action); startService(command); } @@ -382,9 +382,9 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private Intent prepareProviderAPICommand(Bundle parameters, String action) { providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); providerAPI_result_receiver.setReceiver(this); - + Intent command = new Intent(this, ProviderAPI.class); - + command.putExtra(ProviderAPI.PARAMETERS, parameters); command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver); command.setAction(action); @@ -394,12 +394,16 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public void cancelLoginOrSignup() { EipStatus.getInstance().setConnectedOrDisconnected(); } - + public void sessionDialog(Bundle resultData) { - + FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); DialogFragment newFragment = new SessionDialog(); + if(provider.getName().equalsIgnoreCase("riseup")) { + resultData = resultData == Bundle.EMPTY ? new Bundle() : resultData; + resultData.putBoolean(SessionDialog.ERRORS.RISEUP_WARNING.toString(), true); + } if(resultData != null && !resultData.isEmpty()) { newFragment.setArguments(resultData); } @@ -408,7 +412,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn private void switchProvider() { if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); - + preferences.edit().clear().apply(); switching_provider = false; startActivityForResult(new Intent(this, ConfigurationWizard.class), SWITCH_PROVIDER); @@ -426,8 +430,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { downloadVpnCertificate(); } else if(resultCode == ProviderAPI.FAILED_LOGIN) { - if(provider.getName().equalsIgnoreCase("riseup")) - resultData.putBoolean(SessionDialog.ERRORS.CONFUSING_CREDENTIALS.toString(), true); sessionDialog(resultData); } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { if(switching_provider) switchProvider(); @@ -456,7 +458,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn public static Context getContext() { return app; } - + @Override public void startActivityForResult(Intent intent, int requestCode) { intent.putExtra(Dashboard.REQUEST_CODE, requestCode); diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java index e32bca8e..91e56330 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java @@ -26,8 +26,6 @@ import android.view.View; import android.widget.EditText; import android.widget.TextView; -import org.jetbrains.annotations.NotNull; - import butterknife.ButterKnife; import butterknife.InjectView; @@ -51,7 +49,7 @@ public class SessionDialog extends DialogFragment{ public static enum ERRORS { USERNAME_MISSING, PASSWORD_INVALID_LENGTH, - CONFUSING_CREDENTIALS + RISEUP_WARNING } @InjectView(R.id.user_message) @@ -110,9 +108,10 @@ public class SessionDialog extends DialogFragment{ is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false); if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) password_field.setError(getString(R.string.error_not_valid_password_user_message)); - else if(arguments.containsKey(ERRORS.CONFUSING_CREDENTIALS.toString())) - username_field.setError("Perhaps you used your non LEAP credentials"); - if (arguments.containsKey(USERNAME)) { + else if(arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { + user_message.setVisibility(TextView.VISIBLE); + user_message.setText(R.string.login_riseup_warning); + } if (arguments.containsKey(USERNAME)) { String username = arguments.getString(USERNAME); username_field.setText(username); } @@ -121,7 +120,7 @@ public class SessionDialog extends DialogFragment{ } if(arguments.containsKey(getString(R.string.user_message))) user_message.setText(arguments.getString(getString(R.string.user_message))); - else + else if(user_message.getVisibility() != TextView.VISIBLE) user_message.setVisibility(View.GONE); if(!username_field.getText().toString().isEmpty() && password_field.isFocusable()) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 632bc1f8..d1e33928 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,11 +59,10 @@ Logging out from this session. Logged out. Didn\'t log out. Try later, it may be a problem in the network or in the provider. If the problem persists, then wipe Bitmask data from the Android settings + "Riseup users: You need to create a separate account to use the VPN service" Authentication succeeded. Authentication failed. Registration failed. - Your own cert has been correctly downloaded. - Your own cert has incorrectly been downloaded. Initiating connection Cancel connection? There is a connection attempt in progress. Do you wish to cancel it? -- cgit v1.2.3