package eu.alefzero.owncloud.authenticator;
import java.net.ConnectException;
+import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import javax.net.ssl.SSLHandshakeException;
import android.util.Log;
public class ConnectionCheckerRunnable implements Runnable {
+
+ /** Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs. */
+ public static final int TRY_CONNECTION_TIMEOUT = 5000;
+
private static final String TAG = "ConnectionCheckerRunnable";
private OnConnectCheckListener mListener;
private String mUrl;
return;
}
if (mUrl.startsWith("http://") || mUrl.startsWith("https://")) {
- mLatestResult = ResultType.OK;
+ mLatestResult = (mUrl.startsWith("https://"))? ResultType.OK_SSL : ResultType.OK_NO_SSL;
tryConnection(Uri.parse(mUrl + AccountUtils.STATUS_PATH));
postResult(mLatestResult);
} else {
Uri uri = Uri.parse("https://" + mUrl + AccountUtils.STATUS_PATH);
if (tryConnection(uri)) {
- postResult(ResultType.OK);
+ postResult(ResultType.OK_SSL);
return;
}
Log.d(TAG,
GetMethod get = new GetMethod(uri.toString());
boolean retval = false;
try {
- int status = wc.executeMethod(get);
+ int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT);
switch (status) {
case HttpStatus.SC_OK: {
String response = get.getResponseBodyAsString();
} catch (Exception e) {
if (e instanceof UnknownHostException
- || e instanceof ConnectException) {
+ || e instanceof ConnectException
+ || e instanceof SocketTimeoutException) {
mLatestResult = ResultType.HOST_NOT_AVAILABLE;
} else if (e instanceof JSONException) {
mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;