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:
parent
7d76c88f9a
commit
97e7748602
|
@ -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.
|
||||
|
|
|
@ -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 = "";
|
||||
|
|
|
@ -315,15 +315,20 @@ 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 (!Core.isOnline(url)) {
|
||||
writeChanges();
|
||||
} else {
|
||||
if (!result) {
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -343,7 +348,8 @@ public class Options extends Activity {
|
|||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
context);
|
||||
builder.setMessage(getString(R.string.certificate_not_valid))
|
||||
builder.setMessage(
|
||||
getString(R.string.certificate_not_valid))
|
||||
.setPositiveButton(getString(android.R.string.yes),
|
||||
dialogClickListener)
|
||||
.setNegativeButton(getString(android.R.string.no),
|
||||
|
@ -354,3 +360,4 @@ public class Options extends Activity {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue