summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-16 16:58:07 +0100
committerParménides GV <parmegv@sdf.org>2014-12-16 16:58:07 +0100
commit132b62695b021b61d1774944a7bfa6e9166d3ea0 (patch)
tree6c451f16af153d0f7a72971ef3625da7f736cbe3
parent9f146deb3448815fccc1637c00588e0dfb23293e (diff)
Update eip-service.json each EipFragment.onAttach
-rw-r--r--app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java34
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java19
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java (renamed from app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java)17
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SessionDialog.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java5
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java36
6 files changed, 68 insertions, 45 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
index f47510bc..886d70a0 100644
--- a/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/debug/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -46,6 +46,7 @@ import se.leap.bitmaskclient.eip.*;
public class ProviderAPI extends IntentService {
final public static String
+ TAG = ProviderAPI.class.getSimpleName(),
SET_UP_PROVIDER = "setUpProvider",
DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
SRP_REGISTER = "srpRegister",
@@ -58,7 +59,7 @@ public class ProviderAPI extends IntentService {
ERRORS = "errors",
UPDATE_PROGRESSBAR = "update_progressbar",
CURRENT_PROGRESS = "current_progress",
- TAG = ProviderAPI.class.getSimpleName()
+ DOWNLOAD_EIP_SERVICE = TAG + ".DOWNLOAD_EIP_SERVICE"
;
final public static int
@@ -71,7 +72,9 @@ public class ProviderAPI extends IntentService {
CORRECTLY_DOWNLOADED_CERTIFICATE = 9,
INCORRECTLY_DOWNLOADED_CERTIFICATE = 10,
PROVIDER_OK = 11,
- PROVIDER_NOK = 12
+ PROVIDER_NOK = 12,
+ CORRECTLY_DOWNLOADED_EIP_SERVICE = 13,
+ INCORRECTLY_DOWNLOADED_EIP_SERVICE= 14
;
private static boolean
@@ -82,12 +85,12 @@ public class ProviderAPI extends IntentService {
private static String last_provider_main_url;
private static boolean last_danger_on = false;
- private static boolean setting_up_provider = true;
+ private static boolean go_ahead = true;
private static SharedPreferences preferences;
private static String provider_api_url;
public static void stop() {
- setting_up_provider = false;
+ go_ahead = false;
}
public ProviderAPI() {
@@ -124,15 +127,15 @@ public class ProviderAPI extends IntentService {
try {
JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "no provider"));
provider_api_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION);
- setting_up_provider = true;
+ go_ahead = true;
} catch (JSONException e) {
- setting_up_provider = false;
+ go_ahead = false;
}
}
if(action.equalsIgnoreCase(SET_UP_PROVIDER)) {
Bundle result = setUpProvider(parameters);
- if(setting_up_provider) {
+ if(go_ahead) {
if(result.getBoolean(RESULT_KEY)) {
receiver.send(PROVIDER_OK, result);
} else {
@@ -165,7 +168,14 @@ public class ProviderAPI extends IntentService {
} 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);
+ } else {
+ receiver.send(INCORRECTLY_DOWNLOADED_EIP_SERVICE, result);
+ }
+ }
}
private Bundle tryToRegister(Bundle task) {
@@ -487,7 +497,7 @@ public class ProviderAPI extends IntentService {
last_danger_on = task.getBoolean(ProviderItem.DANGER_ON);
last_provider_main_url = task.getString(Provider.MAIN_URL);
CA_CERT_DOWNLOADED = PROVIDER_JSON_DOWNLOADED = EIP_SERVICE_JSON_DOWNLOADED = false;
- setting_up_provider = true;
+ go_ahead = true;
}
if(!PROVIDER_JSON_DOWNLOADED)
@@ -518,7 +528,7 @@ public class ProviderAPI extends IntentService {
String ca_cert_url = provider_json.getString(Provider.CA_CERT_URI);
String cert_string = downloadWithCommercialCA(ca_cert_url, danger_on);
- if(validCertificate(cert_string) && setting_up_provider) {
+ if(validCertificate(cert_string) && go_ahead) {
preferences.edit().putString(Provider.CA_CERT, cert_string).commit();
result.putBoolean(RESULT_KEY, true);
} else {
@@ -579,7 +589,7 @@ public class ProviderAPI extends IntentService {
private Bundle getAndSetProviderJson(String provider_main_url, boolean danger_on) {
Bundle result = new Bundle();
- if(setting_up_provider) {
+ if(go_ahead) {
String provider_dot_json_string = downloadWithCommercialCA(provider_main_url + "/provider.json", danger_on);
try {
@@ -606,7 +616,7 @@ public class ProviderAPI extends IntentService {
private Bundle getAndSetEipServiceJson() {
Bundle result = new Bundle();
String eip_service_json_string = "";
- if(setting_up_provider) {
+ if(go_ahead) {
try {
JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, ""));
String eip_service_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH;
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 862086eb..cca9c63c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -77,7 +77,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
@InjectView(R.id.providerName)
TextView provider_name;
- EipServiceFragment eip_fragment;
+ EipFragment eip_fragment;
private Provider provider;
private static boolean authed_eip;
public ProviderAPIResultReceiver providerAPI_result_receiver;
@@ -220,17 +220,17 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
provider_name.setText(provider.getDomain());
if ( provider.hasEIP()){
- fragment_manager.removePreviousFragment(EipServiceFragment.TAG);
- eip_fragment = new EipServiceFragment();
+ 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(EipServiceFragment.START_ON_BOOT, true);
+ arguments.putBoolean(EipFragment.START_ON_BOOT, true);
if(eip_fragment != null) eip_fragment.setArguments(arguments);
}
- fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipServiceFragment.TAG);
+ fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipFragment.TAG);
if (hide_and_turn_on_eip) {
onBackPressed();
@@ -312,7 +312,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
- private Intent prepareProviderAPICommand() {
+ protected Intent prepareProviderAPICommand() {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
@@ -474,6 +474,13 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
hideProgressBar();
setResult(RESULT_CANCELED);
}
+ else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) {
+ setResult(RESULT_OK);
+
+ updateEipService();
+ } else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) {
+ setResult(RESULT_CANCELED);
+ }
}
private void updateEipService() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 1b40c94c..92d2a8bd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -27,9 +27,9 @@ import se.leap.bitmaskclient.eip.Constants;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
-public class EipServiceFragment extends Fragment implements Observer {
+public class EipFragment extends Fragment implements Observer {
- public static String TAG = "se.leap.bitmask.EipServiceFragment";
+ public static String TAG = EipFragment.class.getSimpleName();
protected static final String IS_PENDING = TAG + ".is_pending";
protected static final String IS_CONNECTED = TAG + ".is_connected";
@@ -53,6 +53,11 @@ public class EipServiceFragment extends Fragment implements Observer {
public void onAttach(Activity activity) {
super.onAttach(activity);
parent_activity = activity;
+
+ Dashboard dashboard = (Dashboard) parent_activity;
+ Intent provider_API_command = dashboard.prepareProviderAPICommand();
+ provider_API_command.setAction(ProviderAPI.DOWNLOAD_EIP_SERVICE);
+ parent_activity.startService(provider_API_command);
}
@Override
@@ -332,14 +337,8 @@ public class EipServiceFragment extends Fragment implements Observer {
if(LeapSRPSession.getToken().isEmpty() && !Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false)) {
dashboard.logInDialog(Bundle.EMPTY);
} else {
- Intent provider_API_command = new Intent(parent_activity, ProviderAPI.class);
- if(dashboard.providerAPI_result_receiver == null) {
- dashboard.providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
- dashboard.providerAPI_result_receiver.setReceiver(dashboard);
- }
-
+ Intent provider_API_command = dashboard.prepareProviderAPICommand();
provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
- provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, dashboard.providerAPI_result_receiver);
parent_activity.startService(provider_API_command);
}
break;
diff --git a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
index 60382cf0..22e0f128 100644
--- a/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/SessionDialog.java
@@ -72,7 +72,7 @@ public class SessionDialog extends DialogFragment{
Bundle arguments = getArguments();
if (arguments != null) {
- is_eip_pending = arguments.getBoolean(EipServiceFragment.IS_PENDING, false);
+ is_eip_pending = arguments.getBoolean(EipFragment.IS_PENDING, false);
if (arguments.containsKey(PASSWORD_INVALID_LENGTH))
password_field.setError(getString(R.string.error_not_valid_password_user_message));
if (arguments.containsKey(USERNAME)) {
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 7db35c17..7017e874 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.os.Handler;
import android.os.ResultReceiver;
import android.util.Log;
@@ -38,7 +37,7 @@ import de.blinkt.openvpn.LaunchVPN;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ProfileManager;
import se.leap.bitmaskclient.Dashboard;
-import se.leap.bitmaskclient.EipServiceFragment;
+import se.leap.bitmaskclient.EipFragment;
import static se.leap.bitmaskclient.eip.Constants.ACTION_CHECK_CERT_VALIDITY;
import static se.leap.bitmaskclient.eip.Constants.ACTION_IS_EIP_RUNNING;
@@ -121,7 +120,7 @@ public final class EIP extends IntentService {
GatewaySelector gateway_selector = new GatewaySelector(gateways);
gateway = gateway_selector.select();
if(gateway != null && gateway.getProfile() != null) {
- mReceiver = EipServiceFragment.getReceiver();
+ mReceiver = EipFragment.getReceiver();
launchActiveGateway();
}
tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK);
diff --git a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
index f1cb84d6..9d0b4db6 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/release/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -31,8 +31,6 @@ import javax.net.ssl.*;
import org.apache.http.client.ClientProtocolException;
import org.json.*;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.SessionDialog;
import se.leap.bitmaskclient.eip.*;
/**
@@ -47,6 +45,7 @@ import se.leap.bitmaskclient.eip.*;
public class ProviderAPI extends IntentService {
final public static String
+ TAG = ProviderAPI.class.getSimpleName(),
SET_UP_PROVIDER = "setUpProvider",
DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
SRP_REGISTER = "srpRegister",
@@ -59,7 +58,7 @@ public class ProviderAPI extends IntentService {
ERRORS = "errors",
UPDATE_PROGRESSBAR = "update_progressbar",
CURRENT_PROGRESS = "current_progress",
- TAG = ProviderAPI.class.getSimpleName()
+ DOWNLOAD_EIP_SERVICE = TAG + ".DOWNLOAD_EIP_SERVICE"
;
final public static int
@@ -72,7 +71,9 @@ public class ProviderAPI extends IntentService {
CORRECTLY_DOWNLOADED_CERTIFICATE = 9,
INCORRECTLY_DOWNLOADED_CERTIFICATE = 10,
PROVIDER_OK = 11,
- PROVIDER_NOK = 12
+ PROVIDER_NOK = 12,
+ CORRECTLY_DOWNLOADED_EIP_SERVICE = 13,
+ INCORRECTLY_DOWNLOADED_EIP_SERVICE= 14
;
private static boolean
@@ -82,12 +83,12 @@ public class ProviderAPI extends IntentService {
;
private static String last_provider_main_url;
- private static boolean setting_up_provider = true;
+ private static boolean go_ahead = true;
private static SharedPreferences preferences;
private static String provider_api_url;
public static void stop() {
- setting_up_provider = false;
+ go_ahead = false;
}
public ProviderAPI() {
@@ -121,15 +122,15 @@ public class ProviderAPI extends IntentService {
try {
JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, ""));
provider_api_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION);
- setting_up_provider = true;
+ go_ahead = true;
} catch (JSONException e) {
- setting_up_provider = false;
+ go_ahead = false;
}
}
if(action.equalsIgnoreCase(SET_UP_PROVIDER)) {
Bundle result = setUpProvider(parameters);
- if(setting_up_provider) {
+ if(go_ahead) {
if(result.getBoolean(RESULT_KEY)) {
receiver.send(PROVIDER_OK, result);
} else {
@@ -162,7 +163,14 @@ public class ProviderAPI extends IntentService {
} 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);
+ } else {
+ receiver.send(INCORRECTLY_DOWNLOADED_EIP_SERVICE, result);
+ }
+ }
}
private Bundle tryToRegister(Bundle task) {
@@ -479,7 +487,7 @@ public class ProviderAPI extends IntentService {
if(task != null && task.containsKey(Provider.MAIN_URL)) {
last_provider_main_url = task.getString(Provider.MAIN_URL);
CA_CERT_DOWNLOADED = PROVIDER_JSON_DOWNLOADED = EIP_SERVICE_JSON_DOWNLOADED = false;
- setting_up_provider = true;
+ go_ahead = true;
}
if(!PROVIDER_JSON_DOWNLOADED)
@@ -512,7 +520,7 @@ public class ProviderAPI extends IntentService {
String cert_string = downloadWithCommercialCA(ca_cert_url);
result.putBoolean(RESULT_KEY, true);
- if(validCertificate(cert_string) && setting_up_provider) {
+ if(validCertificate(cert_string) && go_ahead) {
preferences.edit().putString(Provider.CA_CERT, cert_string).commit();
result.putBoolean(RESULT_KEY, true);
} else {
@@ -575,7 +583,7 @@ public class ProviderAPI extends IntentService {
private Bundle getAndSetProviderJson(String provider_main_url) {
Bundle result = new Bundle();
- if(setting_up_provider) {
+ if(go_ahead) {
String provider_dot_json_string = downloadWithCommercialCA(provider_main_url + "/provider.json");
try {
@@ -602,7 +610,7 @@ public class ProviderAPI extends IntentService {
private Bundle getAndSetEipServiceJson() {
Bundle result = new Bundle();
String eip_service_json_string = "";
- if(setting_up_provider) {
+ if(go_ahead) {
try {
JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, ""));
String eip_service_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH;