From 03d7510858183101fbea93293f68d1748a37bc00 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 23 Jan 2018 13:41:15 +0100 Subject: [PATCH] Show infos on untrusted domains if available --- .../operations/RemoteOperationResult.java | 3 ++- .../status/GetRemoteStatusOperation.java | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index dd3392f3e..fd67b94d9 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -125,7 +125,8 @@ public enum ResultCode { DELAYED_IN_POWER_SAVE_MODE, ACCOUNT_USES_STANDARD_PASSWORD, METADATA_NOT_FOUND, - OLD_ANDROID_API + OLD_ANDROID_API, + UNTRUSTED_DOMAIN } private boolean mSuccess = false; diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java index a7a21eaeb..3aba19669 100644 --- a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java +++ b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java @@ -63,6 +63,7 @@ public class GetRemoteStatusOperation extends RemoteOperation { private static final String NODE_VERSION = "version"; private static final String PROTOCOL_HTTPS = "https://"; private static final String PROTOCOL_HTTP = "http://"; + private static final int UNTRUSTED_DOMAIN_ERROR_CODE = 15; private RemoteOperationResult mLatestResult; private Context mContext; @@ -103,6 +104,7 @@ private boolean tryConnection(OwnCloudClient client) { } String response = get.getResponseBodyAsString(); + if (status == HttpStatus.SC_OK) { JSONObject json = new JSONObject(response); if (!json.getBoolean(NODE_INSTALLED)) { @@ -137,13 +139,24 @@ private boolean tryConnection(OwnCloudClient client) { } } + } else if (status == HttpStatus.SC_BAD_REQUEST) { + try { + JSONObject json = new JSONObject(response); + + if (json.getInt("code") == UNTRUSTED_DOMAIN_ERROR_CODE) { + mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNTRUSTED_DOMAIN); + } else { + mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); + } + } catch (JSONException e) { + mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); + } } else { mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } catch (JSONException e) { - mLatestResult = new RemoteOperationResult( - RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); + mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } catch (Exception e) { mLatestResult = new RemoteOperationResult(e);