- return retval;
- }
-
- private boolean isOnline() {
- ConnectivityManager cm =
- (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
- return cm != null
- && cm.getActiveNetworkInfo() != null
- && cm.getActiveNetworkInfo().isConnectedOrConnecting();
- }
-
- private void postResult(final ResultType result) {
- if (mHandler != null && mListener != null) {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- mListener.onConnectionCheckResult(result);
+ private boolean tryConnection(Uri uri) {
+ WebdavClient wc = new WebdavClient();
+ wc.allowSelfsignedCertificates();
+ GetMethod get = new GetMethod(uri.toString());
+ boolean retval = false;
+ try {
+ int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT);
+ switch (status) {
+ case HttpStatus.SC_OK: {
+ String response = get.getResponseBodyAsString();
+ JSONObject json = new JSONObject(response);
+ if (!json.getBoolean("installed")) {
+ mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
+ break;
+ }
+ mOCVersion = new OwnCloudVersion(json.getString("version"));
+ if (!mOCVersion.isVersionValid())
+ break;
+ retval = true;
+ break;
+ }
+ case HttpStatus.SC_NOT_FOUND:
+ mLatestResult = ResultType.FILE_NOT_FOUND;
+ break;
+ case HttpStatus.SC_INTERNAL_SERVER_ERROR:
+ mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
+ break;
+ default:
+ mLatestResult = ResultType.UNKNOWN_ERROR;
+ Log.e(TAG, "Not handled status received from server: " + status);
+ }
+
+ } catch (Exception e) {
+ if (e instanceof UnknownHostException
+ || e instanceof ConnectException
+ || e instanceof SocketTimeoutException) {
+ mLatestResult = ResultType.HOST_NOT_AVAILABLE;
+ } else if (e instanceof JSONException) {
+ mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED;
+ } else if (e instanceof SSLHandshakeException) {
+ mLatestResult = ResultType.SSL_INIT_ERROR;
+ } else {
+ mLatestResult = ResultType.UNKNOWN_ERROR;
+ }
+ e.printStackTrace();
+ }
+
+ return retval;
+ }
+
+ private boolean isOnline() {
+ ConnectivityManager cm = (ConnectivityManager) mContext
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ return cm != null && cm.getActiveNetworkInfo() != null
+ && cm.getActiveNetworkInfo().isConnectedOrConnecting();
+ }
+
+ private void postResult(final ResultType result) {
+ if (mHandler != null && mListener != null) {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mListener.onConnectionCheckResult(result);
+ }
+ });