summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java15
-rw-r--r--app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java16
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java21
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java54
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java12
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java16
6 files changed, 57 insertions, 77 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
index f180b444..faf3779a 100644
--- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -62,9 +62,6 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
private Provider selected_provider;
final public static String TAG = ConfigurationWizard.class.getSimpleName();
- final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
- final public static String ANON_CERTIFICATE = "anon_certificate";
- final public static String AUTHED_CERTIFICATE = "authed_certificate";
final protected static String PROVIDER_SET = "PROVIDER SET";
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
@@ -83,7 +80,7 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
private int progress = -1;
private void initProviderList() {
- List<Renderer<Provider>> prototypes = new ArrayList<Renderer<Provider>>();
+ List<Renderer<Provider>> prototypes = new ArrayList<>();
prototypes.add(new ProviderRenderer(this));
ProviderRendererBuilder providerRendererBuilder = new ProviderRendererBuilder(prototypes);
adapter = new ProviderListAdapter(getLayoutInflater(), providerRendererBuilder, provider_manager);
@@ -186,7 +183,7 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
if (preferences.getBoolean(Constants.ALLOWED_ANON, false)){
mConfigState.putExtra(SERVICES_RETRIEVED, true);
- downloadAnonCert();
+ downloadVpnCertificate();
} else {
mProgressBar.incrementProgressBy(1);
hideProgressBar();
@@ -305,17 +302,11 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
/**
* Asks ProviderAPI to download an anonymous (anon) VPN certificate.
*/
- private void downloadAnonCert() {
+ private void downloadVpnCertificate() {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle parameters = new Bundle();
-
- parameters.putString(TYPE_OF_CERTIFICATE, ANON_CERTIFICATE);
-
provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
startService(provider_API_command);
}
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
index d63d641a..1dbe11d3 100644
--- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -187,7 +187,7 @@ public class ProviderAPI extends IntentService {
if(validUserLoginData(username, password)) {
session_id_bundle = register(username, password);
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
} else {
if(!wellFormedPassword(password)) {
session_id_bundle.putBoolean(RESULT_KEY, false);
@@ -236,7 +236,7 @@ public class ProviderAPI extends IntentService {
String password = task.getString(SessionDialog.PASSWORD);
if(validUserLoginData(username, password)) {
result = authenticate(username, password);
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
} else {
if(!wellFormedPassword(password)) {
result.putBoolean(RESULT_KEY, false);
@@ -317,7 +317,7 @@ public class ProviderAPI extends IntentService {
* and sends it as a broadcast.
* @param progress
*/
- private void broadcast_progress(int progress) {
+ private void broadcastProgress(int progress) {
Intent intentUpdate = new Intent();
intentUpdate.setAction(UPDATE_PROGRESSBAR);
intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
@@ -507,16 +507,16 @@ public class ProviderAPI extends IntentService {
if(!PROVIDER_JSON_DOWNLOADED)
current_download = getAndSetProviderJson(last_provider_main_url, last_danger_on);
if(PROVIDER_JSON_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
PROVIDER_JSON_DOWNLOADED = true;
current_download = downloadCACert(last_danger_on);
if(CA_CERT_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
CA_CERT_DOWNLOADED = true;
current_download = getAndSetEipServiceJson();
if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
EIP_SERVICE_JSON_DOWNLOADED = true;
}
}
@@ -847,7 +847,7 @@ public class ProviderAPI extends IntentService {
urlConnection.setSSLSocketFactory(getProviderSSLSocketFactory());
responseCode = urlConnection.getResponseCode();
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
LeapSRPSession.setToken("");
Log.d(TAG, Integer.toString(responseCode));
} catch (ClientProtocolException e) {
@@ -864,7 +864,7 @@ public class ProviderAPI extends IntentService {
if(urlConnection != null) {
responseCode = urlConnection.getResponseCode();
if(responseCode == 401) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
LeapSRPSession.setToken("");
Log.d(TAG, Integer.toString(responseCode));
return true;
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 4e6120ab..94be7cd1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -296,11 +296,14 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT);
}
- private void downloadAuthedUserCertificate() {
- Bundle parameters = new Bundle();
- parameters.putString(ConfigurationWizard.TYPE_OF_CERTIFICATE, ConfigurationWizard.AUTHED_CERTIFICATE);
-
- providerApiCommand(parameters, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE);
+ protected void downloadVpnCertificate() {
+ boolean is_authenticated = !LeapSRPSession.getToken().isEmpty();
+ boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false);
+ if(allowed_anon || is_authenticated)
+ providerApiCommand(Bundle.EMPTY, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE);
+ else
+ sessionDialog(Bundle.EMPTY);
+
}
private Bundle bundleParameters(String username, String password) {
@@ -312,8 +315,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
return parameters;
}
- private void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
- if(eip_fragment != null) {
+ protected void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
+ if(eip_fragment != null && progressbar_message_resId != 0) {
eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE);
setStatusMessage(progressbar_message_resId);
}
@@ -322,7 +325,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
startService(command);
}
- protected Intent prepareProviderAPICommand(Bundle parameters, String action) {
+ private Intent prepareProviderAPICommand(Bundle parameters, String action) {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
@@ -371,7 +374,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateViewHidingProgressBar(resultCode);
- downloadAuthedUserCertificate();
+ downloadVpnCertificate();
} else if(resultCode == ProviderAPI.FAILED_LOGIN) {
updateViewHidingProgressBar(resultCode);
sessionDialog(resultData);
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 54432033..bbcaa577 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -45,7 +45,7 @@ public class EipFragment extends Fragment implements Observer {
@InjectView(R.id.eipProgress)
ProgressBar progress_bar;
- private static Activity parent_activity;
+ private static Dashboard dashboard;
private static EIPReceiver mEIPReceiver;
private static EipStatus eip_status;
private boolean is_starting_to_connect;
@@ -53,11 +53,9 @@ public class EipFragment extends Fragment implements Observer {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
- parent_activity = activity;
- Dashboard dashboard = (Dashboard) parent_activity;
- Intent provider_API_command = dashboard.prepareProviderAPICommand(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE);
- parent_activity.startService(provider_API_command);
+ dashboard = (Dashboard) activity;
+ dashboard.providerApiCommand(Bundle.EMPTY, 0, ProviderAPI.DOWNLOAD_EIP_SERVICE);
}
@Override
@@ -130,7 +128,6 @@ public class EipFragment extends Fragment implements Observer {
startEipFromScratch();
else if(canLogInToStartEIP()) {
Log.d(TAG, "Can Log In to start EIP");
- Dashboard dashboard = (Dashboard) parent_activity;
Bundle bundle = new Bundle();
bundle.putBoolean(IS_PENDING, true);
dashboard.sessionDialog(bundle);
@@ -160,16 +157,16 @@ public class EipFragment extends Fragment implements Observer {
}
private void askPendingStartCancellation() {
- AlertDialog.Builder alertBuilder = new AlertDialog.Builder(parent_activity);
- alertBuilder.setTitle(parent_activity.getString(R.string.eip_cancel_connect_title))
- .setMessage(parent_activity.getString(R.string.eip_cancel_connect_text))
+ 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(parent_activity.getString(R.string.no), new DialogInterface.OnClickListener() {
+ .setNegativeButton(dashboard.getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
eip_switch.setChecked(true);
@@ -182,7 +179,7 @@ public class EipFragment extends Fragment implements Observer {
is_starting_to_connect = true;
progress_bar.setVisibility(View.VISIBLE);
eip_switch.setVisibility(View.VISIBLE);
- String status = parent_activity.getString(R.string.eip_status_start_pending);
+ String status = dashboard.getString(R.string.eip_status_start_pending);
status_message.setText(status);
if(!eip_switch.isChecked()) {
@@ -195,15 +192,15 @@ public class EipFragment extends Fragment implements Observer {
private void stopEIP() {
if(eip_status.isConnecting())
VoidVpnService.stop();
- Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
- parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
+ Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class);
+ dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
eip_status.setDisconnecting();
}
protected void askToStopEIP() {
hideProgressBar();
- String status = parent_activity.getString(R.string.eip_state_not_connected);
+ String status = dashboard.getString(R.string.eip_state_not_connected);
status_message.setText(status);
eipCommand(Constants.ACTION_STOP_EIP);
@@ -217,10 +214,10 @@ public class EipFragment extends Fragment implements Observer {
*/
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(parent_activity.getApplicationContext(), EIP.class);
+ Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class);
vpn_intent.setAction(action);
vpn_intent.putExtra(Constants.RECEIVER_TAG, mEIPReceiver);
- parent_activity.startService(vpn_intent);
+ dashboard.startService(vpn_intent);
}
@Override
@@ -228,7 +225,7 @@ public class EipFragment extends Fragment implements Observer {
if(observable instanceof EipStatus) {
eip_status = (EipStatus) observable;
final EipStatus eip_status = (EipStatus) observable;
- parent_activity.runOnUiThread(new Runnable() {
+ dashboard.runOnUiThread(new Runnable() {
@Override
public void run() {
handleNewState(eip_status);
@@ -254,13 +251,13 @@ public class EipFragment extends Fragment implements Observer {
Log.d(TAG, "setConnectedUi? " + eip_status.isConnected());
adjustSwitch();
is_starting_to_connect = false;
- status_message.setText(parent_activity.getString(R.string.eip_state_connected));
+ status_message.setText(dashboard.getString(R.string.eip_state_connected));
}
private void setDisconnectedUI(){
hideProgressBar();
adjustSwitch();
- status_message.setText(parent_activity.getString(R.string.eip_state_not_connected));
+ status_message.setText(dashboard.getString(R.string.eip_state_not_connected));
}
private void adjustSwitch() {
@@ -281,13 +278,18 @@ public class EipFragment extends Fragment implements Observer {
private void setInProgressUI(EipStatus eip_status) {
int localizedResId = eip_status.getLocalizedResId();
String logmessage = eip_status.getLogMessage();
- String prefix = parent_activity.getString(localizedResId);
+ String prefix = dashboard.getString(localizedResId);
status_message.setText(prefix + " " + logmessage);
is_starting_to_connect = false;
adjustSwitch();
}
+ private void updatingCertificateUI() {
+ progress_bar.setVisibility(View.VISIBLE);
+ status_message.setText(getString(R.string.updating_certificate_message));
+ }
+
private void hideProgressBar() {
if(progress_bar != null)
progress_bar.setVisibility(View.GONE);
@@ -333,16 +335,8 @@ public class EipFragment extends Fragment implements Observer {
case Activity.RESULT_OK:
break;
case Activity.RESULT_CANCELED:
- Dashboard dashboard = (Dashboard) parent_activity;
-
- progress_bar.setVisibility(View.VISIBLE);
- status_message.setText(getString(R.string.updating_certificate_message));
- if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false)) {
- dashboard.sessionDialog(Bundle.EMPTY);
- } else {
- Intent provider_API_command = dashboard.prepareProviderAPICommand(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE);
- parent_activity.startService(provider_API_command);
- }
+ updatingCertificateUI();
+ dashboard.downloadVpnCertificate();
break;
}
}
diff --git a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
index e5095f00..abab106d 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -62,9 +62,6 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
private Provider selected_provider;
final public static String TAG = ConfigurationWizard.class.getSimpleName();
- final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
- final public static String ANON_CERTIFICATE = "anon_certificate";
- final public static String AUTHED_CERTIFICATE = "authed_certificate";
final protected static String PROVIDER_SET = "PROVIDER SET";
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
@@ -187,7 +184,7 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
if (preferences.getBoolean(Constants.ALLOWED_ANON, false)){
mConfigState.putExtra(SERVICES_RETRIEVED, true);
- downloadAnonCert();
+ downloadVpnCertificate();
} else {
mProgressBar.incrementProgressBy(1);
hideProgressBar();
@@ -303,15 +300,10 @@ implements NewProviderDialogInterface, ProviderDetailFragmentInterface, Download
/**
* Asks ProviderAPI to download an anonymous (anon) VPN certificate.
*/
- private void downloadAnonCert() {
+ private void downloadVpnCertificate() {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle parameters = new Bundle();
-
- parameters.putString(TYPE_OF_CERTIFICATE, ANON_CERTIFICATE);
-
provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
- provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
index d019ca59..334efaa9 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -182,7 +182,7 @@ public class ProviderAPI extends IntentService {
if(validUserLoginData(username, password)) {
session_id_bundle = register(username, password);
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
} else {
if(!wellFormedPassword(password)) {
session_id_bundle.putBoolean(RESULT_KEY, false);
@@ -232,7 +232,7 @@ public class ProviderAPI extends IntentService {
String password = (String) task.get(SessionDialog.PASSWORD);
if(validUserLoginData(username, password)) {
result = authenticate(username, password);
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
} else {
if(!wellFormedPassword(password)) {
result.putBoolean(RESULT_KEY, false);
@@ -312,7 +312,7 @@ public class ProviderAPI extends IntentService {
* and sends it as a broadcast.
* @param progress
*/
- private void broadcast_progress(int progress) {
+ private void broadcastProgress(int progress) {
Intent intentUpdate = new Intent();
intentUpdate.setAction(UPDATE_PROGRESSBAR);
intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
@@ -497,17 +497,17 @@ public class ProviderAPI extends IntentService {
if(!PROVIDER_JSON_DOWNLOADED)
current_download = getAndSetProviderJson(last_provider_main_url);
if(PROVIDER_JSON_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
PROVIDER_JSON_DOWNLOADED = true;
if(!CA_CERT_DOWNLOADED)
current_download = downloadCACert();
if(CA_CERT_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
CA_CERT_DOWNLOADED = true;
current_download = getAndSetEipServiceJson();
if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
EIP_SERVICE_JSON_DOWNLOADED = true;
}
}
@@ -833,7 +833,7 @@ public class ProviderAPI extends IntentService {
urlConnection.setSSLSocketFactory(getProviderSSLSocketFactory());
responseCode = urlConnection.getResponseCode();
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
LeapSRPSession.setToken("");
Log.d(TAG, Integer.toString(responseCode));
} catch (ClientProtocolException e) {
@@ -850,7 +850,7 @@ public class ProviderAPI extends IntentService {
if(urlConnection != null) {
responseCode = urlConnection.getResponseCode();
if(responseCode == 401) {
- broadcast_progress(progress++);
+ broadcastProgress(progress++);
LeapSRPSession.setToken("");
Log.d(TAG, Integer.toString(responseCode));
return true;