summaryrefslogtreecommitdiff
path: root/src/se
diff options
context:
space:
mode:
authorcyBerta <richy@cyborgsociety.org>2013-12-21 00:38:00 +0100
committercyBerta <richy@cyborgsociety.org>2013-12-21 00:38:00 +0100
commitb2efaf181fb7833206e97f64eb29400057a7d7ed (patch)
treee7a2715313e7a9b7786606280081f7dace026a5f /src/se
parent31e0ee7819ff6e852bc40f66858f0ac02659bf04 (diff)
parent16ac5c300e21ce4c8b380013735f2c17d2e34768 (diff)
Merge branch 'bug/more-detailed-response-to-CW-errors' into develop
Diffstat (limited to 'src/se')
-rw-r--r--src/se/leap/bitmaskclient/ConfigHelper.java3
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java97
-rw-r--r--src/se/leap/bitmaskclient/Dashboard.java5
-rw-r--r--src/se/leap/bitmaskclient/DownloadFailedDialog.java45
-rw-r--r--src/se/leap/bitmaskclient/EIP.java2
-rw-r--r--src/se/leap/bitmaskclient/NewProviderDialog.java8
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java162
-rw-r--r--src/se/leap/bitmaskclient/ProviderListAdapter.java8
-rw-r--r--src/se/leap/bitmaskclient/ProviderListFragment.java22
9 files changed, 284 insertions, 68 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigHelper.java b/src/se/leap/bitmaskclient/ConfigHelper.java
index dd7049a7..6b49d7d7 100644
--- a/src/se/leap/bitmaskclient/ConfigHelper.java
+++ b/src/se/leap/bitmaskclient/ConfigHelper.java
@@ -168,6 +168,9 @@ public class ConfigHelper {
return shared_preferences.getInt(shared_preferences_key, 0);
}
+ protected static boolean sharedPrefContainsKey(String shared_preferences_key) {
+ return shared_preferences.contains(shared_preferences_key);
+ }
/*
* This method defaults to false.
* If you use this method, be sure to fail-closed on false!
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 694dbf7c..2467c52f 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -22,9 +22,15 @@ import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
+
+import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
+import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
+
+import se.leap.bitmaskclient.DownloadFailedDialog.DownloadFailedDialogInterface;
+import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface;
+import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface;
+
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -61,7 +67,7 @@ import android.widget.TextView;
*
*/
public class ConfigurationWizard extends Activity
-implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, Receiver {
+implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderDetailFragmentInterface, DownloadFailedDialogInterface, Receiver {
private ProgressBar mProgressBar;
private TextView progressbar_description;
@@ -78,7 +84,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
public ProviderAPIResultReceiver providerAPI_result_receiver;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -189,9 +195,15 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
// resetOldConnection();
ProviderItem selected_provider = getProvider(id);
int provider_index = getProviderIndex(id);
- startProgressBar(provider_index);
- provider_list_fragment.hideAllBut(provider_index);
- setUpProvider(selected_provider.providerMainUrl(), true);
+
+
+ startProgressBar(provider_index+1);
+ provider_list_fragment.hideAllBut(provider_index);
+
+ boolean danger_on = true;
+ if(ConfigHelper.sharedPrefContainsKey(ProviderItem.DANGER_ON))
+ danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON);
+ setUpProvider(selected_provider.providerMainUrl(), danger_on);
}
@Override
@@ -235,6 +247,13 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
return "";
}
+
+
+ private void startProgressBar() {
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
+ mProgressBar.setProgress(0);
+ mProgressBar.setMax(3);
+ }
private void startProgressBar(int list_item_index) {
mProgressBar.setVisibility(ProgressBar.VISIBLE);
@@ -253,8 +272,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
ProviderItem provider = providers_iterator.next();
if(provider.name().equalsIgnoreCase(id)) {
break;
- }
- index++;
+//<<<<<<< HEAD
+// }
+// index++;
+//=======
+ } else index++;
+//>>>>>>> bug/more-detailed-response-to-CW-errors
}
return index;
}
@@ -340,6 +363,24 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
/**
+ * Open the new provider dialog with data
+ */
+ public void addAndSelectNewProvider(String main_url, boolean danger_on) {
+ FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
+ Fragment previous_new_provider_dialog = getFragmentManager().findFragmentByTag(NewProviderDialog.TAG);
+ if (previous_new_provider_dialog != null) {
+ fragment_transaction.remove(previous_new_provider_dialog);
+ }
+
+ DialogFragment newFragment = NewProviderDialog.newInstance();
+ Bundle data = new Bundle();
+ data.putString(Provider.MAIN_URL, main_url);
+ data.putBoolean(ProviderItem.DANGER_ON, danger_on);
+ newFragment.setArguments(data);
+ newFragment.show(fragment_transaction, NewProviderDialog.TAG);
+ }
+
+ /**
* Once selected a provider, this fragment offers the user to log in,
* use it anonymously (if possible)
* or cancel his/her election pressing the back button.
@@ -388,6 +429,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
private void autoSelectProvider(String provider_main_url, boolean danger_on) {
+
+ ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
onItemSelected(getId(provider_main_url));
}
@@ -406,10 +449,24 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters);
provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
-
- startService(provider_API_command);
- }
-
+
+ startService(provider_API_command);
+ }
+
+ public void retrySetUpProvider() {
+ cancelSettingUpProvider();
+ if(!ProviderAPI.caCertDownloaded()) {
+ addAndSelectNewProvider(ProviderAPI.lastProviderMainUrl(), ProviderAPI.lastDangerOn());
+ } else {
+ Intent provider_API_command = new Intent(this, ProviderAPI.class);
+
+ provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
+
+ startService(provider_API_command);
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.configuration_wizard_activity, menu);
@@ -452,6 +509,18 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
if(provider_list_fragment != null)
provider_list_fragment.unhideAll();
}
+
+ public void cancelSettingUpProvider() {
+ provider_list_fragment = (ProviderListFragment) getFragmentManager().findFragmentByTag(ProviderListFragment.TAG);
+ if(provider_list_fragment != null && ConfigHelper.sharedPrefContainsKey(ProviderItem.DANGER_ON)) {
+ provider_list_fragment.removeLastItem();
+ }
+
+ ConfigHelper.removeFromSharedPref(Provider.KEY);
+ ConfigHelper.removeFromSharedPref(ProviderItem.DANGER_ON);
+ ConfigHelper.removeFromSharedPref(EIP.ALLOWED_ANON);
+ ConfigHelper.removeFromSharedPref(EIP.KEY);
+ }
@Override
public void login() {
diff --git a/src/se/leap/bitmaskclient/Dashboard.java b/src/se/leap/bitmaskclient/Dashboard.java
index 01a9c20a..d37479a2 100644
--- a/src/se/leap/bitmaskclient/Dashboard.java
+++ b/src/se/leap/bitmaskclient/Dashboard.java
@@ -88,7 +88,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
// mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
// eipStatus = (TextView) findViewById(R.id.eipStatus);
-
mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
ConfigHelper.setSharedPreferences(getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE));
@@ -113,6 +112,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
if ( resultCode == RESULT_OK ){
ConfigHelper.saveSharedPref(EIP.PARSED_SERIAL, 0);
ConfigHelper.saveSharedPref(EIP.AUTHED_EIP, authed_eip);
+
startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
buildDashboard();
@@ -167,6 +167,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
providerNameTV = (TextView) findViewById(R.id.providerName);
providerNameTV.setText(provider.getDomain());
providerNameTV.setTextSize(28);
+
+ mProgressBar = (ProgressBar) findViewById(R.id.eipProgress);
FragmentManager fragMan = getFragmentManager();
if ( provider.hasEIP()){
@@ -466,5 +468,4 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
startService(eip_intent);
}
-
}
diff --git a/src/se/leap/bitmaskclient/DownloadFailedDialog.java b/src/se/leap/bitmaskclient/DownloadFailedDialog.java
index 3ce101a6..f78002b0 100644
--- a/src/se/leap/bitmaskclient/DownloadFailedDialog.java
+++ b/src/se/leap/bitmaskclient/DownloadFailedDialog.java
@@ -14,9 +14,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
- package se.leap.bitmaskclient;
+package se.leap.bitmaskclient;
import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface;
+import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
@@ -42,18 +45,50 @@ public class DownloadFailedDialog extends DialogFragment {
return dialog_fragment;
}
- @Override
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-
+
builder.setMessage(reason_to_fail)
- .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ .setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dismiss();
+ interface_with_ConfigurationWizard.retrySetUpProvider();
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
+ interface_with_ConfigurationWizard.cancelSettingUpProvider();
dialog.dismiss();
}
});
-
+
// Create the AlertDialog object and return it
return builder.create();
}
+
+ public interface DownloadFailedDialogInterface {
+ public void retrySetUpProvider();
+ public void cancelSettingUpProvider();
+ }
+
+ DownloadFailedDialogInterface interface_with_ConfigurationWizard;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement NoticeDialogListener");
+ }
+ }
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ interface_with_ConfigurationWizard.cancelSettingUpProvider();
+ dialog.dismiss();
+ }
+
}
diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java
index edd73e83..2b7fd39f 100644
--- a/src/se/leap/bitmaskclient/EIP.java
+++ b/src/se/leap/bitmaskclient/EIP.java
@@ -58,10 +58,10 @@ import android.util.Log;
*/
public final class EIP extends IntentService {
+ public final static String AUTHED_EIP = "authed eip";
public final static String ACTION_START_EIP = "se.leap.bitmaskclient.START_EIP";
public final static String ACTION_STOP_EIP = "se.leap.bitmaskclient.STOP_EIP";
public final static String ACTION_UPDATE_EIP_SERVICE = "se.leap.bitmaskclient.UPDATE_EIP_SERVICE";
- public final static String AUTHED_EIP = "authed_eip";
public final static String ACTION_IS_EIP_RUNNING = "se.leap.bitmaskclient.IS_RUNNING";
public final static String EIP_NOTIFICATION = "EIP_NOTIFICATION";
public final static String ALLOWED_ANON = "allow_anonymous";
diff --git a/src/se/leap/bitmaskclient/NewProviderDialog.java b/src/se/leap/bitmaskclient/NewProviderDialog.java
index 98686bd2..cf09c64b 100644
--- a/src/se/leap/bitmaskclient/NewProviderDialog.java
+++ b/src/se/leap/bitmaskclient/NewProviderDialog.java
@@ -16,6 +16,7 @@
*/
package se.leap.bitmaskclient;
+import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
import se.leap.bitmaskclient.R;
import android.app.Activity;
import android.app.AlertDialog;
@@ -71,7 +72,14 @@ public class NewProviderDialog extends DialogFragment {
LayoutInflater inflater = getActivity().getLayoutInflater();
View new_provider_dialog_view = inflater.inflate(R.layout.new_provider_dialog, null);
final EditText url_input_field = (EditText)new_provider_dialog_view.findViewById(R.id.new_provider_url);
+ if(getArguments() != null && getArguments().containsKey(Provider.MAIN_URL)) {
+ url_input_field.setText(getArguments().getString(Provider.MAIN_URL));
+ }
final CheckBox danger_checkbox = (CheckBox)new_provider_dialog_view.findViewById(R.id.danger_checkbox);
+ if(getArguments() != null && getArguments().containsKey(ProviderItem.DANGER_ON)) {
+ danger_checkbox.setActivated(getArguments().getBoolean(ProviderItem.DANGER_ON));
+ }
+
builder.setView(new_provider_dialog_view)
.setMessage(R.string.introduce_new_provider)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index cc94edff..ff6dd852 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -59,7 +59,6 @@ import org.apache.http.client.ClientProtocolException;
import org.jboss.security.srp.SRPParameters;
import org.json.JSONException;
import org.json.JSONObject;
-import org.json.JSONStringer;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
@@ -70,7 +69,7 @@ import android.os.Handler;
import android.os.ResultReceiver;
import android.util.Base64;
import android.util.Log;
-import android.widget.Toast;
+
/**
* Implements HTTP api methods used to manage communications with the provider server.
@@ -98,8 +97,8 @@ public class ProviderAPI extends IntentService {
SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
SESSION_ID_KEY = "session_id",
ERRORS = "errors",
- UPDATE_PROGRESSBAR = "update_action",
- CURRENT_PROGRESS = "update data",
+ UPDATE_PROGRESSBAR = "update_progressbar",
+ CURRENT_PROGRESS = "current_progress",
TAG = "provider_api_tag"
;
@@ -119,6 +118,15 @@ public class ProviderAPI extends IntentService {
INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
;
+ private static boolean
+ CA_CERT_DOWNLOADED = false,
+ PROVIDER_JSON_DOWNLOADED = false,
+ EIP_SERVICE_JSON_DOWNLOADED = false
+ ;
+
+ private static String last_provider_main_url;
+ private static boolean last_danger_on = false;
+
public ProviderAPI() {
super("ProviderAPI");
Log.v("ClassName", "Provider API");
@@ -131,22 +139,30 @@ public class ProviderAPI extends IntentService {
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER) );
}
+ public static String lastProviderMainUrl() {
+ return last_provider_main_url;
+ }
+
+ public static boolean lastDangerOn() {
+ return last_danger_on;
+ }
+
private String formatErrorMessage(final int toast_string_id) {
return "{ \"" + ERRORS + "\" : \""+getResources().getString(toast_string_id)+"\" }";
}
@Override
protected void onHandleIntent(Intent command) {
- final ResultReceiver receiver = command.getParcelableExtra("receiver");
+ final ResultReceiver receiver = command.getParcelableExtra(RECEIVER_KEY);
String action = command.getAction();
Bundle parameters = command.getBundleExtra(PARAMETERS);
if(action.equalsIgnoreCase(SET_UP_PROVIDER)) {
Bundle result = setUpProvider(parameters);
if(result.getBoolean(RESULT_KEY)) {
- receiver.send(PROVIDER_OK, result);
+ receiver.send(PROVIDER_OK, Bundle.EMPTY);
} else {
- receiver.send(PROVIDER_NOK, Bundle.EMPTY);
+ receiver.send(PROVIDER_NOK, result);
}
} else if (action.equalsIgnoreCase(SRP_AUTH)) {
Bundle session_id_bundle = authenticateBySRP(parameters);
@@ -418,38 +434,85 @@ public class ProviderAPI extends IntentService {
return result.toString();
}
+
+
+
+
/**
* Downloads a provider.json from a given URL, adding a new provider using the given name.
* @param task containing a boolean meaning if the provider is custom or not, another boolean meaning if the user completely trusts this provider, the provider name and its provider.json url.
* @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the update was successful.
*/
private Bundle setUpProvider(Bundle task) {
- Bundle result = new Bundle();
+//<<<<<<< HEAD
+// Bundle result = new Bundle();
+// int progress = 0;
+// boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
+// String provider_main_url = task.getString(Provider.MAIN_URL);
+// if(downloadCACert(provider_main_url, danger_on)) {
+// broadcast_progress(progress++);
+// result.putBoolean(RESULT_KEY, true);
+// if(getAndSetProviderJson(provider_main_url)) {
+// broadcast_progress(progress++);
+// if(getAndSetEipServiceJson())
+// broadcast_progress(progress++);
+// }
+// }
+// return result;
+// }
+//
+//
+//=======
int progress = 0;
- boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
- String provider_main_url = task.getString(Provider.MAIN_URL);
- if(downloadCACert(provider_main_url, danger_on)) {
+ Bundle current_download = new Bundle();
+
+ if(task != null && task.containsKey(ProviderItem.DANGER_ON) && task.containsKey(Provider.MAIN_URL)) {
+ 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;
+ }
+
+ if(!CA_CERT_DOWNLOADED)
+ current_download = downloadCACert(last_provider_main_url, last_danger_on);
+ if(CA_CERT_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
broadcast_progress(progress++);
- result.putBoolean(RESULT_KEY, true);
- if(getAndSetProviderJson(provider_main_url)) {
+ CA_CERT_DOWNLOADED = true;
+ 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++);
- if(getAndSetEipServiceJson())
+ PROVIDER_JSON_DOWNLOADED = true;
+ current_download = getAndSetEipServiceJson();
+ if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
broadcast_progress(progress++);
+ EIP_SERVICE_JSON_DOWNLOADED = true;
+ }
}
}
- return result;
+
+ return current_download;
}
- private boolean downloadCACert(String provider_main_url, boolean danger_on) {
+ private Bundle downloadCACert(String provider_main_url, boolean danger_on) {
+ Bundle result = new Bundle();
String cert_string = downloadWithCommercialCA(provider_main_url + "/ca.crt", danger_on);
- if(validCertificate(cert_string))
+ if(validCertificate(cert_string)) {
ConfigHelper.saveSharedPref(Provider.CA_CERT, cert_string);
- else
- return false;
+ result.putBoolean(RESULT_KEY, true);
+ } else {
+ String reason_to_fail = pickErrorMessage(cert_string);
+ result.putString(ERRORS, reason_to_fail);
+ result.putBoolean(RESULT_KEY, false);
+ }
- return true;
+ return result;
}
+
+ public static boolean caCertDownloaded() {
+ return CA_CERT_DOWNLOADED;
+ }
+
private boolean validCertificate(String cert_string) {
boolean result = false;
if(!ConfigHelper.checkErroneousDownload(cert_string)) {
@@ -465,8 +528,8 @@ public class ProviderAPI extends IntentService {
return result;
}
- private boolean getAndSetProviderJson(String provider_main_url) {
- boolean result = false;
+ private Bundle getAndSetProviderJson(String provider_main_url) {
+ Bundle result = new Bundle();
String provider_dot_json_string = downloadWithProviderCA(provider_main_url + "/provider.json", true);
@@ -477,31 +540,67 @@ public class ProviderAPI extends IntentService {
ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
- ProviderItem added_provider = new ProviderItem(name, provider_main_url);
-
- result = true;
+
+ result.putBoolean(RESULT_KEY, true);
} catch (JSONException e) {
+ //TODO Error message should be contained in that provider_dot_json_string
+ String reason_to_fail = pickErrorMessage(provider_dot_json_string);
+ result.putString(ERRORS, reason_to_fail);
+ result.putBoolean(RESULT_KEY, false);
}
return result;
}
+
- private boolean getAndSetEipServiceJson() {
- boolean result = false;
+ public static boolean providerJsonDownloaded() {
+ return PROVIDER_JSON_DOWNLOADED;
+ }
+ private Bundle getAndSetEipServiceJson() {
+ Bundle result = new Bundle();
+ String eip_service_json_string = "";
try {
JSONObject provider_json = ConfigHelper.getJsonFromSharedPref(Provider.KEY);
String eip_service_url = provider_json.getString(Provider.API_URL) + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.SERVICE_API_PATH;
- String eip_service_json_string = downloadWithProviderCA(eip_service_url, true);
+ eip_service_json_string = downloadWithProviderCA(eip_service_url, true);
JSONObject eip_service_json = new JSONObject(eip_service_json_string);
eip_service_json.getInt(Provider.API_RETURN_SERIAL);
ConfigHelper.saveSharedPref(EIP.KEY, eip_service_json);
- result = true;
+
+ result.putBoolean(RESULT_KEY, true);
} catch (JSONException e) {
+ String reason_to_fail = pickErrorMessage(eip_service_json_string);
+ result.putString(ERRORS, reason_to_fail);
+ result.putBoolean(RESULT_KEY, false);
}
return result;
}
+
+ public static boolean eipServiceDownloaded() {
+ return EIP_SERVICE_JSON_DOWNLOADED;
+ }
+
+ /**
+ * Interprets the error message as a JSON object and extract the "errors" keyword pair.
+ * If the error message is not a JSON object, then it is returned untouched.
+ * @param string_json_error_message
+ * @return final error message
+ */
+ private String pickErrorMessage(String string_json_error_message) {
+ String error_message = "";
+ try {
+ JSONObject json_error_message = new JSONObject(string_json_error_message);
+ error_message = json_error_message.getString(ERRORS);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ error_message = string_json_error_message;
+ }
+
+ return error_message;
+ }
+
/**
* Tries to download the contents of the provided url using commercially validated CA certificate from chosen provider.
*
@@ -723,10 +822,9 @@ public class ProviderAPI extends IntentService {
URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIP.CERTIFICATE);
boolean danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON);
-//<<<<<<< HEAD
-// String cert_string = downloadWithProviderCA(new_cert_string_url, true);
-//=======
+
String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), danger_on);
+
if(!cert_string.isEmpty()) {
if(ConfigHelper.checkErroneousDownload(cert_string)) {
String reason_to_fail = provider_json.getString(ERRORS);
diff --git a/src/se/leap/bitmaskclient/ProviderListAdapter.java b/src/se/leap/bitmaskclient/ProviderListAdapter.java
index 4abf15a2..c5e8b64d 100644
--- a/src/se/leap/bitmaskclient/ProviderListAdapter.java
+++ b/src/se/leap/bitmaskclient/ProviderListAdapter.java
@@ -86,6 +86,14 @@ public class ProviderListAdapter<T> extends ArrayAdapter<T> {
new_hidden[hidden.length] = false;
hidden = new_hidden;
}
+
+ @Override
+ public void remove(T item) {
+ super.remove(item);
+ boolean[] new_hidden = new boolean[hidden.length-1];
+ System.arraycopy(hidden, 0, new_hidden, 0, hidden.length-1);
+ hidden = new_hidden;
+ }
@Override
public View getView(int index, View convertView, ViewGroup parent) {
diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java
index f074e665..45047982 100644
--- a/src/se/leap/bitmaskclient/ProviderListFragment.java
+++ b/src/se/leap/bitmaskclient/ProviderListFragment.java
@@ -19,7 +19,6 @@
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
import android.app.Activity;
-import android.app.DialogFragment;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -156,14 +155,11 @@ public class ProviderListFragment extends ListFragment {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mCallbacks.onItemSelected(ProviderListContent.ITEMS.get(position).name());
-//<<<<<<< HEAD
-//=======
-
+
for(int item_position = 0; item_position < listView.getCount(); item_position++) {
if(item_position != position)
content_adapter.hide(item_position);
}
-//>>>>>>> feature/token-based-auth
}
@Override
@@ -200,13 +196,18 @@ public class ProviderListFragment extends ListFragment {
mActivatedPosition = position;
}
+ public void removeLastItem() {
+ unhideAll();
+ content_adapter.remove(content_adapter.getItem(content_adapter.getCount()-1));
+ content_adapter.notifyDataSetChanged();
+ }
+
public void addItem(ProviderItem provider) {
content_adapter.add(provider);
content_adapter.notifyDataSetChanged();
}
public void hideAllBut(int position) {
-//<<<<<<< HEAD
int real_count = content_adapter.getCount();
for(int i = 0; i < real_count;)
if(i != position) {
@@ -215,14 +216,7 @@ public class ProviderListFragment extends ListFragment {
real_count--;
} else {
i++;
- }
-//=======
-/* for(int i = 0; i < content_adapter.getCount(); i++)
- if(i != position)
- content_adapter.hide(i);
- else
- content_adapter.unHide(i);
-*///>>>>>>> feature/token-based-auth
+ }
}
public void unhideAll() {