summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-01-16 17:41:47 +0100
committerFup Duck <fupduck@sacknagel.com>2018-01-16 17:42:48 +0100
commit4f536f457da8bb7ab0316f6de7703437ad0ce58f (patch)
tree0ab3e6453a488c7b46854cbcc5ecb286217625da /app/src/main/java/se/leap
parentdeb8f0c1192a36c9aa66ab16bfd5e26357096821 (diff)
resolve commented issues
* recreate activity correctly after changing orientation * replace getApplicationActivity
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java154
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/LoginActivity.java6
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java7
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java60
5 files changed, 151 insertions, 78 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
index f30c962c..64ea4779 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
@@ -26,6 +26,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
+import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@@ -58,8 +59,15 @@ import static se.leap.bitmaskclient.Constants.APP_ACTION_QUIT;
import static se.leap.bitmaskclient.Constants.PROVIDER_ALLOW_ANONYMOUS;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE;
import static se.leap.bitmaskclient.ProviderAPI.ERRORS;
-import static se.leap.bitmaskclient.ProviderAPI.SET_UP_PROVIDER;
+import static se.leap.bitmaskclient.ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE;
+import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_API_EVENT;
+import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_NOK;
+import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_OK;
+import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_SET_UP;
+import static se.leap.bitmaskclient.ProviderAPI.RESULT_CODE;
+import static se.leap.bitmaskclient.ProviderAPI.RESULT_KEY;
import static se.leap.bitmaskclient.ProviderAPI.UPDATE_PROGRESSBAR;
/**
@@ -93,11 +101,9 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
final protected static String PROVIDER_NOT_SET = "PROVIDER NOT SET";
final protected static String SETTING_UP_PROVIDER = "PROVIDER GETS SET";
- final private static String PENDING_SHOW_PROVIDER_DETAILS = "PENDING PROVIDER DETAILS";
- final private static String SHOWING_PROVIDER_DETAILS = "SHOWING PROVIDER DETAILS SHOWN";
+ final private static String SHOWING_PROVIDER_DETAILS = "SHOWING PROVIDER DETAILS";
final private static String PENDING_SHOW_FAILED_DIALOG = "SHOW FAILED DIALOG";
final private static String REASON_TO_FAIL = "REASON TO FAIL";
- final protected static String PROVIDER_SET = "PROVIDER SET";
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
final private static String PROGRESSBAR_TEXT = TAG + "PROGRESSBAR_TEXT";
@@ -110,7 +116,6 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
protected static SharedPreferences preferences;
FragmentManagerEnhanced fragmentManager;
//TODO: add some states (values for progressbarText) about ongoing setup or remove that field
- private String progressbarText = "";
private boolean isActivityShowing;
@@ -155,12 +160,10 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
}
private void restoreState(Bundle savedInstanceState) {
- progressbarText = savedInstanceState.getString(PROGRESSBAR_TEXT, "");
selectedProvider = savedInstanceState.getParcelable(Provider.KEY);
mConfigState.setAction(savedInstanceState.getString(ACTIVITY_STATE, PROVIDER_NOT_SET));
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction()) ||
- PENDING_SHOW_PROVIDER_DETAILS.equals(mConfigState.getAction()) ||
PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())
) {
onItemSelectedUi();
@@ -169,16 +172,15 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
@Override
protected void onResume() {
+ Log.d(TAG, "resuming with ConfigState: " + mConfigState.getAction());
super.onResume();
hideProgressBar();
isActivityShowing = true;
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) {
showProgressBar();
adapter.hideAllBut(adapter.indexOf(selectedProvider));
- // TODO find a better replacement! This can lead to loops
- onItemSelectedLogic();
- } else if (PENDING_SHOW_PROVIDER_DETAILS.equals(mConfigState.getAction())) {
- showProviderDetails();
+ checkProviderSetUp();
+ showDownloadFailedDialog(null);
} else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) {
showDownloadFailedDialog(mConfigState.getStringExtra(REASON_TO_FAIL));
} else if (SHOWING_PROVIDER_DETAILS.equals(mConfigState.getAction())) {
@@ -215,6 +217,7 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
super.onDestroy();
if (providerAPIBroadcastReceiver != null)
unregisterReceiver(providerAPIBroadcastReceiver);
+ providerAPIResultReceiver = null;
}
private void setUpProviderAPIResultReceiver() {
@@ -222,49 +225,60 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
providerAPIBroadcastReceiver = new ProviderAPIBroadcastReceiver();
IntentFilter updateIntentFilter = new IntentFilter(UPDATE_PROGRESSBAR);
- updateIntentFilter.addAction(SET_UP_PROVIDER);
+ updateIntentFilter.addAction(PROVIDER_API_EVENT);
updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter);
}
- @Override
- public void onReceiveResult(int resultCode, Bundle resultData) {
- if (resultCode == ProviderAPI.PROVIDER_OK) {
- try {
- String providerJsonString = preferences.getString(Provider.KEY, "");
- if (!providerJsonString.isEmpty())
- selectedProvider.define(new JSONObject(providerJsonString));
- String caCert = preferences.getString(Provider.CA_CERT, "");
- selectedProvider.setCACert(caCert);
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
- if (preferences.getBoolean(PROVIDER_ALLOW_ANONYMOUS, false)) {
- mConfigState.putExtra(SERVICES_RETRIEVED, true);
-
- downloadVpnCertificate();
- } else {
- mProgressBar.incrementProgressBy(1);
- hideProgressBar();
-
- }
- } else if (resultCode == ProviderAPI.PROVIDER_NOK) {
- mConfigState.setAction(PROVIDER_NOT_SET);
- preferences.edit().remove(Provider.KEY).apply();
+ void handleProviderSetUp() {
+ try {
+ String providerJsonString = preferences.getString(Provider.KEY, "");
+ if (!providerJsonString.isEmpty())
+ selectedProvider.define(new JSONObject(providerJsonString));
+ String caCert = preferences.getString(Provider.CA_CERT, "");
+ selectedProvider.setCACert(caCert);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
- setResult(RESULT_CANCELED, mConfigState);
+ if (preferences.getBoolean(PROVIDER_ALLOW_ANONYMOUS, false)) {
+ mConfigState.putExtra(SERVICES_RETRIEVED, true);
- String reason_to_fail = resultData.getString(ERRORS);
- showDownloadFailedDialog(reason_to_fail);
- } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
+ downloadVpnCertificate();
+ } else {
mProgressBar.incrementProgressBy(1);
hideProgressBar();
+
showProviderDetails();
- } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
- mConfigState.setAction(PROVIDER_NOT_SET);
- hideProgressBar();
- setResult(RESULT_CANCELED, mConfigState);
+ }
+ }
+
+ void handleProviderSetupFailed(Bundle resultData) {
+ mConfigState.setAction(PROVIDER_NOT_SET);
+ preferences.edit().remove(Provider.KEY).apply();
+
+ setResult(RESULT_CANCELED, mConfigState);
+
+ String reasonToFail = resultData.getString(ERRORS);
+ showDownloadFailedDialog(reasonToFail);
+ }
+
+ void handleCorrectlyDownloadedCertificate() {
+ mProgressBar.incrementProgressBy(1);
+ hideProgressBar();
+ showProviderDetails();
+ }
+
+ void handleIncorrectlyDownloadedCertificate() {
+ mConfigState.setAction(PROVIDER_NOT_SET);
+ hideProgressBar();
+ setResult(RESULT_CANCELED, mConfigState);
+ }
+
+ @Override
+ public void onReceiveResult(int resultCode, Bundle resultData) {
+ if (resultCode == ProviderAPI.PROVIDER_OK) {
+ handleProviderSetUp();
} else if (resultCode == AboutFragment.VIEWED) {
// Do nothing, right now
// I need this for CW to wait for the About activity to end before going back to Dashboard.
@@ -274,7 +288,6 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
@OnItemClick(R.id.provider_list)
void onItemSelected(int position) {
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction()) ||
- PENDING_SHOW_PROVIDER_DETAILS.equals(mConfigState.getAction()) ||
PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) {
return;
}
@@ -294,7 +307,6 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
@Override
public void onBackPressed() {
if (SETTING_UP_PROVIDER.equals(mConfigState.getAction()) ||
- PENDING_SHOW_PROVIDER_DETAILS.equals(mConfigState.getAction()) ||
PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) {
stopSettingUpProvider();
} else {
@@ -326,7 +338,6 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
Intent providerAPICommand = new Intent(this, ProviderAPI.class);
providerAPICommand.setAction(ProviderAPI.UPDATE_PROVIDER_DETAILS);
- providerAPICommand.putExtra(ProviderAPI.RECEIVER_KEY, providerAPIResultReceiver);
Bundle parameters = new Bundle();
parameters.putString(Provider.MAIN_URL, selectedProvider.getMainUrl().toString());
providerAPICommand.putExtra(ProviderAPI.PARAMETERS, parameters);
@@ -334,6 +345,13 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
startService(providerAPICommand);
}
+ public void checkProviderSetUp() {
+ Intent providerAPICommand = new Intent(this, ProviderAPI.class);
+ providerAPICommand.setAction(PROVIDER_SET_UP);
+ providerAPICommand.putExtra(ProviderAPI.RECEIVER_KEY, providerAPIResultReceiver);
+ startService(providerAPICommand);
+ }
+
private void askDashboardToQuitApp() {
Intent askQuit = new Intent();
askQuit.putExtra(APP_ACTION_QUIT, APP_ACTION_QUIT);
@@ -373,10 +391,7 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
*/
private void downloadVpnCertificate() {
Intent providerAPICommand = new Intent(this, ProviderAPI.class);
-
providerAPICommand.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE);
- providerAPICommand.putExtra(ProviderAPI.RECEIVER_KEY, providerAPIResultReceiver);
-
startService(providerAPICommand);
}
@@ -404,7 +419,7 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
/**
* Shows an error dialog, if configuring of a provider failed.
*
- * @param reasonToFail
+ * @param reasonToFail - the reason it has failed
*/
public void showDownloadFailedDialog(String reasonToFail) {
try {
@@ -435,14 +450,11 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
*/
public void showProviderDetails() {
// show only if current activity is shown
- if (isActivityShowing) {
+ if (isActivityShowing && !mConfigState.getAction().equalsIgnoreCase(SHOWING_PROVIDER_DETAILS)) {
mConfigState.setAction(SHOWING_PROVIDER_DETAILS);
Intent intent = new Intent(this, ProviderDetailActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
- } else {
- // may be called AFTER onSaveInstanceState (!)
- mConfigState.setAction(PENDING_SHOW_PROVIDER_DETAILS);
}
}
@@ -475,8 +487,34 @@ public abstract class BaseConfigurationWizard extends ButterKnifeActivity
public class ProviderAPIBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- int update = intent.getIntExtra(ProviderAPI.CURRENT_PROGRESS, 0);
- mProgressBar.setProgress(update);
+ String action = intent.getAction();
+
+ if (action == null) {
+ return;
+ }
+
+ if (action.equalsIgnoreCase(UPDATE_PROGRESSBAR)) {
+ int update = intent.getIntExtra(ProviderAPI.CURRENT_PROGRESS, 0);
+ mProgressBar.setProgress(update);
+ } else if (action.equalsIgnoreCase(PROVIDER_API_EVENT)) {
+ int resultCode = intent.getIntExtra(RESULT_CODE, -1);
+
+ switch (resultCode) {
+ case PROVIDER_OK:
+ handleProviderSetUp();
+ break;
+ case PROVIDER_NOK:
+ handleProviderSetupFailed((Bundle) intent.getParcelableExtra(RESULT_KEY));
+ break;
+ case CORRECTLY_DOWNLOADED_CERTIFICATE:
+ handleCorrectlyDownloadedCertificate();
+ break;
+ case INCORRECTLY_DOWNLOADED_CERTIFICATE:
+ handleIncorrectlyDownloadedCertificate();
+ break;
+
+ }
+ }
}
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 901dee89..82ff9db8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -274,7 +274,7 @@ public class Dashboard extends ButterKnifeActivity {
.setPositiveButton(getResources().getString(R.string.setup_error_configure_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- startActivityForResult(new Intent(getApplicationContext(), ConfigurationWizard.class), REQUEST_CODE_CONFIGURE_LEAP);
+ startActivityForResult(new Intent(Dashboard.this, ConfigurationWizard.class), REQUEST_CODE_CONFIGURE_LEAP);
}
})
.setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java
index 1b36d807..a5cbf5f5 100644
--- a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java
@@ -2,6 +2,7 @@ package se.leap.bitmaskclient;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.util.Log;
import butterknife.OnClick;
@@ -21,6 +22,11 @@ public class LoginActivity extends ProviderCredentialsBaseActivity {
}
@Override
+ protected void onResume() {
+ super.onResume();
+ }
+
+ @Override
@OnClick(R.id.button)
void handleButton() {
login(getUsername(), getPassword());
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
index 3dc93539..ccc71a67 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java
@@ -47,12 +47,15 @@ public class ProviderAPI extends IntentService implements ProviderApiManagerBase
DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
PARAMETERS = "parameters",
RESULT_KEY = "result",
+ RESULT_CODE = "RESULT CODE",
RECEIVER_KEY = "receiver",
ERRORS = "errors",
ERRORID = "errorId",
UPDATE_PROGRESSBAR = "update_progressbar",
CURRENT_PROGRESS = "current_progress",
- DOWNLOAD_EIP_SERVICE = TAG + ".DOWNLOAD_EIP_SERVICE";
+ DOWNLOAD_EIP_SERVICE = TAG + ".DOWNLOAD_EIP_SERVICE",
+ PROVIDER_SET_UP = TAG + ".PROVIDER_SET_UP",
+ PROVIDER_API_EVENT = "PROVIDER_API_EVENT";
final public static int
SUCCESSFUL_LOGIN = 3,
@@ -106,7 +109,7 @@ public class ProviderAPI extends IntentService implements ProviderApiManagerBase
}
@Override
- public void broadcastProgress(Intent intent) {
+ public void broadcastEvent(Intent intent) {
sendBroadcast(intent);
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
index 2542759f..da2e4c8b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
@@ -73,6 +73,8 @@ import static se.leap.bitmaskclient.ProviderAPI.FAILED_LOGIN;
import static se.leap.bitmaskclient.ProviderAPI.FAILED_SIGNUP;
import static se.leap.bitmaskclient.ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE;
import static se.leap.bitmaskclient.ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE;
+import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_API_EVENT;
+import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_SET_UP;
import static se.leap.bitmaskclient.ProviderAPI.LOGOUT_FAILED;
import static se.leap.bitmaskclient.ProviderAPI.LOG_IN;
import static se.leap.bitmaskclient.ProviderAPI.LOG_OUT;
@@ -80,6 +82,7 @@ import static se.leap.bitmaskclient.ProviderAPI.PARAMETERS;
import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_NOK;
import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_OK;
import static se.leap.bitmaskclient.ProviderAPI.RECEIVER_KEY;
+import static se.leap.bitmaskclient.ProviderAPI.RESULT_CODE;
import static se.leap.bitmaskclient.ProviderAPI.RESULT_KEY;
import static se.leap.bitmaskclient.ProviderAPI.SET_UP_PROVIDER;
import static se.leap.bitmaskclient.ProviderAPI.SIGN_UP;
@@ -93,6 +96,7 @@ import static se.leap.bitmaskclient.R.string.error_io_exception_user_message;
import static se.leap.bitmaskclient.R.string.error_json_exception_user_message;
import static se.leap.bitmaskclient.R.string.error_no_such_algorithm_exception_user_message;
import static se.leap.bitmaskclient.R.string.malformed_url;
+import static se.leap.bitmaskclient.R.string.routes_info_excl;
import static se.leap.bitmaskclient.R.string.server_unreachable_message;
import static se.leap.bitmaskclient.R.string.service_is_down_error;
import static se.leap.bitmaskclient.R.string.warning_corrupted_provider_cert;
@@ -107,7 +111,7 @@ import static se.leap.bitmaskclient.R.string.warning_expired_provider_cert;
public abstract class ProviderApiManagerBase {
public interface ProviderApiServiceCallback {
- void broadcastProgress(Intent intent);
+ void broadcastEvent(Intent intent);
}
private ProviderApiServiceCallback serviceCallback;
@@ -171,50 +175,56 @@ public abstract class ProviderApiManagerBase {
Bundle result = setUpProvider(parameters);
if (go_ahead) {
if (result.getBoolean(RESULT_KEY)) {
- receiver.send(PROVIDER_OK, result);
+ sendToReceiverOrBroadcast(receiver, PROVIDER_OK, result);
} else {
- receiver.send(PROVIDER_NOK, result);
+ sendToReceiverOrBroadcast(receiver, PROVIDER_NOK, result);
}
}
} else if (action.equalsIgnoreCase(SIGN_UP)) {
UserStatus.updateStatus(UserStatus.SessionStatus.SIGNING_UP, resources);
Bundle result = tryToRegister(parameters);
if (result.getBoolean(RESULT_KEY)) {
- receiver.send(SUCCESSFUL_SIGNUP, result);
+ sendToReceiverOrBroadcast(receiver, SUCCESSFUL_SIGNUP, result);
} else {
- receiver.send(FAILED_SIGNUP, result);
+ sendToReceiverOrBroadcast(receiver, FAILED_SIGNUP, result);
}
} else if (action.equalsIgnoreCase(LOG_IN)) {
UserStatus.updateStatus(UserStatus.SessionStatus.LOGGING_IN, resources);
Bundle result = tryToAuthenticate(parameters);
if (result.getBoolean(RESULT_KEY)) {
- receiver.send(SUCCESSFUL_LOGIN, result);
+ sendToReceiverOrBroadcast(receiver, SUCCESSFUL_LOGIN, result);
UserStatus.updateStatus(UserStatus.SessionStatus.LOGGED_IN, resources);
} else {
- receiver.send(FAILED_LOGIN, result);
+ sendToReceiverOrBroadcast(receiver, FAILED_LOGIN, result);
UserStatus.updateStatus(UserStatus.SessionStatus.NOT_LOGGED_IN, resources);
}
} else if (action.equalsIgnoreCase(LOG_OUT)) {
UserStatus.updateStatus(UserStatus.SessionStatus.LOGGING_OUT, resources);
if (logOut()) {
- receiver.send(SUCCESSFUL_LOGOUT, Bundle.EMPTY);
+ sendToReceiverOrBroadcast(receiver, SUCCESSFUL_LOGOUT, Bundle.EMPTY);
UserStatus.updateStatus(UserStatus.SessionStatus.LOGGED_OUT, resources);
} else {
- receiver.send(LOGOUT_FAILED, Bundle.EMPTY);
+ sendToReceiverOrBroadcast(receiver, LOGOUT_FAILED, Bundle.EMPTY);
UserStatus.updateStatus(UserStatus.SessionStatus.DIDNT_LOG_OUT, resources);
}
} else if (action.equalsIgnoreCase(DOWNLOAD_CERTIFICATE)) {
if (updateVpnCertificate()) {
- receiver.send(CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
+ sendToReceiverOrBroadcast(receiver, CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
} else {
- receiver.send(INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
+ sendToReceiverOrBroadcast(receiver, 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);
+ sendToReceiverOrBroadcast(receiver, CORRECTLY_DOWNLOADED_EIP_SERVICE, result);
} else {
- receiver.send(INCORRECTLY_DOWNLOADED_EIP_SERVICE, result);
+ sendToReceiverOrBroadcast(receiver, INCORRECTLY_DOWNLOADED_EIP_SERVICE, result);
+ }
+ } else if (action.equalsIgnoreCase(PROVIDER_SET_UP)) {
+ if(EIP_SERVICE_JSON_DOWNLOADED && CA_CERT_DOWNLOADED && PROVIDER_JSON_DOWNLOADED ) {
+ if(receiver!= null) {
+ receiver.send(PROVIDER_OK, Bundle.EMPTY);
+ }
}
}
}
@@ -421,20 +431,36 @@ public abstract class ProviderApiManagerBase {
return userNotificationBundle;
}
+ void sendToReceiverOrBroadcast(ResultReceiver receiver, int resultCode, Bundle resultData) {
+ if (receiver != null) {
+ receiver.send(resultCode, resultData);
+ } else {
+ broadcastEvent(PROVIDER_API_EVENT, resultCode, resultData);
+ }
+ }
+
/**
* Sets up an intent with the progress value passed as a parameter
* and sends it as a broadcast.
*
* @param progress
*/
- protected void broadcastProgress(int progress) {
- Intent intentUpdate = new Intent();
- intentUpdate.setAction(UPDATE_PROGRESSBAR);
+ void broadcastProgress(int progress) {
+ Intent intentUpdate = new Intent(UPDATE_PROGRESSBAR);
intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
intentUpdate.putExtra(CURRENT_PROGRESS, progress);
- serviceCallback.broadcastProgress(intentUpdate);
+ serviceCallback.broadcastEvent(intentUpdate);
}
+ void broadcastEvent(String action, int resultCode , Bundle resultData) {
+ Intent intentUpdate = new Intent(action);
+ intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
+ intentUpdate.putExtra(RESULT_CODE, resultCode);
+ intentUpdate.putExtra(RESULT_KEY, resultData);
+ serviceCallback.broadcastEvent(intentUpdate);
+ }
+
+
/**
* Validates parameters entered by the user to log in
*