summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-08-01 12:22:48 +0200
committerParménides GV <parmegv@sdf.org>2013-08-01 12:22:48 +0200
commit21e71b0b8916264d7499254fb36a0ee533018224 (patch)
treeef84fa7c3acd4d501eaebc394dce4a16ca1cae8b /src/se/leap/leapclient
parenta1a03615cb9c4f978142b234f028e718eb91a103 (diff)
ProviderAPI intent receives actions and parameters.
We no longer use BundleExtras named as the action ProviderAPI is intended to perform, but we standardise this name (ProviderAPI.PARAMETERS), and use setAction to pass that action string.
Diffstat (limited to 'src/se/leap/leapclient')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java7
-rw-r--r--src/se/leap/leapclient/ConfigurationWizard.java40
-rw-r--r--src/se/leap/leapclient/Dashboard.java29
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java49
4 files changed, 66 insertions, 59 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index 62ebf8f1..e139bf62 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -52,18 +52,11 @@ public class ConfigHelper {
final public static String
ABOUT_FRAGMENT = "aboutFragment",
- DOWNLOAD_JSON_FILES_BUNDLE_EXTRA = "downloadJSONFiles",
- UPDATE_PROVIDER_DOTJSON = "updateProviderDotJSON",
- DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
LOG_IN_DIALOG = "logInDialog",
NEW_PROVIDER_DIALOG = "logInDialog",
- SRP_REGISTER = "srpRegister",
- SRP_AUTH = "srpAuth",
M1_KEY = "M1",
M2_KEY = "M2",
LOG_IN = "logIn",
- LOG_OUT = "logOut",
- DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
API_VERSION_KEY = "api_version",
API_RETURN_SERIAL_KEY = "serial",
RESULT_KEY = "result",
diff --git a/src/se/leap/leapclient/ConfigurationWizard.java b/src/se/leap/leapclient/ConfigurationWizard.java
index 934e2ea0..4ddac803 100644
--- a/src/se/leap/leapclient/ConfigurationWizard.java
+++ b/src/se/leap/leapclient/ConfigurationWizard.java
@@ -265,14 +265,15 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private void downloadJSONFiles(ProviderItem provider) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
+ Bundle parameters = new Bundle();
- method_and_parameters.putString(ConfigHelper.PROVIDER_KEY, provider.name);
- method_and_parameters.putString(ConfigHelper.MAIN_CERT_KEY, provider.cert_json_url);
- method_and_parameters.putString(ConfigHelper.EIP_SERVICE_KEY, provider.eip_service_json_url);
- method_and_parameters.putBoolean(ConfigHelper.DANGER_ON, provider.danger_on);
+ parameters.putString(ConfigHelper.PROVIDER_KEY, provider.name);
+ parameters.putString(ConfigHelper.MAIN_CERT_KEY, provider.cert_json_url);
+ parameters.putString(ConfigHelper.EIP_SERVICE_KEY, provider.eip_service_json_url);
+ parameters.putBoolean(ConfigHelper.DANGER_ON, provider.danger_on);
- provider_API_command.putExtra(ConfigHelper.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
@@ -284,11 +285,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
private void downloadAnonCert() {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
+ Bundle parameters = new Bundle();
- method_and_parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.ANON_CERTIFICATE);
+ parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.ANON_CERTIFICATE);
- provider_API_command.putExtra(ConfigHelper.DOWNLOAD_CERTIFICATE, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
@@ -332,11 +334,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public void saveAndSelectProvider(String provider_main_url, boolean danger_on) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
- method_and_parameters.putString(ConfigHelper.PROVIDER_MAIN_URL, provider_main_url);
- method_and_parameters.putBoolean(ConfigHelper.DANGER_ON, danger_on);
+ Bundle parameters = new Bundle();
+ parameters.putString(ConfigHelper.PROVIDER_MAIN_URL, provider_main_url);
+ parameters.putBoolean(ConfigHelper.DANGER_ON, danger_on);
- provider_API_command.putExtra(ConfigHelper.DOWNLOAD_NEW_PROVIDER_DOTJSON, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.DOWNLOAD_NEW_PROVIDER_DOTJSON);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
@@ -351,12 +354,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public void updateProviderDotJson(String provider_name, String provider_json_url, boolean danger_on) {
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
- method_and_parameters.putString(ConfigHelper.PROVIDER_NAME, provider_name);
- method_and_parameters.putString(ConfigHelper.PROVIDER_JSON_URL, provider_json_url);
- method_and_parameters.putBoolean(ConfigHelper.DANGER_ON, danger_on);
+ Bundle parameters = new Bundle();
+ parameters.putString(ConfigHelper.PROVIDER_NAME, provider_name);
+ parameters.putString(ConfigHelper.PROVIDER_JSON_URL, provider_json_url);
+ parameters.putBoolean(ConfigHelper.DANGER_ON, danger_on);
- provider_API_command.putExtra(ConfigHelper.UPDATE_PROVIDER_DOTJSON, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.UPDATE_PROVIDER_DOTJSON);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index 063cd3cd..b652bb73 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -213,20 +213,21 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
- method_and_parameters.putString(ConfigHelper.USERNAME_KEY, username);
- method_and_parameters.putString(ConfigHelper.PASSWORD_KEY, password);
+ Bundle parameters = new Bundle();
+ parameters.putString(ConfigHelper.USERNAME_KEY, username);
+ parameters.putString(ConfigHelper.PASSWORD_KEY, password);
JSONObject provider_json;
try {
provider_json = new JSONObject(preferences.getString(ConfigHelper.PROVIDER_KEY, ""));
- method_and_parameters.putString(ConfigHelper.API_URL_KEY, provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY));
+ parameters.putString(ConfigHelper.API_URL_KEY, provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- provider_API_command.putExtra(ConfigHelper.SRP_AUTH, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.SRP_AUTH);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
if(mProgressDialog != null) mProgressDialog.dismiss();
@@ -242,18 +243,19 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
providerAPI_result_receiver.setReceiver(this);
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
+ Bundle parameters = new Bundle();
JSONObject provider_json;
try {
provider_json = new JSONObject(preferences.getString(ConfigHelper.PROVIDER_KEY, ""));
- method_and_parameters.putString(ConfigHelper.API_URL_KEY, provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY));
+ parameters.putString(ConfigHelper.API_URL_KEY, provider_json.getString(ConfigHelper.API_URL_KEY) + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- provider_API_command.putExtra(ConfigHelper.LOG_OUT, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.LOG_OUT);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
if(mProgressDialog != null) mProgressDialog.dismiss();
@@ -292,12 +294,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Intent provider_API_command = new Intent(this, ProviderAPI.class);
- Bundle method_and_parameters = new Bundle();
- method_and_parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.AUTHED_CERTIFICATE);
- method_and_parameters.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_id.getName());
- method_and_parameters.putString(ConfigHelper.SESSION_ID_KEY, session_id.getValue());
+ Bundle parameters = new Bundle();
+ parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.AUTHED_CERTIFICATE);
+ parameters.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_id.getName());
+ parameters.putString(ConfigHelper.SESSION_ID_KEY, session_id.getValue());
- provider_API_command.putExtra(ConfigHelper.DOWNLOAD_CERTIFICATE, method_and_parameters);
+ provider_API_command.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
+ provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ConfigHelper.RECEIVER_KEY, providerAPI_result_receiver);
startService(provider_API_command);
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 944a0e7f..11dfabf1 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -88,6 +88,17 @@ public class ProviderAPI extends IntentService {
private Handler mHandler;
+ final public static String
+ DOWNLOAD_JSON_FILES_BUNDLE_EXTRA = "downloadJSONFiles",
+ UPDATE_PROVIDER_DOTJSON = "updateProviderDotJSON",
+ DOWNLOAD_NEW_PROVIDER_DOTJSON = "downloadNewProviderDotJSON",
+ SRP_REGISTER = "srpRegister",
+ SRP_AUTH = "srpAuth",
+ LOG_OUT = "logOut",
+ DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
+ PARAMETERS = "parameters"
+ ;
+
public ProviderAPI() {
super("ProviderAPI");
Log.v("ClassName", "Provider API");
@@ -110,35 +121,33 @@ public class ProviderAPI extends IntentService {
}
@Override
- protected void onHandleIntent(Intent task_for) {
- final ResultReceiver receiver = task_for.getParcelableExtra("receiver");
+ protected void onHandleIntent(Intent command) {
+ final ResultReceiver receiver = command.getParcelableExtra("receiver");
+ String action = command.getAction();
+ Bundle parameters = command.getBundleExtra(PARAMETERS);
- Bundle task;
- if((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_JSON_FILES_BUNDLE_EXTRA)) != null) {
- if(!downloadJsonFiles(task)) {
+ if(action.equalsIgnoreCase(DOWNLOAD_JSON_FILES_BUNDLE_EXTRA)) {
+ if(!downloadJsonFiles(parameters)) {
receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
} else {
receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.UPDATE_PROVIDER_DOTJSON)) != null) {
- Bundle result = updateProviderDotJSON(task);
+ } else if(action.equalsIgnoreCase(UPDATE_PROVIDER_DOTJSON)) {
+ Bundle result = updateProviderDotJSON(parameters);
if(result.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
- } else {
+ } else {
receiver.send(ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_NEW_PROVIDER_DOTJSON)) != null) {
- Bundle result = downloadNewProviderDotJSON(task);
+ } else if (action.equalsIgnoreCase(DOWNLOAD_NEW_PROVIDER_DOTJSON)) {
+ Bundle result = downloadNewProviderDotJSON(parameters);
if(result.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, result);
} else {
receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.SRP_AUTH)) != null) {
- Bundle session_id_bundle = authenticateBySRP(task);
+ } else if (action.equalsIgnoreCase(SRP_AUTH)) {
+ Bundle session_id_bundle = authenticateBySRP(parameters);
if(session_id_bundle.getBoolean(ConfigHelper.RESULT_KEY)) {
receiver.send(ConfigHelper.SRP_AUTHENTICATION_SUCCESSFUL, session_id_bundle);
} else {
@@ -147,16 +156,14 @@ public class ProviderAPI extends IntentService {
user_message_bundle.putString(user_message_key, session_id_bundle.getString(user_message_key));
receiver.send(ConfigHelper.SRP_AUTHENTICATION_FAILED, user_message_bundle);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.LOG_OUT)) != null) {
- if(logOut(task)) {
+ } else if (action.equalsIgnoreCase(LOG_OUT)) {
+ if(logOut(parameters)) {
receiver.send(ConfigHelper.LOGOUT_SUCCESSFUL, Bundle.EMPTY);
} else {
receiver.send(ConfigHelper.LOGOUT_FAILED, Bundle.EMPTY);
}
- }
- else if ((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_CERTIFICATE)) != null) {
- if(getNewCert(task)) {
+ } else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
+ if(getNewCert(parameters)) {
receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
} else {
receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);