2012-06-21 Santiago Munin <burning1@gmail.com>

* src/pandroid_event_viewer/pandorafms/Core.java: Added a new method which checks if a website is online.
	* src/pandroid_event_viewer/pandorafms/Options.java: Fixed a bug. The app didn't check if the url were online before checking the certificate.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6673 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
santimunin 2012-06-21 22:11:22 +00:00
parent 7d76c88f9a
commit 97e7748602
3 changed files with 61 additions and 30 deletions

View File

@ -1,3 +1,7 @@
2012-06-21 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Added a new method which checks if a website is online.
* src/pandroid_event_viewer/pandorafms/Options.java: Fixed a bug. The app didn't check if the url were online before checking the certificate.
2012-06-21 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/EventList.java: Restored to the previous version.
* src/pandroid_event_viewer/pandorafms/Core.java: Added a line which checks if the connection is secure.

View File

@ -386,7 +386,7 @@ public class Core {
return img;
}
} catch (IOException e) {
Log.e(TAG, "Downloading image "+fileUrl+": error");
Log.e(TAG, "Downloading image " + fileUrl + ": error");
}
return null;
}
@ -437,13 +437,15 @@ public class Core {
* Finds out if the given url has a CA signed certificate.
*
* @param url
* @return
* @return boolean
* @throws IOException
* If the given url is not accessible.
*/
public static boolean isValidCertificate(URL url) {
HttpsURLConnection con;
try {
con = (HttpsURLConnection) url.openConnection();
con.getResponseCode();
con.connect();
con.disconnect();
return true;
@ -452,6 +454,24 @@ public class Core {
}
}
public static boolean isOnline(URL url) {
HttpsURLConnection con;
try {
con = (HttpsURLConnection) url.openConnection();
con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
con.setSSLSocketFactory(getSocketFactory());
if (con.getResponseCode()!=400) {
return false;
} else return true;
} catch (IOException e) {
return true;
}
}
public static String httpsGet(String url,
List<NameValuePair> additionalParameters) {
String result = "";
@ -487,7 +507,7 @@ public class Core {
String temp;
while ((temp = bufferedReader.readLine()) != null) {
Log.d("CONTENT", temp);
result += temp+"\n";
result += temp + "\n";
}
} catch (IOException e) {
return "";

View File

@ -315,41 +315,48 @@ public class Options extends Activity {
private class CheckCertificateAsyncTask extends
AsyncTask<URL, Void, Boolean> {
private URL url;
@Override
protected Boolean doInBackground(URL... arg0) {
url = arg0[0];
return Core.isValidCertificate(arg0[0]);
}
@Override
protected void onPostExecute(Boolean result) {
retrievingCertificate.dismiss();
if (!result) {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
Toast.makeText(getApplicationContext(),
R.string.options_not_saved,
Toast.LENGTH_SHORT).show();
return;
case DialogInterface.BUTTON_POSITIVE:
writeChanges();
return;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(
context);
builder.setMessage(getString(R.string.certificate_not_valid))
.setPositiveButton(getString(android.R.string.yes),
dialogClickListener)
.setNegativeButton(getString(android.R.string.no),
dialogClickListener).show();
} else {
if (!Core.isOnline(url)) {
writeChanges();
} else {
if (!result) {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
Toast.makeText(getApplicationContext(),
R.string.options_not_saved,
Toast.LENGTH_SHORT).show();
return;
case DialogInterface.BUTTON_POSITIVE:
writeChanges();
return;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(
context);
builder.setMessage(
getString(R.string.certificate_not_valid))
.setPositiveButton(getString(android.R.string.yes),
dialogClickListener)
.setNegativeButton(getString(android.R.string.no),
dialogClickListener).show();
} else {
writeChanges();
}
}
}
}