diff options
| -rwxr-xr-x | res/values/strings.xml | 4 | ||||
| -rw-r--r-- | src/se/leap/leapclient/ConfigurationWizard.java | 11 | ||||
| -rw-r--r-- | src/se/leap/leapclient/ProviderAPI.java | 36 | 
3 files changed, 36 insertions, 15 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 0cc3593..6f06ab6 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -291,7 +291,9 @@      <string name="incorrectly_downloaded_json_files_message">You have not entered a LEAP provider URL or it is unavailable</string>      <string name="correctly_downloaded_json_files_message">Your anon cert has been correctly downloaded</string>      <string name="incorrectly_downloaded_certificate_message">Your anon cert was not downloaded</string> -    <string name="incorrectly_updated_provider_dot_json_message">Server is down.</string> +    <string name="server_is_down_message">Server is down.</string> +    <string name="malformed_url">It doesn\'t seem to be a LEAP provider.</string> +    <string name="certificate_error">This is not a trusted LEAP provider.</string>      <string name="not_valid_password_message">Your password is not well-formed: it should have at least 8 characters.</string>      <string name="succesful_authentication_message">Authentication succeeded.</string>      <string name="authentication_failed_message">Authentication failed.</string> diff --git a/src/se/leap/leapclient/ConfigurationWizard.java b/src/se/leap/leapclient/ConfigurationWizard.java index df7da8f..840e4e6 100644 --- a/src/se/leap/leapclient/ConfigurationWizard.java +++ b/src/se/leap/leapclient/ConfigurationWizard.java @@ -101,13 +101,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn  				e.printStackTrace();
  				mProgressDialog.dismiss();
 -				Toast.makeText(this, getResources().getString(R.string.config_error_parsing), Toast.LENGTH_LONG);
 +				//Toast.makeText(this, getResources().getString(R.string.config_error_parsing), Toast.LENGTH_LONG);
  				setResult(RESULT_CANCELED, mConfigState);
  			}
  		}
  		else if(resultCode == ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
  			mProgressDialog.dismiss();
 -			Toast.makeText(getApplicationContext(), R.string.incorrectly_updated_provider_dot_json_message, Toast.LENGTH_LONG).show();
  			setResult(RESULT_CANCELED, mConfigState);
  		}
  		else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES) {
 @@ -123,20 +122,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn  			}
  		}
  		else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES) {
 -			Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message, Toast.LENGTH_LONG).show();
 +			//Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message, Toast.LENGTH_LONG).show();
  			setResult(RESULT_CANCELED, mConfigState);
  		}
  		else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE) {
  			mProgressDialog.dismiss();
 -			//Toast.makeText(getApplicationContext(), R.string.correctly_downloaded_json_files_message, Toast.LENGTH_LONG).show();
 -			//Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
 -			//mConfigState.putExtra(CERTIFICATE_RETRIEVED, true); // If this isn't the last step and finish() is moved...
  			setResult(RESULT_OK);
 -			//finish();
  			showProviderDetails(getCurrentFocus());
  		} else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
  			mProgressDialog.dismiss();
 -			Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_certificate_message, Toast.LENGTH_LONG).show();
 +			//Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_certificate_message, Toast.LENGTH_LONG).show();
          	setResult(RESULT_CANCELED, mConfigState);
  		}
  	}
 diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java index 11ad2e1..4f98e42 100644 --- a/src/se/leap/leapclient/ProviderAPI.java +++ b/src/se/leap/leapclient/ProviderAPI.java @@ -21,6 +21,7 @@ import java.net.SocketTimeoutException;  import java.net.URISyntaxException;  import java.net.URL;  import java.net.URLConnection; +import java.net.UnknownHostException;  import java.util.Scanner;  import javax.net.ssl.HostnameVerifier; @@ -52,9 +53,11 @@ import se.leap.leapclient.ProviderListContent.ProviderItem;  import android.app.IntentService;  import android.content.Intent;  import android.os.Bundle; +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. @@ -67,10 +70,28 @@ import android.util.Log;   */  public class ProviderAPI extends IntentService { +	private Handler mHandler; +  	public ProviderAPI() {  		super("ProviderAPI");  		Log.v("ClassName", "Provider API");  	} +	 +	@Override +	public void onCreate() { +		super.onCreate(); +		mHandler = new Handler(); +	} +	 +	private void displayToast(final int toast_string_id) { +		mHandler.post(new Runnable() { +			 +			@Override +			public void run() { +	            Toast.makeText(ProviderAPI.this, toast_string_id, Toast.LENGTH_LONG).show();                 +			} +		}); +	}  	@Override  	protected void onHandleIntent(Intent task_for) { @@ -304,7 +325,7 @@ public class ProviderAPI extends IntentService {  			provider_json = getJSONFromProvider(provider_json_url, danger_on);  			if(provider_json == null) {  				result.putBoolean(ConfigHelper.RESULT_KEY, false); -			} else {    			 +			} else {  				ConfigHelper.saveSharedPref(ConfigHelper.PROVIDER_KEY, provider_json);  				ConfigHelper.saveSharedPref(ConfigHelper.DANGER_ON, danger_on); @@ -344,13 +365,14 @@ public class ProviderAPI extends IntentService {  			url_connection.setConnectTimeout(seconds_of_timeout*1000);  			json_file_content = new Scanner(url_connection.getInputStream()).useDelimiter("\\A").next();  		} catch (MalformedURLException e) { -			// TODO Auto-generated catch block -			e.printStackTrace(); +			displayToast(R.string.malformed_url);  		} catch(SocketTimeoutException e) { -			return ""; +			displayToast(R.string.server_is_down_message);  		} catch (IOException e) {  			if(provider_url != null && danger_on) {  				json_file_content = getStringFromProviderWithoutValidate(provider_url); +			} else { +				displayToast(R.string.certificate_error);  			}  		} catch (Exception e) {  			if(provider_url != null && danger_on) { @@ -385,8 +407,7 @@ public class ProviderAPI extends IntentService {  			urlConnection.setHostnameVerifier(hostnameVerifier);  			json_string = new Scanner(urlConnection.getInputStream()).useDelimiter("\\A").next();  		} catch (MalformedURLException e) { -			// TODO Auto-generated catch block -			e.printStackTrace(); +			displayToast(R.string.malformed_url);  		} catch (IOException e) {  			json_string = getStringFromProviderWithCACertAdded(string_url);  		} @@ -447,9 +468,12 @@ public class ProviderAPI extends IntentService {  		} catch (CertificateException e) {  			// TODO Auto-generated catch block  			e.printStackTrace(); +		} catch (UnknownHostException e) { +			displayToast(R.string.server_is_down_message);  		} catch (IOException e) {  			// The downloaded certificate doesn't validate our https connection.  			json_file_content = getStringFromProviderIgnoringCertificate(url); +			displayToast(R.string.certificate_error);  		} catch (KeyStoreException e) {  			// TODO Auto-generated catch block  			e.printStackTrace();  | 
