From d0eb8293fda913ff7fbc1f97b9ab933bdedbcd35 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 10 Oct 2019 14:13:13 +0200 Subject: [PATCH 01/36] Rever compileSdkVersion to 28 --- owncloudComLibrary/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index d33b7543..72db6d82 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -16,7 +16,7 @@ allOpen { } android { - compileSdkVersion 29 + compileSdkVersion 28 defaultConfig { minSdkVersion 19 From 87d244e4735c33db3d6b6951c5568c1ae21def99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Mon, 30 Sep 2019 14:24:53 +0200 Subject: [PATCH 02/36] Add min number of character to search capability --- .../status/GetRemoteCapabilitiesOperation.kt | 95 ++++++++++--------- .../lib/resources/status/RemoteCapability.kt | 3 + 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index 8bce27ef..d5ab846d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -60,7 +60,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation() { val getMethod = GetMethod(URL(uriBuilder.build().toString())) - getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE) + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) val status = client.executeHttpMethod(getMethod) @@ -123,6 +123,10 @@ class GetRemoteCapabilitiesOperation : RemoteOperation() { respFilesSharing.getBoolean(PROPERTY_API_ENABLED) ) } + if (respFilesSharing.has(PROPERTY_SEARCH_MIN_LENGTH)){ + capability.filesSharingMinLength = respFilesSharing.getInt( + PROPERTY_SEARCH_MIN_LENGTH) + } if (respFilesSharing.has(NODE_PUBLIC)) { val respPublic = respFilesSharing.getJSONObject(NODE_PUBLIC) @@ -263,64 +267,65 @@ class GetRemoteCapabilitiesOperation : RemoteOperation() { private val TAG = GetRemoteCapabilitiesOperation::class.java.simpleName // OCS Routes - private val OCS_ROUTE = "ocs/v2.php/cloud/capabilities" + private const val OCS_ROUTE = "ocs/v2.php/cloud/capabilities" // Arguments - names - private val PARAM_FORMAT = "format" + private const val PARAM_FORMAT = "format" // Arguments - constant values - private val VALUE_FORMAT = "json" + private const val VALUE_FORMAT = "json" // JSON Node names - private val NODE_OCS = "ocs" + private const val NODE_OCS = "ocs" - private val NODE_META = "meta" + private const val NODE_META = "meta" - private val NODE_DATA = "data" - private val NODE_VERSION = "version" + private const val NODE_DATA = "data" + private const val NODE_VERSION = "version" - private val NODE_CAPABILITIES = "capabilities" - private val NODE_CORE = "core" + private const val NODE_CAPABILITIES = "capabilities" + private const val NODE_CORE = "core" - private val NODE_FILES_SHARING = "files_sharing" - private val NODE_PUBLIC = "public" - private val NODE_PASSWORD = "password" - private val NODE_ENFORCED_FOR = "enforced_for" - private val NODE_EXPIRE_DATE = "expire_date" - private val NODE_USER = "user" - private val NODE_FEDERATION = "federation" - private val NODE_FILES = "files" + private const val NODE_FILES_SHARING = "files_sharing" + private const val NODE_PUBLIC = "public" + private const val NODE_PASSWORD = "password" + private const val NODE_ENFORCED_FOR = "enforced_for" + private const val NODE_EXPIRE_DATE = "expire_date" + private const val NODE_USER = "user" + private const val NODE_FEDERATION = "federation" + private const val NODE_FILES = "files" - private val PROPERTY_STATUS = "status" - private val PROPERTY_STATUS_OK = "ok" - private val PROPERTY_STATUSCODE = "statuscode" - private val PROPERTY_MESSAGE = "message" + private const val PROPERTY_STATUS = "status" + private const val PROPERTY_STATUS_OK = "ok" + private const val PROPERTY_STATUSCODE = "statuscode" + private const val PROPERTY_MESSAGE = "message" - private val PROPERTY_POLLINTERVAL = "pollinterval" + private const val PROPERTY_POLLINTERVAL = "pollinterval" - private val PROPERTY_MAJOR = "major" - private val PROPERTY_MINOR = "minor" - private val PROPERTY_MICRO = "micro" - private val PROPERTY_STRING = "string" - private val PROPERTY_EDITION = "edition" + private const val PROPERTY_MAJOR = "major" + private const val PROPERTY_MINOR = "minor" + private const val PROPERTY_MICRO = "micro" + private const val PROPERTY_STRING = "string" + private const val PROPERTY_EDITION = "edition" - private val PROPERTY_API_ENABLED = "api_enabled" - private val PROPERTY_ENABLED = "enabled" - private val PROPERTY_ENFORCED = "enforced" - private val PROPERTY_ENFORCED_READ_ONLY = "read_only" - private val PROPERTY_ENFORCED_READ_WRITE = "read_write" - private val PROPERTY_ENFORCED_UPLOAD_ONLY = "upload_only" - private val PROPERTY_DAYS = "days" - private val PROPERTY_SEND_MAIL = "send_mail" - private val PROPERTY_UPLOAD = "upload" - private val PROPERTY_UPLOAD_ONLY = "supports_upload_only" - private val PROPERTY_MULTIPLE = "multiple" - private val PROPERTY_RESHARING = "resharing" - private val PROPERTY_OUTGOING = "outgoing" - private val PROPERTY_INCOMING = "incoming" + private const val PROPERTY_API_ENABLED = "api_enabled" + private const val PROPERTY_ENABLED = "enabled" + private const val PROPERTY_ENFORCED = "enforced" + private const val PROPERTY_ENFORCED_READ_ONLY = "read_only" + private const val PROPERTY_ENFORCED_READ_WRITE = "read_write" + private const val PROPERTY_ENFORCED_UPLOAD_ONLY = "upload_only" + private const val PROPERTY_DAYS = "days" + private const val PROPERTY_SEARCH_MIN_LENGTH = "search_min_length" + private const val PROPERTY_SEND_MAIL = "send_mail" + private const val PROPERTY_UPLOAD = "upload" + private const val PROPERTY_UPLOAD_ONLY = "supports_upload_only" + private const val PROPERTY_MULTIPLE = "multiple" + private const val PROPERTY_RESHARING = "resharing" + private const val PROPERTY_OUTGOING = "outgoing" + private const val PROPERTY_INCOMING = "incoming" - private val PROPERTY_BIGFILECHUNKING = "bigfilechunking" - private val PROPERTY_UNDELETE = "undelete" - private val PROPERTY_VERSIONING = "versioning" + private const val PROPERTY_BIGFILECHUNKING = "bigfilechunking" + private const val PROPERTY_UNDELETE = "undelete" + private const val PROPERTY_VERSIONING = "versioning" } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index a38a9343..c1337119 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -1,6 +1,7 @@ /* ownCloud Android Library is available under MIT license * @author masensio * @author David González Verdugo + * @author Abel García de Prada * Copyright (C) 2019 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -43,6 +44,7 @@ class RemoteCapability { // Files Sharing var filesSharingApiEnabled: CapabilityBooleanType + var filesSharingMinLength: Int var filesSharingPublicEnabled: CapabilityBooleanType var filesSharingPublicPasswordEnforced: CapabilityBooleanType var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType @@ -77,6 +79,7 @@ class RemoteCapability { corePollinterval = 0 filesSharingApiEnabled = CapabilityBooleanType.UNKNOWN + filesSharingMinLength = 4 filesSharingPublicEnabled = CapabilityBooleanType.UNKNOWN filesSharingPublicPasswordEnforced = CapabilityBooleanType.UNKNOWN filesSharingPublicPasswordEnforcedReadOnly = CapabilityBooleanType.UNKNOWN From 2913176f81958e8fad0fd7420d7c5243106ae382 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Wed, 30 Oct 2019 23:01:52 +0100 Subject: [PATCH 03/36] Android Studio 3.5.1 --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 27d7add3..a68a163a 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ad9ad691..14cf0c88 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip From eb177543fc0fb7f8d5f85e77f40d86c829acdb13 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Wed, 6 Nov 2019 06:25:21 +0100 Subject: [PATCH 04/36] Android Studio 3.5.2 --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index a68a163a..8461dad5 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' + classpath 'com.android.tools.build:gradle:3.5.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 14cf0c88..ce011295 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip From fdde542f1519b45cde9a19a1f0c4a5fff0394338 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Thu, 14 Feb 2019 06:38:41 +0100 Subject: [PATCH 05/36] code cleanup --- .../android/lib/common/OwnCloudAccount.java | 4 +--- .../lib/common/OwnCloudClientManager.java | 8 +++---- .../common/OwnCloudClientManagerFactory.java | 11 +++------- .../lib/common/SingleSessionManager.java | 20 +++++++----------- .../oauth/BearerCredentials.java | 3 --- .../network/AdvancedX509TrustManager.java | 21 +++++++------------ .../network/ProgressiveDataTransferer.java | 6 +++--- .../users/GetRemoteUserAvatarOperation.java | 21 ++++--------------- 8 files changed, 29 insertions(+), 65 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java index 87e1e150..ba03b545 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java @@ -107,13 +107,11 @@ public class OwnCloudAccount { * Method for deferred load of account attributes from AccountManager * * @param context - * @throws AccountNotFoundException * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ - public void loadCredentials(Context context) throws AuthenticatorException, - IOException, OperationCanceledException { + public void loadCredentials(Context context) throws AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java index c2d7e6b3..fe793863 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManager.java @@ -43,12 +43,10 @@ import java.io.IOException; public interface OwnCloudClientManager { OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws AccountNotFoundException, - OperationCanceledException, AuthenticatorException, - IOException; + OperationCanceledException, AuthenticatorException, IOException; OwnCloudClient removeClientFor(OwnCloudAccount account); - void saveAllClients(Context context, String accountType) - throws AccountNotFoundException, AuthenticatorException, - IOException, OperationCanceledException; + void saveAllClients(Context context, String accountType) throws AccountNotFoundException, AuthenticatorException, IOException, + OperationCanceledException; } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java index 7b1b0b5b..b66bc249 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java @@ -82,18 +82,13 @@ public class OwnCloudClientManagerFactory { if (sDefaultSingleton == null) { return false; } - if (policy == Policy.ALWAYS_NEW_CLIENT && - !(sDefaultSingleton instanceof SimpleFactoryManager)) { + if (policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager)) { return true; } - if (policy == Policy.SINGLE_SESSION_PER_ACCOUNT && - !(sDefaultSingleton instanceof SingleSessionManager)) { - return true; - } - return false; + return policy == Policy.SINGLE_SESSION_PER_ACCOUNT && !(sDefaultSingleton instanceof SingleSessionManager); } - public static enum Policy { + public enum Policy { ALWAYS_NEW_CLIENT, SINGLE_SESSION_PER_ACCOUNT, SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java index 128207a8..630ba7f7 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java @@ -34,6 +34,7 @@ import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.authentication.OwnCloudSamlSsoCredentials; +import com.owncloud.android.lib.common.http.HttpClient; import com.owncloud.android.lib.common.utils.Log_OC; import java.io.IOException; @@ -56,11 +57,9 @@ public class SingleSessionManager implements OwnCloudClientManager { private static final String TAG = SingleSessionManager.class.getSimpleName(); - private ConcurrentMap mClientsWithKnownUsername = - new ConcurrentHashMap<>(); + private ConcurrentMap mClientsWithKnownUsername = new ConcurrentHashMap<>(); - private ConcurrentMap mClientsWithUnknownUsername = - new ConcurrentHashMap<>(); + private ConcurrentMap mClientsWithUnknownUsername = new ConcurrentHashMap<>(); @Override public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws OperationCanceledException, @@ -76,9 +75,7 @@ public class SingleSessionManager implements OwnCloudClientManager { OwnCloudClient client = null; String accountName = account.getName(); String sessionName = account.getCredentials() == null ? "" : - AccountUtils.buildAccountName( - account.getBaseUri(), - account.getCredentials().getAuthToken()); + AccountUtils.buildAccountName(account.getBaseUri(), account.getCredentials().getAuthToken()); if (accountName != null) { client = mClientsWithKnownUsername.get(accountName); @@ -113,7 +110,7 @@ public class SingleSessionManager implements OwnCloudClientManager { context.getApplicationContext(), true); // TODO remove dependency on OwnCloudClientFactory client.setAccount(account); - client.setContext(context); + HttpClient.setContext(context); client.setOwnCloudClientManager(this); account.loadCredentials(context); @@ -198,10 +195,7 @@ public class SingleSessionManager implements OwnCloudClientManager { while (accountNames.hasNext()) { accountName = accountNames.next(); account = new Account(accountName, accountType); - AccountUtils.saveClient( - mClientsWithKnownUsername.get(accountName), - account, - context); + AccountUtils.saveClient(mClientsWithKnownUsername.get(accountName), account, context); } if (Log.isLoggable(TAG, Log.DEBUG)) { @@ -218,7 +212,7 @@ public class SingleSessionManager implements OwnCloudClientManager { if (am != null && account.getSavedAccount() != null) { String recentCookies = am.getUserData(account.getSavedAccount(), AccountUtils.Constants.KEY_COOKIES); String previousCookies = reusedClient.getCookiesString(); - if (recentCookies != null && previousCookies != "" && !recentCookies.equals(previousCookies)) { + if (recentCookies != null && !previousCookies.equals("") && !recentCookies.equals(previousCookies)) { AccountUtils.restoreCookies(account.getSavedAccount(), reusedClient, context); } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java index ffed3a03..6f7e9a6e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/BearerCredentials.java @@ -41,9 +41,6 @@ public class BearerCredentials { * @param token The bearer token */ public BearerCredentials(String token) { - /*if (token == null) { - throw new IllegalArgumentException("Bearer token may not be null"); - }*/ mAccessToken = (token == null) ? "" : token; } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/AdvancedX509TrustManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/AdvancedX509TrustManager.java index a1fbf59d..f70dabd8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/AdvancedX509TrustManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/AdvancedX509TrustManager.java @@ -33,7 +33,6 @@ import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertPathValidatorException; -import java.security.cert.CertStoreException; import java.security.cert.CertificateException; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; @@ -46,20 +45,17 @@ public class AdvancedX509TrustManager implements X509TrustManager { private static final String TAG = AdvancedX509TrustManager.class.getSimpleName(); - private X509TrustManager mStandardTrustManager = null; + private X509TrustManager mStandardTrustManager; private KeyStore mKnownServersKeyStore; /** * Constructor for AdvancedX509TrustManager * * @param knownServersKeyStore Local certificates store with server certificates explicitly trusted by the user. - * @throws CertStoreException When no default X509TrustManager instance was found in the system. */ - public AdvancedX509TrustManager(KeyStore knownServersKeyStore) - throws NoSuchAlgorithmException, KeyStoreException, CertStoreException { + public AdvancedX509TrustManager(KeyStore knownServersKeyStore) throws NoSuchAlgorithmException, KeyStoreException { super(); - TrustManagerFactory factory = TrustManagerFactory - .getInstance(TrustManagerFactory.getDefaultAlgorithm()); + TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); factory.init((KeyStore) null); mStandardTrustManager = findX509TrustManager(factory); @@ -71,13 +67,12 @@ public class AdvancedX509TrustManager implements X509TrustManager { * * @param factory TrustManagerFactory to inspect in the search for a X509TrustManager * @return The first X509TrustManager found in factory. - * @throws CertStoreException When no X509TrustManager instance was found in factory */ - private X509TrustManager findX509TrustManager(TrustManagerFactory factory) throws CertStoreException { + private X509TrustManager findX509TrustManager(TrustManagerFactory factory) { TrustManager tms[] = factory.getTrustManagers(); - for (int i = 0; i < tms.length; i++) { - if (tms[i] instanceof X509TrustManager) { - return (X509TrustManager) tms[i]; + for (TrustManager tm : tms) { + if (tm instanceof X509TrustManager) { + return (X509TrustManager) tm; } } return null; @@ -116,7 +111,7 @@ public class AdvancedX509TrustManager implements X509TrustManager { previousCause = cause; cause = cause.getCause(); } - if (cause != null && cause instanceof CertPathValidatorException) { + if (cause instanceof CertPathValidatorException) { result.setCertPathValidatorException((CertPathValidatorException) cause); } else { result.setOtherCertificateException(c); diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/ProgressiveDataTransferer.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/ProgressiveDataTransferer.java index 9c89e542..19b07205 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/ProgressiveDataTransferer.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/ProgressiveDataTransferer.java @@ -28,10 +28,10 @@ import java.util.Collection; public interface ProgressiveDataTransferer { - public void addDatatransferProgressListener(OnDatatransferProgressListener listener); + void addDatatransferProgressListener(OnDatatransferProgressListener listener); - public void addDatatransferProgressListeners(Collection listeners); + void addDatatransferProgressListeners(Collection listeners); - public void removeDatatransferProgressListener(OnDatatransferProgressListener listener); + void removeDatatransferProgressListener(OnDatatransferProgressListener listener); } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java index 40d19465..e9263cd7 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java @@ -58,15 +58,8 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation(RemoteOperationResult.ResultCode.FILE_NOT_FOUND); return result; } @@ -115,12 +104,10 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation Date: Sat, 9 Nov 2019 10:05:16 +0100 Subject: [PATCH 06/36] apply review suggestion --- .../lib/resources/users/GetRemoteUserAvatarOperation.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java index e9263cd7..06b0e120 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java @@ -58,6 +58,11 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation Date: Wed, 30 Oct 2019 23:07:04 +0100 Subject: [PATCH 07/36] Better logging --- owncloudComLibrary/build.gradle | 1 + .../android/lib/common/utils/Log_OC.java | 190 ++---------------- .../android/lib/common/utils/LoggingHelper.kt | 24 +++ 3 files changed, 40 insertions(+), 175 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 72db6d82..30743838 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -8,6 +8,7 @@ dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' + api 'com.github.hannesa2:Logcat:1.5.2' } allOpen { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index 47d49c07..4724986c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -1,212 +1,52 @@ package com.owncloud.android.lib.common.utils; -import android.util.Log; +import timber.log.Timber; -import com.owncloud.android.lib.BuildConfig; - -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Locale; public class Log_OC { - private static final String SIMPLE_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; - private static final String LOG_FOLDER_NAME = "log"; - private static final long MAX_FILE_SIZE = 2000000; // 2MB - private static String mOwncloudDataFolderLog = "owncloud_log"; - - private static File mLogFile; - private static File mFolder; - private static BufferedWriter mBuf; - - private static String[] mLogFileNames = { - "currentLog" + BuildConfig.BUILD_TYPE + ".txt", - "olderLog" + BuildConfig.BUILD_TYPE + ".txt" - }; - - private static boolean isMaxFileSizeReached = false; - private static boolean isEnabled = false; + private static String mOwncloudDataFolderLog; public static void setLogDataFolder(String logFolder) { mOwncloudDataFolderLog = logFolder; } - public static void i(String TAG, String message) { - Log.i(TAG, message); - appendLog("I: " + TAG + " : " + message); + public static void i(String tag, String message) { + Timber.i(message); } public static void d(String TAG, String message) { - Log.d(TAG, message); - appendLog("D: " + TAG + " : " + message); + Timber.d(message); } public static void d(String TAG, String message, Exception e) { - Log.d(TAG, message, e); - appendLog("D: " + TAG + " : " + message + " Exception : " + e.getStackTrace()); + Timber.d(e, message); } public static void e(String TAG, String message) { - Log.e(TAG, message); - appendLog("E: " + TAG + " : " + message); + Timber.d(message); } public static void e(String TAG, String message, Throwable e) { - Log.e(TAG, message, e); - appendLog("E: " + TAG + " : " + message + " Exception : " + e.getStackTrace()); + Timber.e(e, message); } public static void v(String TAG, String message) { - Log.v(TAG, message); - appendLog("V: " + TAG + " : " + message); + Timber.v(message); } public static void w(String TAG, String message) { - Log.w(TAG, message); - appendLog("W: " + TAG + " : " + message); + Timber.w(message); } - /** - * Start doing logging - * - * @param storagePath : directory for keeping logs - */ - synchronized public static void startLogging(String storagePath) { - String logPath = storagePath + File.separator + mOwncloudDataFolderLog + File.separator + LOG_FOLDER_NAME; - mFolder = new File(logPath); - mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); - - boolean isFileCreated = false; - - if (!mFolder.exists()) { - mFolder.mkdirs(); - isFileCreated = true; - Log.d("LOG_OC", "Log file created"); - } - - try { - - // Create the current log file if does not exist - mLogFile.createNewFile(); - mBuf = new BufferedWriter(new FileWriter(mLogFile, true)); - isEnabled = true; - - if (isFileCreated) { - appendPhoneInfo(); - } - - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (mBuf != null) { - try { - mBuf.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } + public static void startLogging(String storagePath) { + LoggingHelper.INSTANCE.startLogging( + new File(storagePath+ File.separator + mOwncloudDataFolderLog), mOwncloudDataFolderLog); } - synchronized public static void stopLogging() { - try { - if (mBuf != null) { - mBuf.close(); - } - isEnabled = false; - - mLogFile = null; - mFolder = null; - mBuf = null; - isMaxFileSizeReached = false; - - } catch (IOException e) { - // Because we are stopping logging, we only log to Android console. - Log.e("OC_Log", "Closing log file failed: ", e); - } catch (Exception e) { - // This catch should never fire because we do null check on mBuf. - // But just for the sake of stability let's log this odd situation. - // Because we are stopping logging, we only log to Android console. - Log.e("OC_Log", "Stopping logging failed: ", e); - } + public static void stopLogging() { + LoggingHelper.INSTANCE.stopLogging(); } - /** - * Delete history logging - */ - public static void deleteHistoryLogging() { - File folderLogs = new File(mFolder + File.separator); - if (folderLogs.isDirectory()) { - String[] myFiles = folderLogs.list(); - for (String fileName : myFiles) { - File fileInFolder = new File(folderLogs, fileName); - Log_OC.d("delete file", fileInFolder.getAbsoluteFile() + " " + fileInFolder.delete()); - } - } - } - - /** - * Append the info of the device - */ - private static void appendPhoneInfo() { - appendLog("Model : " + android.os.Build.MODEL); - appendLog("Brand : " + android.os.Build.BRAND); - appendLog("Product : " + android.os.Build.PRODUCT); - appendLog("Device : " + android.os.Build.DEVICE); - appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME); - appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE); - } - - /** - * Append to the log file the info passed - * - * @param text : text for adding to the log file - */ - synchronized private static void appendLog(String text) { - - if (isEnabled) { - - if (isMaxFileSizeReached) { - - // Move current log file info to another file (old logs) - File olderFile = new File(mFolder + File.separator + mLogFileNames[1]); - if (mLogFile.exists()) { - mLogFile.renameTo(olderFile); - } - - // Construct a new file for current log info - mLogFile = new File(mFolder + File.separator + mLogFileNames[0]); - isMaxFileSizeReached = false; - } - - String timeStamp = new SimpleDateFormat(SIMPLE_DATE_FORMAT, Locale.ENGLISH).format(Calendar.getInstance().getTime()); - - try { - mBuf = new BufferedWriter(new FileWriter(mLogFile, true)); - mBuf.newLine(); - mBuf.write(timeStamp + " " + text); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - mBuf.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - // Check if current log file size is bigger than the max file size defined - if (mLogFile.length() > MAX_FILE_SIZE) { - isMaxFileSizeReached = true; - } - } - } - - public static String[] getLogFileNames() { - return mLogFileNames; - } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt new file mode 100644 index 00000000..23d9125b --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt @@ -0,0 +1,24 @@ +package com.owncloud.android.lib.common.utils + +import info.hannes.timber.FileLoggingTree +import info.hannes.timber.fileLoggingTree +import timber.log.Timber +import java.io.File + +object LoggingHelper { + + fun startLogging(directory: File, storagePath: String) { + Timber.forest().fileLoggingTree()?.let { + Timber.forest().drop(Timber.forest().indexOf(it)) + } + if (!directory.exists()) + directory.mkdirs() + Timber.plant(FileLoggingTree(directory, filename = storagePath, delegator = Log_OC::class.java)) + } + + fun stopLogging() { + Timber.forest().fileLoggingTree()?.let { + Timber.forest().drop(Timber.forest().indexOf(it)) + } + } +} From d32f35147f6efacce41099e41c7d1271fd20a10f Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 12 Nov 2019 08:26:25 +0100 Subject: [PATCH 08/36] remove some pointless warnings --- owncloudComLibrary/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 30743838..8d63d2b9 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -8,7 +8,7 @@ dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' - api 'com.github.hannesa2:Logcat:1.5.2' + api 'com.github.hannesa2:Logcat:1.5.3' } allOpen { From b084ca7c03d7989ad222b2443a35b9828f5304e6 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Fri, 15 Nov 2019 08:16:14 +0100 Subject: [PATCH 09/36] introduce deprecated old and new methods --- .../android/lib/common/utils/Log_OC.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java index 4724986c..831076b6 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/Log_OC.java @@ -12,30 +12,65 @@ public class Log_OC { mOwncloudDataFolderLog = logFolder; } + public static void i(String message) { + Timber.i(message); + } + + public static void d(String message) { + Timber.d(message); + } + + public static void d(String message, Exception e) { + Timber.d(e, message); + } + + public static void e(String message) { + Timber.e(message); + } + + public static void e(String message, Throwable e) { + Timber.e(e, message); + } + + public static void v(String message) { + Timber.v(message); + } + + public static void w(String message) { + Timber.w(message); + } + + @Deprecated public static void i(String tag, String message) { Timber.i(message); } + @Deprecated public static void d(String TAG, String message) { Timber.d(message); } + @Deprecated public static void d(String TAG, String message, Exception e) { Timber.d(e, message); } + @Deprecated public static void e(String TAG, String message) { - Timber.d(message); + Timber.e(message); } + @Deprecated public static void e(String TAG, String message, Throwable e) { Timber.e(e, message); } + @Deprecated public static void v(String TAG, String message) { Timber.v(message); } + @Deprecated public static void w(String TAG, String message) { Timber.w(message); } From fa4db38a416020687b32e544bdb5f2da59c68bb0 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Wed, 20 Nov 2019 07:51:07 +0100 Subject: [PATCH 10/36] fix progress dialog and 'No adapter attached' --- owncloudComLibrary/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 8d63d2b9..5df7c481 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -8,7 +8,7 @@ dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' - api 'com.github.hannesa2:Logcat:1.5.3' + api 'com.github.hannesa2:Logcat:1.5.4' } allOpen { From 10a7bdbc4d06f0ff4f6ac477095eb8515f561293 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Fri, 22 Nov 2019 23:33:47 +0100 Subject: [PATCH 11/36] delete all *.log in directory --- owncloudComLibrary/build.gradle | 2 +- .../com/owncloud/android/lib/common/utils/LoggingHelper.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 5df7c481..0e8238d2 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -8,7 +8,7 @@ dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' - api 'com.github.hannesa2:Logcat:1.5.4' + api 'com.github.hannesa2:Logcat:1.5.5' } allOpen { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt index 23d9125b..edb93b66 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/LoggingHelper.kt @@ -8,7 +8,7 @@ import java.io.File object LoggingHelper { fun startLogging(directory: File, storagePath: String) { - Timber.forest().fileLoggingTree()?.let { + fileLoggingTree()?.let { Timber.forest().drop(Timber.forest().indexOf(it)) } if (!directory.exists()) @@ -17,7 +17,7 @@ object LoggingHelper { } fun stopLogging() { - Timber.forest().fileLoggingTree()?.let { + fileLoggingTree()?.let { Timber.forest().drop(Timber.forest().indexOf(it)) } } From 5bf99df58afb0e3803a6185631832bab8dceddda Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 26 Nov 2019 16:47:15 +0100 Subject: [PATCH 12/36] Update Logcat library dependency --- owncloudComLibrary/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 0e8238d2..28c9a5d1 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -8,7 +8,7 @@ dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' - api 'com.github.hannesa2:Logcat:1.5.5' + api 'com.github.hannesa2:Logcat:1.5.6' } allOpen { From e28ffbac7cdce2c70786a41038179382d6171daf Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 3 Jul 2019 17:20:57 +0200 Subject: [PATCH 13/36] Make some classes opened for testing --- owncloudComLibrary/build.gradle | 1 - .../android/lib/resources/shares/CreateRemoteShareOperation.kt | 2 ++ .../lib/resources/shares/GetRemoteSharesForFileOperation.kt | 2 ++ .../android/lib/resources/shares/RemoveRemoteShareOperation.kt | 2 ++ .../android/lib/resources/shares/UpdateRemoteShareOperation.kt | 3 ++- .../lib/resources/status/GetRemoteCapabilitiesOperation.kt | 2 ++ 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 28c9a5d1..384dacf3 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -1,7 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' - apply plugin: 'kotlin-allopen' dependencies { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index b7080c4d..72a242b1 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS +import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -65,6 +66,7 @@ import java.util.Locale * To obtain combinations, add the desired values together. * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. */ +@OpenForTesting class CreateRemoteShareOperation( private val remoteFilePath: String, private val shareType: ShareType, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 321f170b..26d4c52f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -33,6 +33,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -55,6 +56,7 @@ import java.net.URL * @param subfiles If set to false (default), lists only the folder being shared * If set to true, all shared files within the folder are returned. */ +@OpenForTesting class GetRemoteSharesForFileOperation( private val remoteFilePath: String, private val reshares: Boolean, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt index d4deda06..0bb53a74 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt @@ -33,6 +33,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -48,6 +49,7 @@ import java.net.URL * * @param remoteShareId Share ID */ +@OpenForTesting class RemoveRemoteShareOperation(private val remoteShareId: Long) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt index 49f38e65..6196c458 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt @@ -32,6 +32,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION +import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -47,7 +48,7 @@ import java.util.Locale * @author David A. Velasco * @author David González Verdugo */ - +@OpenForTesting class UpdateRemoteShareOperation /** * Constructor. No update is initialized by default, need to be applied with setters below. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index d5ab846d..e8d3b47f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.testing.OpenForTesting import org.json.JSONObject import java.net.URL @@ -47,6 +48,7 @@ import java.net.URL /** * Constructor */ +@OpenForTesting class GetRemoteCapabilitiesOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { From 5981dfab9601cdb695085f7a40b053705f1a408e Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 5 Jul 2019 10:31:10 +0200 Subject: [PATCH 14/36] Remove OpenForTesting, no longer needed since mockk is used --- .../android/lib/testing/OpenForTesting.kt | 31 ------------------- .../shares/CreateRemoteShareOperation.kt | 2 -- .../shares/GetRemoteShareesOperation.kt | 7 +---- .../shares/GetRemoteSharesForFileOperation.kt | 2 -- .../shares/RemoveRemoteShareOperation.kt | 2 -- .../shares/UpdateRemoteShareOperation.kt | 2 -- .../status/GetRemoteCapabilitiesOperation.kt | 2 -- .../lib/resources/status/OwnCloudVersion.kt | 2 -- .../android/lib/testing/OpenForTesting.kt | 31 ------------------- 9 files changed, 1 insertion(+), 80 deletions(-) delete mode 100644 owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt delete mode 100644 owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt diff --git a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt deleted file mode 100644 index 3c91e836..00000000 --- a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.owncloud.android.lib.testing - -/** - * This annotation allows us to open some classes for mocking purposes while they are final in - * release builds. - */ -@Target(AnnotationTarget.ANNOTATION_CLASS) -annotation class OpenClass - -/** - * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds. - */ -@OpenClass -@Target(AnnotationTarget.CLASS) -annotation class OpenForTesting diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index 72a242b1..b7080c4d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS -import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -66,7 +65,6 @@ import java.util.Locale * To obtain combinations, add the desired values together. * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. */ -@OpenForTesting class CreateRemoteShareOperation( private val remoteFilePath: String, private val shareType: ShareType, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt index d439ff26..1419ff7e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt @@ -33,16 +33,12 @@ import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK import com.owncloud.android.lib.common.utils.Log_OC - import org.json.JSONObject - import java.net.URL import java.util.ArrayList -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK -import com.owncloud.android.lib.testing.OpenForTesting - /** * Created by masensio on 08/10/2015. * @@ -73,7 +69,6 @@ import com.owncloud.android.lib.testing.OpenForTesting * @author David A. Velasco * @author David González Verdugo */ -@OpenForTesting class GetRemoteShareesOperation /** * Constructor diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 26d4c52f..321f170b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -56,7 +55,6 @@ import java.net.URL * @param subfiles If set to false (default), lists only the folder being shared * If set to true, all shared files within the folder are returned. */ -@OpenForTesting class GetRemoteSharesForFileOperation( private val remoteFilePath: String, private val reshares: Boolean, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt index 0bb53a74..d4deda06 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -49,7 +48,6 @@ import java.net.URL * * @param remoteShareId Share ID */ -@OpenForTesting class RemoveRemoteShareOperation(private val remoteShareId: Long) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt index 6196c458..16f34e2d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt @@ -32,7 +32,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION -import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -48,7 +47,6 @@ import java.util.Locale * @author David A. Velasco * @author David González Verdugo */ -@OpenForTesting class UpdateRemoteShareOperation /** * Constructor. No update is initialized by default, need to be applied with setters below. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index e8d3b47f..d5ab846d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.testing.OpenForTesting import org.json.JSONObject import java.net.URL @@ -48,7 +47,6 @@ import java.net.URL /** * Constructor */ -@OpenForTesting class GetRemoteCapabilitiesOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt index ef9b6357..dae5b91a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt @@ -27,9 +27,7 @@ package com.owncloud.android.lib.resources.status import android.os.Parcel import android.os.Parcelable -import com.owncloud.android.lib.testing.OpenForTesting -@OpenForTesting class OwnCloudVersion(version: String) : Comparable, Parcelable { // format is in version diff --git a/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt deleted file mode 100644 index 3c91e836..00000000 --- a/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.owncloud.android.lib.testing - -/** - * This annotation allows us to open some classes for mocking purposes while they are final in - * release builds. - */ -@Target(AnnotationTarget.ANNOTATION_CLASS) -annotation class OpenClass - -/** - * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds. - */ -@OpenClass -@Target(AnnotationTarget.CLASS) -annotation class OpenForTesting From ea34453f0a9676bc9bab909dbfabd2145c0e3701 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 8 Jul 2019 12:24:14 +0200 Subject: [PATCH 15/36] Delete unneeded extend --- .../android/lib/common/operations/RemoteOperation.java | 2 +- .../android/lib/common/operations/RemoteOperationResult.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java index fc8fd3d4..9bcdd8f2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -16,7 +16,7 @@ import okhttp3.OkHttpClient; import java.io.IOException; -public abstract class RemoteOperation implements Runnable { +public abstract class RemoteOperation implements Runnable { /** * OCS API header name diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index e87ed5ec..2ae646fb 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -52,7 +52,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -public class RemoteOperationResult +public class RemoteOperationResult implements Serializable { /** @@ -70,6 +70,7 @@ public class RemoteOperationResult private ArrayList mAuthenticate = new ArrayList<>(); private String mLastPermanentLocation = null; private T mData = null; + /** * Public constructor from result code. *

@@ -583,4 +584,4 @@ public class RemoteOperationResult SPECIFIC_UNSUPPORTED_MEDIA_TYPE, SPECIFIC_METHOD_NOT_ALLOWED } -} \ No newline at end of file +} From ebf1a08508f6b29ce84583d3b2eeca06bfebb140 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 11 Jul 2019 11:05:28 +0200 Subject: [PATCH 16/36] Remove unused OwnCloudClient constructor --- .../lib/common/OwnCloudClientFactory.java | 110 ------------------ .../oauth/OwnCloudOAuth2RequestBuilder.java | 1 - .../shares/GetRemoteSharesForFileOperation.kt | 2 +- 3 files changed, 1 insertion(+), 112 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java index 041f72fa..6fb5345f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -24,123 +24,13 @@ package com.owncloud.android.lib.common; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.AccountManagerFuture; -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.os.Bundle; - -import com.owncloud.android.lib.common.accounts.AccountTypeUtils; -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; -import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; - -import java.io.IOException; public class OwnCloudClientFactory { final private static String TAG = OwnCloudClientFactory.class.getSimpleName(); - /** - * Creates a OwnCloudClient setup for an ownCloud account - *

- * Do not call this method from the main thread. - * - * @param account The ownCloud account - * @param appContext Android application context - * @param currentActivity Caller {@link Activity} - * @return A OwnCloudClient object ready to be used - * @throws AuthenticatorException If the authenticator failed to get the authorization - * token for the account. - * @throws OperationCanceledException If the authenticator operation was cancelled while - * getting the authorization token for the account. - * @throws IOException If there was some I/O error while getting the - * authorization token for the account. - * @throws AccountNotFoundException If 'account' is unknown for the AccountManager - */ - public static OwnCloudClient createOwnCloudClient(Account account, Context appContext, - Activity currentActivity) - throws OperationCanceledException, AuthenticatorException, IOException, - AccountNotFoundException { - Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account)); - AccountManager am = AccountManager.get(appContext); - // TODO avoid calling to getUserData here - boolean isOauth2 = - am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; - boolean isSamlSso = - am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; - OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso); - - String username = AccountUtils.getUsernameForAccount(account); - if (isOauth2) { // TODO avoid a call to getUserData here - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), - null, - currentActivity, - null, - null); - - Bundle result = future.getResult(); - String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); - if (accessToken == null) { - throw new AuthenticatorException("WTF!"); - } - client.setCredentials( - OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken) - ); - - } else if (isSamlSso) { // TODO avoid a call to getUserData here - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), - null, - currentActivity, - null, - null); - - Bundle result = future.getResult(); - String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); - if (accessToken == null) { - throw new AuthenticatorException("WTF!"); - } - client.setCredentials( - OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken) - ); - - } else { - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypePass(account.type), - null, - currentActivity, - null, - null - ); - - Bundle result = future.getResult(); - String password = result.getString(AccountManager.KEY_AUTHTOKEN); - OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); - client.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - username, - password, - (version != null && version.isPreemptiveAuthenticationPreferred()) - ) - ); - } - - // Restore cookies - AccountUtils.restoreCookies(account, client, appContext); - - return client; - } - /** * Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud * client connections. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java index 83d1625c..935004dd 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java @@ -152,5 +152,4 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder { ); } } - } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 321f170b..f74a7e75 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -75,7 +75,7 @@ class GetRemoteSharesForFileOperation( val getMethod = GetMethod(URL(uriBuilder.build().toString())) - getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE) + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) val status = client.executeHttpMethod(getMethod) From 66490ff2b0cf42993e65b857df2e0018232e3736 Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 12 Jul 2019 11:51:08 +0200 Subject: [PATCH 17/36] Update gradle version --- .../java/com/owncloud/android/lib/resources/shares/ShareType.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt index 234b4276..8825ffdc 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt @@ -47,7 +47,6 @@ enum class ShareType constructor(val value: Int) { FEDERATED(6); companion object { - fun fromValue(value: Int): ShareType? { return when (value) { -1 -> NO_SHARED From 31868dca00eb8b6e9500a22b84f38698774ef4db Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 28 Aug 2019 12:54:04 +0200 Subject: [PATCH 18/36] Start to use Mockk instead of Mockito since is better prepared to be used along with Kotlin --- .../lib/common/accounts/AccountTypeUtils.java | 7 +---- .../lib/common/accounts/AccountUtils.java | 27 +++---------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java index b5e67c82..1d40884e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2019 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,9 +41,4 @@ public class AccountTypeUtils { public static String getAuthTokenTypeRefreshToken(String accountType) { return accountType + ".oauth2.refresh_token"; } - - public static String getAuthTokenTypeSamlSessionCookie(String accountType) { - return accountType + ".saml.web_sso.session_cookie"; - } - } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index 4478330f..2be339d8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -65,11 +65,7 @@ public class AccountUtils { OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account); webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_FILES_PATH_4_0 + ownCloudCredentials.getUsername(); - } catch (OperationCanceledException e) { - e.printStackTrace(); - } catch (AuthenticatorException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (OperationCanceledException | AuthenticatorException | IOException e) { e.printStackTrace(); } @@ -148,11 +144,6 @@ public class AccountUtils { String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2); boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE"); - String supportsSamlSSo = am.getUserData(account, - AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO); - - boolean isSamlSso = supportsSamlSSo != null && supportsSamlSSo.equals("TRUE"); - String username = AccountUtils.getUsernameForAccount(account); OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION)); @@ -164,14 +155,6 @@ public class AccountUtils { credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken); - } else if (isSamlSso) { - String accessToken = am.blockingGetAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), - false); - - credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken); - } else { String password = am.blockingGetAuthToken( account, @@ -317,10 +300,7 @@ public class AccountUtils { * Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens. */ public static final String KEY_SUPPORTS_OAUTH2 = "oc_supports_oauth2"; - /** - * Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on. - */ - public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso"; + /** * OC account cookies */ @@ -345,6 +325,5 @@ public class AccountUtils { * OAuth2 refresh token **/ public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token"; - } -} \ No newline at end of file +} From 32ecf729c59d9393522227a33e112c8951a8f137 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 28 Aug 2019 13:22:20 +0200 Subject: [PATCH 19/36] Keep removing more SAML stuff --- .../lib/common/DynamicSessionManager.java | 4 +- .../android/lib/common/OwnCloudClient.java | 15 +--- .../common/OwnCloudClientManagerFactory.java | 13 +--- .../lib/common/SingleSessionManager.java | 7 +- .../OwnCloudCredentialsFactory.java | 4 -- .../OwnCloudSamlSsoCredentials.java | 70 ------------------- .../operations/RemoteOperationResult.java | 10 --- 7 files changed, 8 insertions(+), 115 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java index 04b1f69a..38fb11e4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java @@ -11,7 +11,7 @@ import java.io.IOException; /** * Dynamic implementation of {@link OwnCloudClientManager}. - *

+ * * Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one * or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount} * @@ -60,4 +60,4 @@ public class DynamicSessionManager implements OwnCloudClientManager { mSimpleFactoryManager.saveAllClients(context, accountType); mSingleSessionManager.saveAllClients(context, accountType); } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index e0a48f19..d036214d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -114,7 +114,7 @@ public class OwnCloudClient extends HttpClient { status = method.execute(); checkFirstRedirection(method); - if (mFollowRedirects && !isIdPRedirection()) { + if (mFollowRedirects) { status = followRedirection(method).getLastStatus(); } @@ -422,7 +422,7 @@ public class OwnCloudClient extends HttpClient { */ private boolean shouldInvalidateAccountCredentials(int httpStatusCode) { - boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED || isIdPRedirection()); // invalid credentials + boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); // invalid credentials should &= (mCredentials != null && // real credentials !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); @@ -459,17 +459,6 @@ public class OwnCloudClient extends HttpClient { mOwnCloudClientManager = clientManager; } - /** - * Check if the redirection is to an identity provider such as SAML or wayf - * - * @return true if the redirection location includes SAML or wayf, false otherwise - */ - private boolean isIdPRedirection() { - return (mRedirectedLocation != null && - (mRedirectedLocation.toUpperCase().contains("SAML") || - mRedirectedLocation.toLowerCase().contains("wayf"))); - } - public boolean followRedirects() { return mFollowRedirects; } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java index b66bc249..14944a15 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2019 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,9 +38,6 @@ public class OwnCloudClientManagerFactory { case ALWAYS_NEW_CLIENT: return new SimpleFactoryManager(); - case SINGLE_SESSION_PER_ACCOUNT: - return new SingleSessionManager(); - case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING: return new DynamicSessionManager(); @@ -82,15 +79,11 @@ public class OwnCloudClientManagerFactory { if (sDefaultSingleton == null) { return false; } - if (policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager)) { - return true; - } - return policy == Policy.SINGLE_SESSION_PER_ACCOUNT && !(sDefaultSingleton instanceof SingleSessionManager); + return policy == Policy.ALWAYS_NEW_CLIENT && !(sDefaultSingleton instanceof SimpleFactoryManager); } public enum Policy { ALWAYS_NEW_CLIENT, - SINGLE_SESSION_PER_ACCOUNT, SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java index 630ba7f7..21bdf925 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java @@ -33,7 +33,6 @@ import android.net.Uri; import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.authentication.OwnCloudSamlSsoCredentials; import com.owncloud.android.lib.common.http.HttpClient; import com.owncloud.android.lib.common.utils.Log_OC; @@ -116,10 +115,6 @@ public class SingleSessionManager implements OwnCloudClientManager { account.loadCredentials(context); client.setCredentials(account.getCredentials()); - if (client.getCredentials() instanceof OwnCloudSamlSsoCredentials) { - client.disableAutomaticCookiesHandling(); - } - if (accountName != null) { mClientsWithKnownUsername.put(accountName, client); if (Log.isLoggable(TAG, Log.VERBOSE)) { @@ -226,4 +221,4 @@ public class SingleSessionManager implements OwnCloudClientManager { reusedClient.setBaseUri(recentUri); } } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java index 5ac44517..822ef760 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java @@ -48,10 +48,6 @@ public class OwnCloudCredentialsFactory { return new OwnCloudBearerCredentials(username, authToken); } - public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) { - return new OwnCloudSamlSsoCredentials(username, sessionCookie); - } - public static final OwnCloudCredentials getAnonymousCredentials() { if (sAnonymousCredentials == null) { sAnonymousCredentials = new OwnCloudAnonymousCredentials(); diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java deleted file mode 100644 index 40f77bb3..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.common.authentication; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpClient; -import com.owncloud.android.lib.common.http.HttpConstants; - -public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials { - - private String mUsername; - private String mSessionCookie; - - public OwnCloudSamlSsoCredentials(String username, String sessionCookie) { - mUsername = username != null ? username : ""; - mSessionCookie = sessionCookie != null ? sessionCookie : ""; - } - - @Override - public void applyTo(OwnCloudClient client) { - // Clear previous credentials - HttpClient.deleteHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER); - HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER); - - HttpClient.addHeaderForAllRequests(HttpConstants.COOKIE_HEADER, mSessionCookie); - client.setFollowRedirects(false); - } - - @Override - public String getUsername() { - // not relevant for authentication, but relevant for informational purposes - return mUsername; - } - - @Override - public String getAuthToken() { - return mSessionCookie; - } - - @Override - public boolean authTokenExpires() { - return true; - } - - @Override - public boolean authTokenCanBeRefreshed() { - return false; - } -} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 2ae646fb..b58d1b73 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -254,10 +254,6 @@ public class RemoteOperationResult } } } - if (isIdPRedirection()) { - // overrides default ResultCode.UNKNOWN - mCode = ResultCode.UNAUTHORIZED; - } } /** @@ -492,12 +488,6 @@ public class RemoteOperationResult return mRedirectedLocation; } - public boolean isIdPRedirection() { - return (mRedirectedLocation != null && - (mRedirectedLocation.toUpperCase().contains("SAML") || - mRedirectedLocation.toLowerCase().contains("wayf"))); - } - /** * Checks if is a non https connection * From cc38dcd9a6ca1540441dfe204427c666fa5d8e62 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 25 Sep 2019 17:01:30 +0200 Subject: [PATCH 20/36] Include a new class to give data or throw remote exceptions to upper layers --- .../operations/RemoteOperationDeferred.kt | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt new file mode 100644 index 00000000..9ffe5df6 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt @@ -0,0 +1,82 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.common.operations + +suspend fun awaitToRemoteOperationResult(remoteOperation: suspend () -> RemoteOperationResult): T { + + val remoteOperationResult = remoteOperation.invoke() + + if (remoteOperationResult.isSuccess) { + return remoteOperationResult.data + } + + // Errors + when (remoteOperationResult.code) { + RemoteOperationResult.ResultCode.UNHANDLED_HTTP_CODE -> throw Exception() + RemoteOperationResult.ResultCode.UNAUTHORIZED -> throw Exception() + RemoteOperationResult.ResultCode.FILE_NOT_FOUND -> throw Exception() + RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED -> throw Exception() + RemoteOperationResult.ResultCode.UNKNOWN_ERROR -> throw Exception() + RemoteOperationResult.ResultCode.WRONG_CONNECTION -> throw Exception() + RemoteOperationResult.ResultCode.TIMEOUT -> throw Exception() + RemoteOperationResult.ResultCode.INCORRECT_ADDRESS -> throw Exception() + RemoteOperationResult.ResultCode.HOST_NOT_AVAILABLE -> throw Exception() + RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION -> throw Exception() + RemoteOperationResult.ResultCode.SSL_ERROR -> throw Exception() + RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED -> throw Exception() + RemoteOperationResult.ResultCode.BAD_OC_VERSION -> throw Exception() + RemoteOperationResult.ResultCode.CANCELLED -> throw Exception() + RemoteOperationResult.ResultCode.INVALID_LOCAL_FILE_NAME -> throw Exception() + RemoteOperationResult.ResultCode.INVALID_OVERWRITE -> throw Exception() + RemoteOperationResult.ResultCode.CONFLICT -> throw Exception() + RemoteOperationResult.ResultCode.OAUTH2_ERROR -> throw Exception() + RemoteOperationResult.ResultCode.SYNC_CONFLICT -> throw Exception() + RemoteOperationResult.ResultCode.LOCAL_STORAGE_FULL -> throw Exception() + RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED -> throw Exception() + RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_COPIED -> throw Exception() + RemoteOperationResult.ResultCode.OAUTH2_ERROR_ACCESS_DENIED -> throw Exception() + RemoteOperationResult.ResultCode.QUOTA_EXCEEDED -> throw Exception() + RemoteOperationResult.ResultCode.ACCOUNT_NOT_FOUND -> throw Exception() + RemoteOperationResult.ResultCode.ACCOUNT_EXCEPTION -> throw Exception() + RemoteOperationResult.ResultCode.ACCOUNT_NOT_NEW -> throw Exception() + RemoteOperationResult.ResultCode.ACCOUNT_NOT_THE_SAME -> throw Exception() + RemoteOperationResult.ResultCode.INVALID_CHARACTER_IN_NAME -> throw Exception() + RemoteOperationResult.ResultCode.SHARE_NOT_FOUND -> throw Exception() + RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_REMOVED -> throw Exception() + RemoteOperationResult.ResultCode.FORBIDDEN -> throw Exception() + RemoteOperationResult.ResultCode.SHARE_FORBIDDEN -> throw Exception() + RemoteOperationResult.ResultCode.SPECIFIC_FORBIDDEN -> throw Exception() + RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION -> throw Exception() + RemoteOperationResult.ResultCode.INVALID_MOVE_INTO_DESCENDANT -> throw Exception() + RemoteOperationResult.ResultCode.INVALID_COPY_INTO_DESCENDANT -> throw Exception() + RemoteOperationResult.ResultCode.PARTIAL_MOVE_DONE -> throw Exception() + RemoteOperationResult.ResultCode.PARTIAL_COPY_DONE -> throw Exception() + RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER -> throw Exception() + RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE -> throw Exception() + RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER -> throw Exception() + RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI -> throw Exception() + RemoteOperationResult.ResultCode.LOCAL_FILE_NOT_FOUND -> throw Exception() + RemoteOperationResult.ResultCode.SERVICE_UNAVAILABLE -> throw Exception() + RemoteOperationResult.ResultCode.SPECIFIC_SERVICE_UNAVAILABLE -> throw Exception() + RemoteOperationResult.ResultCode.SPECIFIC_UNSUPPORTED_MEDIA_TYPE -> throw Exception() + RemoteOperationResult.ResultCode.SPECIFIC_METHOD_NOT_ALLOWED -> throw Exception() + else -> throw Exception() + } +} From 9aff678fa402e0536836a5066724c0e44f0a70bf Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 26 Sep 2019 11:48:07 +0200 Subject: [PATCH 21/36] Delete GetRemoteSharesOperation --- .../shares/GetRemoteSharesOperation.java | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java deleted file mode 100644 index 5f4110e4..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java +++ /dev/null @@ -1,91 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.resources.shares; - -import android.net.Uri; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpConstants; -import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; - -import java.net.URL; - -/** - * Get the data from the server about ALL the known shares owned by the requester. - * - * @author masensio - * @author David A. Velasco - * @author David González Verdugo - */ - -public class GetRemoteSharesOperation extends RemoteOperation { - - private static final String TAG = GetRemoteSharesOperation.class.getSimpleName(); - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - - try { - Uri requestUri = client.getBaseUri(); - Uri.Builder uriBuilder = requestUri.buildUpon(); - uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH); - - GetMethod getMethod = new GetMethod( - new URL(client.getBaseUri() + ShareUtils.SHARING_API_PATH) - ); - - getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - int status = client.executeHttpMethod(getMethod); - - if (isSuccess(status)) { - - // Parse xml response and obtain the list of shares - ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( - new ShareXMLParser() - ); - parser.setOwnCloudVersion(client.getOwnCloudVersion()); - parser.setServerBaseUri(client.getBaseUri()); - result = parser.parse(getMethod.getResponseBodyAsString()); - } else { - result = new RemoteOperationResult<>(getMethod); - } - } catch (Exception e) { - result = new RemoteOperationResult<>(e); - Log_OC.e(TAG, "Exception while getting remote shares ", e); - } - - return result; - } - - private boolean isSuccess(int status) { - return (status == HttpConstants.HTTP_OK); - } -} \ No newline at end of file From d73ee43e3d42a6e3d06f8fbdc208a4f9551db203 Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 27 Sep 2019 13:45:10 +0200 Subject: [PATCH 22/36] Handle remote operations, both sync and non-sync --- .../lib/common/operations/RemoteOperation.java | 2 +- ...perationDeferred.kt => RemoteOperationHandler.kt} | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/{RemoteOperationDeferred.kt => RemoteOperationHandler.kt} (93%) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java index 9bcdd8f2..9f009bbd 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -192,7 +192,7 @@ public abstract class RemoteOperation implements Runnable { /** * Synchronously executes the remote operation - *

+ * * Do not call this method from the main thread. * * @param client Client object to reach an ownCloud server during the execution of diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt similarity index 93% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt index 9ffe5df6..6fef26cc 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationDeferred.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt @@ -20,14 +20,22 @@ package com.owncloud.android.lib.common.operations suspend fun awaitToRemoteOperationResult(remoteOperation: suspend () -> RemoteOperationResult): T { + remoteOperation.invoke().also { + return handleRemoteOperationResult(it) + } +} - val remoteOperationResult = remoteOperation.invoke() +fun waitForRemoteOperationResult(remoteOperation: () -> RemoteOperationResult): T { + remoteOperation.invoke().also { + return handleRemoteOperationResult(it) + } +} +private fun handleRemoteOperationResult(remoteOperationResult: RemoteOperationResult): T { if (remoteOperationResult.isSuccess) { return remoteOperationResult.data } - // Errors when (remoteOperationResult.code) { RemoteOperationResult.ResultCode.UNHANDLED_HTTP_CODE -> throw Exception() RemoteOperationResult.ResultCode.UNAUTHORIZED -> throw Exception() From 9230937a4421dc12da05fa70e6ed101ae0e19da2 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 30 Sep 2019 15:27:17 +0200 Subject: [PATCH 23/36] Keep decoupling shares and capabilities, start to use mappers --- owncloudComLibrary/build.gradle | 2 + .../android/lib/common/OwnCloudAccount.java | 1 - .../shares/CreateRemoteShareOperation.kt | 1 + .../lib/resources/shares/RemoteShare.kt | 1 + .../lib/resources/shares/RemoteShareMapper.kt | 51 +++++++++++++++ .../ShareToRemoteOperationResultParser.kt | 1 + .../android/lib/resources/shares/ShareType.kt | 63 ------------------ .../lib/resources/shares/ShareXMLParser.kt | 1 + .../resources/status/CapabilityBooleanType.kt | 65 ------------------- .../status/GetRemoteCapabilitiesOperation.kt | 1 + .../lib/resources/status/RemoteCapability.kt | 2 + 11 files changed, 60 insertions(+), 129 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 384dacf3..971d400e 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -4,6 +4,8 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-allopen' dependencies { + implementation project(':owncloudDomain') + api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java index ba03b545..222eb366 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java @@ -149,5 +149,4 @@ public class OwnCloudAccount { return null; } } - } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index b7080c4d..cfec6248 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.shares +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt index 04b61b97..2d75b125 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt @@ -26,6 +26,7 @@ package com.owncloud.android.lib.resources.shares import android.os.Parcel import android.os.Parcelable +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.FileUtils import java.io.Serializable diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt new file mode 100644 index 00000000..81229fa9 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt @@ -0,0 +1,51 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.shares + +import com.owncloud.android.domain.mapper.RemoteMapper +import com.owncloud.android.domain.sharing.shares.model.OCShare + +class RemoteShareMapper : RemoteMapper { + override fun toModel(remote: RemoteShare?): OCShare? = + remote?.let { + OCShare( + fileSource = remote.fileSource, + itemSource = remote.itemSource, + shareType = remote.shareType!!, + shareWith = remote.shareWith, + path = remote.path, + permissions = remote.permissions, + sharedDate = remote.sharedDate, + expirationDate = remote.expirationDate, + token = remote.token, + sharedWithDisplayName = remote.sharedWithDisplayName, + sharedWithAdditionalInfo = remote.sharedWithAdditionalInfo, + isFolder = remote.isFolder, + userId = remote.userId, + remoteId = remote.id, + name = remote.name, + shareLink = remote.shareLink + ) + } + + override fun toRemote(model: OCShare?): RemoteShare? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt index 09fc03ab..775e35d8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt @@ -28,6 +28,7 @@ package com.owncloud.android.lib.resources.shares import android.net.Uri +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.status.OwnCloudVersion diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt deleted file mode 100644 index 8825ffdc..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.resources.shares - -/** - * Enum for Share Type, with values: - * -1 - No shared - * 0 - Shared by user - * 1 - Shared by group - * 3 - Shared by public link - * 4 - Shared by e-mail - * 5 - Shared by contact - * 6 - Federated - * - * @author masensio - */ - -enum class ShareType constructor(val value: Int) { - NO_SHARED(-1), - USER(0), - GROUP(1), - PUBLIC_LINK(3), - EMAIL(4), - CONTACT(5), - FEDERATED(6); - - companion object { - fun fromValue(value: Int): ShareType? { - return when (value) { - -1 -> NO_SHARED - 0 -> USER - 1 -> GROUP - 3 -> PUBLIC_LINK - 4 -> EMAIL - 5 -> CONTACT - 6 -> FEDERATED - else -> null - } - } - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt index df634321..95b60982 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt @@ -25,6 +25,7 @@ package com.owncloud.android.lib.resources.shares import android.util.Xml +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.resources.files.FileUtils diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt deleted file mode 100644 index 7d3d51e7..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * @author masensio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.resources.status - -/** - * Enum for Boolean Type in RemoteCapability parameters, with values: - * -1 - Unknown - * 0 - False - * 1 - True - */ -enum class CapabilityBooleanType private constructor(val value: Int) { - UNKNOWN(-1), - FALSE(0), - TRUE(1); - - val isUnknown: Boolean - get() = value == -1 - - val isFalse: Boolean - get() = value == 0 - - val isTrue: Boolean - get() = value == 1 - - companion object { - fun fromValue(value: Int): CapabilityBooleanType? { - return when (value) { - -1 -> UNKNOWN - 0 -> FALSE - 1 -> TRUE - else -> null - } - } - - fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType { - return if (boolValue) { - TRUE - } else { - FALSE - } - } - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index d5ab846d..2dc62568 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.status +import com.owncloud.android.domain.capabilities.model.CapabilityBooleanType import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index c1337119..2de02389 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -26,6 +26,8 @@ */ package com.owncloud.android.lib.resources.status +import com.owncloud.android.domain.capabilities.model.CapabilityBooleanType + /** * Contains data of the Capabilities for an account, from the Capabilities API */ From 2e460d9cf7d74ae62678f3eb5e482fe9c472283d Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 1 Oct 2019 10:49:58 +0200 Subject: [PATCH 24/36] Include mapper for remote capabilities --- .../lib/resources/shares/RemoteShareMapper.kt | 2 +- .../status/RemoteCapabilityMapper.kt | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt index 81229fa9..b2a56a06 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt @@ -19,7 +19,7 @@ package com.owncloud.android.lib.resources.shares -import com.owncloud.android.domain.mapper.RemoteMapper +import com.owncloud.android.domain.mappers.RemoteMapper import com.owncloud.android.domain.sharing.shares.model.OCShare class RemoteShareMapper : RemoteMapper { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt new file mode 100644 index 00000000..431816c0 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt @@ -0,0 +1,62 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.status + +import com.owncloud.android.domain.capabilities.model.OCCapability +import com.owncloud.android.domain.mappers.RemoteMapper + +class RemoteCapabilityMapper : RemoteMapper { + override fun toModel(remote: RemoteCapability?): OCCapability? = + remote?.let { + OCCapability( + accountName = remote.accountName, + versionMayor = remote.versionMayor, + versionMinor = remote.versionMinor, + versionMicro = remote.versionMicro, + versionString = remote.versionString, + versionEdition = remote.versionEdition, + corePollInterval = remote.corePollinterval, + filesSharingApiEnabled = remote.filesSharingApiEnabled, + filesSharingPublicEnabled = remote.filesSharingPublicEnabled, + filesSharingPublicPasswordEnforced = remote.filesSharingPublicPasswordEnforced, + filesSharingPublicPasswordEnforcedReadOnly = remote.filesSharingPublicPasswordEnforcedReadOnly, + filesSharingPublicPasswordEnforcedReadWrite = remote.filesSharingPublicPasswordEnforcedReadWrite, + filesSharingPublicPasswordEnforcedUploadOnly = remote.filesSharingPublicPasswordEnforcedUploadOnly, + filesSharingPublicExpireDateEnabled = remote.filesSharingPublicExpireDateEnabled, + filesSharingPublicExpireDateDays = remote.filesSharingPublicExpireDateDays, + filesSharingPublicExpireDateEnforced = remote.filesSharingPublicExpireDateEnforced, + filesSharingPublicSendMail = remote.filesSharingPublicSendMail, + filesSharingPublicUpload = remote.filesSharingPublicUpload, + filesSharingPublicMultiple = remote.filesSharingPublicMultiple, + filesSharingPublicSupportsUploadOnly = remote.filesSharingPublicSupportsUploadOnly, + filesSharingUserSendMail = remote.filesSharingUserSendMail, + filesSharingResharing = remote.filesSharingResharing, + filesSharingFederationOutgoing = remote.filesSharingFederationOutgoing, + filesSharingFederationIncoming = remote.filesSharingFederationIncoming, + filesBigFileChunking = remote.filesBigFileChunking, + filesUndelete = remote.filesUndelete, + filesVersioning = remote.filesVersioning + ) + } + + override fun toRemote(model: OCCapability?): RemoteCapability? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} From 9ea10e2f9670db82e9de32f630a0b6b71a922682 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 2 Oct 2019 13:20:22 +0200 Subject: [PATCH 25/36] Remove dependency between the library and the domain layer --- owncloudComLibrary/build.gradle | 2 - .../shares/CreateRemoteShareOperation.kt | 1 - .../lib/resources/shares/RemoteShare.kt | 42 ++++++++++++- .../lib/resources/shares/RemoteShareMapper.kt | 51 --------------- .../ShareToRemoteOperationResultParser.kt | 1 - .../lib/resources/shares/ShareXMLParser.kt | 1 - .../status/GetRemoteCapabilitiesOperation.kt | 1 - .../lib/resources/status/RemoteCapability.kt | 42 ++++++++++++- .../status/RemoteCapabilityMapper.kt | 62 ------------------- 9 files changed, 81 insertions(+), 122 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 971d400e..384dacf3 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -4,8 +4,6 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-allopen' dependencies { - implementation project(':owncloudDomain') - api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index cfec6248..b7080c4d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -27,7 +27,6 @@ package com.owncloud.android.lib.resources.shares -import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt index 2d75b125..a088ebc5 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt @@ -26,7 +26,6 @@ package com.owncloud.android.lib.resources.shares import android.os.Parcel import android.os.Parcelable -import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.FileUtils import java.io.Serializable @@ -196,4 +195,45 @@ class RemoteShare : Parcelable, Serializable { } } } + + +} + +/** + * // TODO This type is already included in the domain but we still need it here since the parsing takes place in this library for the moment + * + * Enum for Share Type, with values: + * -1 - No shared + * 0 - Shared by user + * 1 - Shared by group + * 3 - Shared by public link + * 4 - Shared by e-mail + * 5 - Shared by contact + * 6 - Federated + * + * @author masensio + */ +enum class ShareType constructor(val value: Int) { + NO_SHARED(-1), + USER(0), + GROUP(1), + PUBLIC_LINK(3), + EMAIL(4), + CONTACT(5), + FEDERATED(6); + + companion object { + fun fromValue(value: Int): ShareType? { + return when (value) { + -1 -> NO_SHARED + 0 -> USER + 1 -> GROUP + 3 -> PUBLIC_LINK + 4 -> EMAIL + 5 -> CONTACT + 6 -> FEDERATED + else -> null + } + } + } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt deleted file mode 100644 index b2a56a06..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt +++ /dev/null @@ -1,51 +0,0 @@ -/** - * ownCloud Android client application - * - * @author David González Verdugo - * Copyright (C) 2019 ownCloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.lib.resources.shares - -import com.owncloud.android.domain.mappers.RemoteMapper -import com.owncloud.android.domain.sharing.shares.model.OCShare - -class RemoteShareMapper : RemoteMapper { - override fun toModel(remote: RemoteShare?): OCShare? = - remote?.let { - OCShare( - fileSource = remote.fileSource, - itemSource = remote.itemSource, - shareType = remote.shareType!!, - shareWith = remote.shareWith, - path = remote.path, - permissions = remote.permissions, - sharedDate = remote.sharedDate, - expirationDate = remote.expirationDate, - token = remote.token, - sharedWithDisplayName = remote.sharedWithDisplayName, - sharedWithAdditionalInfo = remote.sharedWithAdditionalInfo, - isFolder = remote.isFolder, - userId = remote.userId, - remoteId = remote.id, - name = remote.name, - shareLink = remote.shareLink - ) - } - - override fun toRemote(model: OCShare?): RemoteShare? { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt index 775e35d8..09fc03ab 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt @@ -28,7 +28,6 @@ package com.owncloud.android.lib.resources.shares import android.net.Uri -import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.status.OwnCloudVersion diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt index 95b60982..df634321 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt @@ -25,7 +25,6 @@ package com.owncloud.android.lib.resources.shares import android.util.Xml -import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.resources.files.FileUtils diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index 2dc62568..d5ab846d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -27,7 +27,6 @@ package com.owncloud.android.lib.resources.status -import com.owncloud.android.domain.capabilities.model.CapabilityBooleanType import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index 2de02389..6645a3aa 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -26,8 +26,6 @@ */ package com.owncloud.android.lib.resources.status -import com.owncloud.android.domain.capabilities.model.CapabilityBooleanType - /** * Contains data of the Capabilities for an account, from the Capabilities API */ @@ -104,3 +102,43 @@ class RemoteCapability { filesVersioning = CapabilityBooleanType.UNKNOWN } } + +/** + * Enum for Boolean Type in capabilities, with values: + * -1 - Unknown + * 0 - False + * 1 - True + */ +enum class CapabilityBooleanType constructor(val value: Int) { + UNKNOWN(-1), + FALSE(0), + TRUE(1); + + val isUnknown: Boolean + get() = value == -1 + + val isFalse: Boolean + get() = value == 0 + + val isTrue: Boolean + get() = value == 1 + + companion object { + fun fromValue(value: Int): CapabilityBooleanType? { + return when (value) { + -1 -> UNKNOWN + 0 -> FALSE + 1 -> TRUE + else -> null + } + } + + fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType { + return if (boolValue) { + TRUE + } else { + FALSE + } + } + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt deleted file mode 100644 index 431816c0..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapabilityMapper.kt +++ /dev/null @@ -1,62 +0,0 @@ -/** - * ownCloud Android client application - * - * @author David González Verdugo - * Copyright (C) 2019 ownCloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.lib.resources.status - -import com.owncloud.android.domain.capabilities.model.OCCapability -import com.owncloud.android.domain.mappers.RemoteMapper - -class RemoteCapabilityMapper : RemoteMapper { - override fun toModel(remote: RemoteCapability?): OCCapability? = - remote?.let { - OCCapability( - accountName = remote.accountName, - versionMayor = remote.versionMayor, - versionMinor = remote.versionMinor, - versionMicro = remote.versionMicro, - versionString = remote.versionString, - versionEdition = remote.versionEdition, - corePollInterval = remote.corePollinterval, - filesSharingApiEnabled = remote.filesSharingApiEnabled, - filesSharingPublicEnabled = remote.filesSharingPublicEnabled, - filesSharingPublicPasswordEnforced = remote.filesSharingPublicPasswordEnforced, - filesSharingPublicPasswordEnforcedReadOnly = remote.filesSharingPublicPasswordEnforcedReadOnly, - filesSharingPublicPasswordEnforcedReadWrite = remote.filesSharingPublicPasswordEnforcedReadWrite, - filesSharingPublicPasswordEnforcedUploadOnly = remote.filesSharingPublicPasswordEnforcedUploadOnly, - filesSharingPublicExpireDateEnabled = remote.filesSharingPublicExpireDateEnabled, - filesSharingPublicExpireDateDays = remote.filesSharingPublicExpireDateDays, - filesSharingPublicExpireDateEnforced = remote.filesSharingPublicExpireDateEnforced, - filesSharingPublicSendMail = remote.filesSharingPublicSendMail, - filesSharingPublicUpload = remote.filesSharingPublicUpload, - filesSharingPublicMultiple = remote.filesSharingPublicMultiple, - filesSharingPublicSupportsUploadOnly = remote.filesSharingPublicSupportsUploadOnly, - filesSharingUserSendMail = remote.filesSharingUserSendMail, - filesSharingResharing = remote.filesSharingResharing, - filesSharingFederationOutgoing = remote.filesSharingFederationOutgoing, - filesSharingFederationIncoming = remote.filesSharingFederationIncoming, - filesBigFileChunking = remote.filesBigFileChunking, - filesUndelete = remote.filesUndelete, - filesVersioning = remote.filesVersioning - ) - } - - override fun toRemote(model: OCCapability?): RemoteCapability? { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -} From f32a3af5720f236aefeccc969f61a126810cba62 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 2 Oct 2019 16:58:27 +0200 Subject: [PATCH 26/36] Uncomplished commit --- .../operations/RemoteOperationHandler.kt | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt deleted file mode 100644 index 6fef26cc..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationHandler.kt +++ /dev/null @@ -1,90 +0,0 @@ -/** - * ownCloud Android client application - * - * @author David González Verdugo - * Copyright (C) 2019 ownCloud GmbH. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.lib.common.operations - -suspend fun awaitToRemoteOperationResult(remoteOperation: suspend () -> RemoteOperationResult): T { - remoteOperation.invoke().also { - return handleRemoteOperationResult(it) - } -} - -fun waitForRemoteOperationResult(remoteOperation: () -> RemoteOperationResult): T { - remoteOperation.invoke().also { - return handleRemoteOperationResult(it) - } -} - -private fun handleRemoteOperationResult(remoteOperationResult: RemoteOperationResult): T { - if (remoteOperationResult.isSuccess) { - return remoteOperationResult.data - } - - when (remoteOperationResult.code) { - RemoteOperationResult.ResultCode.UNHANDLED_HTTP_CODE -> throw Exception() - RemoteOperationResult.ResultCode.UNAUTHORIZED -> throw Exception() - RemoteOperationResult.ResultCode.FILE_NOT_FOUND -> throw Exception() - RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED -> throw Exception() - RemoteOperationResult.ResultCode.UNKNOWN_ERROR -> throw Exception() - RemoteOperationResult.ResultCode.WRONG_CONNECTION -> throw Exception() - RemoteOperationResult.ResultCode.TIMEOUT -> throw Exception() - RemoteOperationResult.ResultCode.INCORRECT_ADDRESS -> throw Exception() - RemoteOperationResult.ResultCode.HOST_NOT_AVAILABLE -> throw Exception() - RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION -> throw Exception() - RemoteOperationResult.ResultCode.SSL_ERROR -> throw Exception() - RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED -> throw Exception() - RemoteOperationResult.ResultCode.BAD_OC_VERSION -> throw Exception() - RemoteOperationResult.ResultCode.CANCELLED -> throw Exception() - RemoteOperationResult.ResultCode.INVALID_LOCAL_FILE_NAME -> throw Exception() - RemoteOperationResult.ResultCode.INVALID_OVERWRITE -> throw Exception() - RemoteOperationResult.ResultCode.CONFLICT -> throw Exception() - RemoteOperationResult.ResultCode.OAUTH2_ERROR -> throw Exception() - RemoteOperationResult.ResultCode.SYNC_CONFLICT -> throw Exception() - RemoteOperationResult.ResultCode.LOCAL_STORAGE_FULL -> throw Exception() - RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED -> throw Exception() - RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_COPIED -> throw Exception() - RemoteOperationResult.ResultCode.OAUTH2_ERROR_ACCESS_DENIED -> throw Exception() - RemoteOperationResult.ResultCode.QUOTA_EXCEEDED -> throw Exception() - RemoteOperationResult.ResultCode.ACCOUNT_NOT_FOUND -> throw Exception() - RemoteOperationResult.ResultCode.ACCOUNT_EXCEPTION -> throw Exception() - RemoteOperationResult.ResultCode.ACCOUNT_NOT_NEW -> throw Exception() - RemoteOperationResult.ResultCode.ACCOUNT_NOT_THE_SAME -> throw Exception() - RemoteOperationResult.ResultCode.INVALID_CHARACTER_IN_NAME -> throw Exception() - RemoteOperationResult.ResultCode.SHARE_NOT_FOUND -> throw Exception() - RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_REMOVED -> throw Exception() - RemoteOperationResult.ResultCode.FORBIDDEN -> throw Exception() - RemoteOperationResult.ResultCode.SHARE_FORBIDDEN -> throw Exception() - RemoteOperationResult.ResultCode.SPECIFIC_FORBIDDEN -> throw Exception() - RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION -> throw Exception() - RemoteOperationResult.ResultCode.INVALID_MOVE_INTO_DESCENDANT -> throw Exception() - RemoteOperationResult.ResultCode.INVALID_COPY_INTO_DESCENDANT -> throw Exception() - RemoteOperationResult.ResultCode.PARTIAL_MOVE_DONE -> throw Exception() - RemoteOperationResult.ResultCode.PARTIAL_COPY_DONE -> throw Exception() - RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER -> throw Exception() - RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE -> throw Exception() - RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER -> throw Exception() - RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI -> throw Exception() - RemoteOperationResult.ResultCode.LOCAL_FILE_NOT_FOUND -> throw Exception() - RemoteOperationResult.ResultCode.SERVICE_UNAVAILABLE -> throw Exception() - RemoteOperationResult.ResultCode.SPECIFIC_SERVICE_UNAVAILABLE -> throw Exception() - RemoteOperationResult.ResultCode.SPECIFIC_UNSUPPORTED_MEDIA_TYPE -> throw Exception() - RemoteOperationResult.ResultCode.SPECIFIC_METHOD_NOT_ALLOWED -> throw Exception() - else -> throw Exception() - } -} From 28d93a6790a1ffe9943dee2af92566602c856607 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 11 Nov 2019 15:05:29 +0100 Subject: [PATCH 27/36] Update RemoteCapability with new search min characters field --- .../owncloud/android/lib/resources/status/RemoteCapability.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index 6645a3aa..c9997c73 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -44,6 +44,7 @@ class RemoteCapability { // Files Sharing var filesSharingApiEnabled: CapabilityBooleanType + var filesSharingSearchMinLength: CapabilityBooleanType var filesSharingMinLength: Int var filesSharingPublicEnabled: CapabilityBooleanType var filesSharingPublicPasswordEnforced: CapabilityBooleanType @@ -79,6 +80,7 @@ class RemoteCapability { corePollinterval = 0 filesSharingApiEnabled = CapabilityBooleanType.UNKNOWN + filesSharingSearchMinLength = CapabilityBooleanType.UNKNOWN filesSharingMinLength = 4 filesSharingPublicEnabled = CapabilityBooleanType.UNKNOWN filesSharingPublicPasswordEnforced = CapabilityBooleanType.UNKNOWN From 27ff4dfd231c96110c4aef9142f903b2747a9820 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 2 Oct 2019 18:22:20 +0200 Subject: [PATCH 28/36] Fix upload --- .../com/owncloud/android/lib/resources/files/FileUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java index f0165505..c9c424d3 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileUtils.java @@ -78,8 +78,9 @@ public class FileUtils { (path.contains("\\") || path.contains("<") || path.contains(">") || path.contains(":") || path.contains("\"") || path.contains("|") || path.contains("?") || path.contains("*"))) { + result = false; } return result; } -} \ No newline at end of file +} From 8fa6cc648b1f0ff106edf76fffbe09ae5a884ed4 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 3 Oct 2019 12:26:30 +0200 Subject: [PATCH 29/36] Fix add headers using interceptors --- .../android/lib/common/http/interceptors/HttpInterceptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java index b9720924..993919b9 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java @@ -60,12 +60,12 @@ public class HttpInterceptor implements Interceptor { } public HttpInterceptor addRequestInterceptor(RequestInterceptor requestInterceptor) { - mRequestInterceptors.add(requestInterceptor); + mRequestInterceptors.listIterator().add(requestInterceptor); return this; } public HttpInterceptor addResponseInterceptor(ResponseInterceptor responseInterceptor) { - mResponseInterceptors.add(responseInterceptor); + mResponseInterceptors.listIterator().add(responseInterceptor); return this; } From c05a11a7b4ec173797c3217efc8ec5526d612ae7 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 7 Oct 2019 15:22:20 +0200 Subject: [PATCH 30/36] Create some service interfaces as facade for remote operations --- .../owncloud/android/lib/resources/Service.kt | 31 +++++++++++ .../lib/resources/shares/ShareService.kt | 54 +++++++++++++++++++ .../lib/resources/shares/ShareeService.kt | 34 ++++++++++++ .../lib/resources/status/CapabilityService.kt | 28 ++++++++++ 4 files changed, 147 insertions(+) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt new file mode 100644 index 00000000..0fa90756 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/Service.kt @@ -0,0 +1,31 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources + +import com.owncloud.android.lib.common.OwnCloudClient + +/** + * Facade to perform network calls without the verbosity of remote operations + */ + +interface Service { + val client: OwnCloudClient +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt new file mode 100644 index 00000000..e8b728b3 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt @@ -0,0 +1,54 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.shares + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.Service + +interface ShareService : Service { + fun getShares( + remoteFilePath: String, + reshares: Boolean, + subfiles: Boolean + ): RemoteOperationResult + + fun insertShare( + remoteFilePath: String, + shareType: ShareType, + shareWith: String, + permissions: Int, + name: String, + password: String, + expirationDate: Long, + publicUpload: Boolean + ): RemoteOperationResult + + fun updateShare( + remoteId: Long, + name: String, + password: String?, + expirationDate: Long, + permissions: Int, + publicUpload: Boolean + ): RemoteOperationResult + + fun deleteShare(remoteId: Long): RemoteOperationResult +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt new file mode 100644 index 00000000..ba6426dc --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt @@ -0,0 +1,34 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.shares + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.Service +import org.json.JSONObject +import java.util.ArrayList + +interface ShareeService : Service { + fun getSharees( + searchString: String, + page: Int, + perPage: Int + ): RemoteOperationResult> +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt new file mode 100644 index 00000000..1253f9ca --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt @@ -0,0 +1,28 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.status + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.Service + +interface CapabilityService: Service { + fun getCapabilities() : RemoteOperationResult +} From c50e199b76958a7e43c05ea797c5afbaafb0f508 Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 11 Oct 2019 14:02:24 +0200 Subject: [PATCH 31/36] Fix null error in http interceptors --- .../android/lib/common/http/HttpClient.java | 11 +++++++---- .../http/interceptors/HttpInterceptor.java | 16 +++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java index b0b3e7a2..9564922d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java @@ -156,10 +156,13 @@ public class HttpClient { * @param headerValue */ public static void addHeaderForAllRequests(String headerName, String headerValue) { - getOkHttpInterceptor() - .addRequestInterceptor( - new RequestHeaderInterceptor(headerName, headerValue) - ); + HttpInterceptor httpInterceptor = getOkHttpInterceptor(); + + if(getOkHttpInterceptor() != null) { + httpInterceptor.addRequestInterceptor( + new RequestHeaderInterceptor(headerName, headerValue) + ); + } } public static void deleteHeaderForAllRequests(String headerName) { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java index 993919b9..55abe84d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/interceptors/HttpInterceptor.java @@ -46,14 +46,20 @@ public class HttpInterceptor implements Interceptor { public Response intercept(Chain chain) throws IOException { Request request = chain.request(); - for (RequestInterceptor interceptor : mRequestInterceptors) { - request = interceptor.intercept(request); + ListIterator requestInterceptorIterator = mRequestInterceptors.listIterator(); + + while (requestInterceptorIterator.hasNext()) { + RequestInterceptor currentRequestInterceptor = requestInterceptorIterator.next(); + request = currentRequestInterceptor.intercept(request); } Response response = chain.proceed(request); - for (ResponseInterceptor interceptor : mResponseInterceptors) { - response = interceptor.intercept(response); + ListIterator responseInterceptorIterator = mResponseInterceptors.listIterator(); + + while (responseInterceptorIterator.hasNext()) { + ResponseInterceptor currentResponseInterceptor = responseInterceptorIterator.next(); + response = currentResponseInterceptor.intercept(response); } return response; @@ -107,4 +113,4 @@ public class HttpInterceptor implements Interceptor { public interface ResponseInterceptor { Response intercept(Response response) throws IOException; } -} \ No newline at end of file +} From f104d6842e7fcb6f0b81b5167f07e38d9ebbb62d Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 14 Nov 2019 14:35:19 +0100 Subject: [PATCH 32/36] Clean up remote objects (code review) --- .../lib/resources/shares/RemoteShare.kt | 160 +++--------------- .../lib/resources/status/RemoteCapability.kt | 107 ++++-------- 2 files changed, 53 insertions(+), 214 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt index a088ebc5..a0a4afea 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt @@ -24,11 +24,7 @@ package com.owncloud.android.lib.resources.shares -import android.os.Parcel -import android.os.Parcelable -import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.FileUtils -import java.io.Serializable /** * Contains the data of a Share from the Share API @@ -37,124 +33,27 @@ import java.io.Serializable * @author David A. Velasco * @author David González Verdugo */ -class RemoteShare : Parcelable, Serializable { - var id: Long = 0 - var shareWith: String = "" - var path: String = "" - var token: String = "" - var sharedWithDisplayName: String = "" - var sharedWithAdditionalInfo: String = "" - var name: String = "" - var shareLink: String = "" - var fileSource: Long = 0 - var itemSource: Long = 0 - var shareType: ShareType? = null - var permissions: Int = DEFAULT_PERMISSION - var sharedDate: Long = INIT_SHARED_DATE - var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS - var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR) - var userId: Long = 0 - +data class RemoteShare( + var id: Long = 0, + var shareWith: String = "", + var path: String = "", + var token: String = "", + var sharedWithDisplayName: String = "", + var sharedWithAdditionalInfo: String = "", + var name: String = "", + var shareLink: String = "", + var fileSource: Long = 0, + var itemSource: Long = 0, + var shareType: ShareType? = ShareType.UNKNOWN, + var permissions: Int = DEFAULT_PERMISSION, + var sharedDate: Long = INIT_SHARED_DATE, + var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS, + var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR), + var userId: Long = 0, val isValid: Boolean = id > -1 - - constructor() : super() { - resetData() - } - - constructor(path: String?) { - resetData() - if (path.isNullOrEmpty() || !path.startsWith(FileUtils.PATH_SEPARATOR)) { - Log_OC.e(TAG, "Trying to create a RemoteShare with a non valid path") - throw IllegalArgumentException("Trying to create a RemoteShare with a non valid path: " + path!!) - } - this.path = path - } - - /** - * Used internally. Reset all file properties - */ - private fun resetData() { - id = -1 - shareWith = "" - path = "" - token = "" - sharedWithDisplayName = "" - sharedWithAdditionalInfo = "" - name = "" - shareLink = "" - fileSource = 0 - itemSource = 0 - shareType = ShareType.NO_SHARED - permissions = DEFAULT_PERMISSION - sharedDate = INIT_SHARED_DATE - expirationDate = INIT_EXPIRATION_DATE_IN_MILLIS - sharedWithAdditionalInfo = "" - isFolder = false - userId = -1 - } - - /** - * Reconstruct from parcel - * - * @param source The source parcel - */ - protected constructor(source: Parcel) { - readFromParcel(source) - } - - fun readFromParcel(source: Parcel) { - id = source.readLong() - shareWith = source.readString().toString() - path = source.readString().toString() - token = source.readString().toString() - sharedWithDisplayName = source.readString().toString() - sharedWithAdditionalInfo = source.readString().toString() - name = source.readString().toString() - shareLink = source.readString().toString() - fileSource = source.readLong() - itemSource = source.readLong() - shareType = ShareType.NO_SHARED - try { - shareType = source.readString()?.let { ShareType.valueOf(it) } - } catch (x: IllegalArgumentException) { - } - permissions = source.readInt() - sharedDate = source.readLong() - expirationDate = source.readLong() - isFolder = source.readInt() == 0 - userId = source.readLong() - } - - override fun describeContents(): Int = this.hashCode() - - override fun writeToParcel(dest: Parcel, flags: Int) { - dest.writeLong(id) - dest.writeString(shareWith) - dest.writeString(path) - dest.writeString(token) - dest.writeString(sharedWithDisplayName) - dest.writeString(sharedWithAdditionalInfo) - dest.writeString(name) - dest.writeString(shareLink) - dest.writeLong(fileSource) - dest.writeLong(itemSource) - dest.writeString(shareType?.name ?: "") - dest.writeInt(permissions) - dest.writeLong(sharedDate) - dest.writeLong(expirationDate) - dest.writeInt(if (isFolder) 1 else 0) - dest.writeLong(userId) - } +) { companion object { - - /** - * Generated - should be refreshed every time the class changes!! - */ - private const val serialVersionUID = 4124975224281327921L - - private val TAG = RemoteShare::class.java.simpleName - const val DEFAULT_PERMISSION = -1 const val READ_PERMISSION_FLAG = 1 const val UPDATE_PERMISSION_FLAG = 2 @@ -180,30 +79,14 @@ class RemoteShare : Parcelable, Serializable { const val INIT_EXPIRATION_DATE_IN_MILLIS: Long = 0 const val INIT_SHARED_DATE: Long = 0 - - /** - * Parcelable Methods - */ - @JvmField - val CREATOR: Parcelable.Creator = object : Parcelable.Creator { - override fun createFromParcel(source: Parcel): RemoteShare { - return RemoteShare(source) - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - } } - - } /** * // TODO This type is already included in the domain but we still need it here since the parsing takes place in this library for the moment * * Enum for Share Type, with values: - * -1 - No shared + * -1 - Unknown * 0 - Shared by user * 1 - Shared by group * 3 - Shared by public link @@ -213,8 +96,9 @@ class RemoteShare : Parcelable, Serializable { * * @author masensio */ + enum class ShareType constructor(val value: Int) { - NO_SHARED(-1), + UNKNOWN(-1), USER(0), GROUP(1), PUBLIC_LINK(3), @@ -225,7 +109,7 @@ enum class ShareType constructor(val value: Int) { companion object { fun fromValue(value: Int): ShareType? { return when (value) { - -1 -> NO_SHARED + -1 -> UNKNOWN 0 -> USER 1 -> GROUP 3 -> PUBLIC_LINK diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index c9997c73..5d4f6e77 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -29,81 +29,45 @@ package com.owncloud.android.lib.resources.status /** * Contains data of the Capabilities for an account, from the Capabilities API */ -class RemoteCapability { - var accountName: String +data class RemoteCapability( + var accountName: String = "", // Server version - var versionMayor: Int - var versionMinor: Int - var versionMicro: Int - var versionString: String - var versionEdition: String + var versionMayor: Int = 0, + var versionMinor: Int = 0, + var versionMicro: Int = 0, + var versionString: String = "", + var versionEdition: String = "", // Core PollInterval - var corePollinterval: Int + var corePollinterval: Int = 0, // Files Sharing - var filesSharingApiEnabled: CapabilityBooleanType - var filesSharingSearchMinLength: CapabilityBooleanType - var filesSharingMinLength: Int - var filesSharingPublicEnabled: CapabilityBooleanType - var filesSharingPublicPasswordEnforced: CapabilityBooleanType - var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType - var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType - var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType - var filesSharingPublicExpireDateEnabled: CapabilityBooleanType - var filesSharingPublicExpireDateDays: Int - var filesSharingPublicExpireDateEnforced: CapabilityBooleanType - var filesSharingPublicSendMail: CapabilityBooleanType - var filesSharingPublicUpload: CapabilityBooleanType - var filesSharingPublicMultiple: CapabilityBooleanType - var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType - var filesSharingUserSendMail: CapabilityBooleanType - var filesSharingResharing: CapabilityBooleanType - var filesSharingFederationOutgoing: CapabilityBooleanType - var filesSharingFederationIncoming: CapabilityBooleanType + var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingSearchMinLength: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingMinLength: Int = 0, + var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicExpireDateEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicExpireDateDays: Int = 0, + var filesSharingPublicExpireDateEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicUpload: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicMultiple: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingUserSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingResharing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingFederationOutgoing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingFederationIncoming: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, // Files - var filesBigFileChunking: CapabilityBooleanType - var filesUndelete: CapabilityBooleanType - var filesVersioning: CapabilityBooleanType - - init { - accountName = "" - - versionMayor = 0 - versionMinor = 0 - versionMicro = 0 - versionString = "" - versionEdition = "" - - corePollinterval = 0 - - filesSharingApiEnabled = CapabilityBooleanType.UNKNOWN - filesSharingSearchMinLength = CapabilityBooleanType.UNKNOWN - filesSharingMinLength = 4 - filesSharingPublicEnabled = CapabilityBooleanType.UNKNOWN - filesSharingPublicPasswordEnforced = CapabilityBooleanType.UNKNOWN - filesSharingPublicPasswordEnforcedReadOnly = CapabilityBooleanType.UNKNOWN - filesSharingPublicPasswordEnforcedReadWrite = CapabilityBooleanType.UNKNOWN - filesSharingPublicPasswordEnforcedUploadOnly = CapabilityBooleanType.UNKNOWN - filesSharingPublicExpireDateEnabled = CapabilityBooleanType.UNKNOWN - filesSharingPublicExpireDateDays = 0 - filesSharingPublicExpireDateEnforced = CapabilityBooleanType.UNKNOWN - filesSharingPublicSendMail = CapabilityBooleanType.UNKNOWN - filesSharingPublicUpload = CapabilityBooleanType.UNKNOWN - filesSharingPublicMultiple = CapabilityBooleanType.UNKNOWN - filesSharingPublicSupportsUploadOnly = CapabilityBooleanType.UNKNOWN - filesSharingUserSendMail = CapabilityBooleanType.UNKNOWN - filesSharingResharing = CapabilityBooleanType.UNKNOWN - filesSharingFederationOutgoing = CapabilityBooleanType.UNKNOWN - filesSharingFederationIncoming = CapabilityBooleanType.UNKNOWN - - filesBigFileChunking = CapabilityBooleanType.UNKNOWN - filesUndelete = CapabilityBooleanType.UNKNOWN - filesVersioning = CapabilityBooleanType.UNKNOWN - } -} + var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesVersioning: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN +) /** * Enum for Boolean Type in capabilities, with values: @@ -116,15 +80,6 @@ enum class CapabilityBooleanType constructor(val value: Int) { FALSE(0), TRUE(1); - val isUnknown: Boolean - get() = value == -1 - - val isFalse: Boolean - get() = value == 0 - - val isTrue: Boolean - get() = value == 1 - companion object { fun fromValue(value: Int): CapabilityBooleanType? { return when (value) { From da08f04fa171177f8a64c1696b24a7be26585ce7 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 18 Nov 2019 10:47:39 +0100 Subject: [PATCH 33/36] Fix capability type --- .../owncloud/android/lib/resources/status/RemoteCapability.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index 5d4f6e77..29b1780f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -44,7 +44,7 @@ data class RemoteCapability( // Files Sharing var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, - var filesSharingSearchMinLength: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, + var filesSharingSearchMinLength: Int = 0, var filesSharingMinLength: Int = 0, var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, From 9710cf991dbc50c0a96fe28a3a2d5f8d38e6e0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Thu, 28 Nov 2019 14:14:09 +0100 Subject: [PATCH 34/36] Update remote capability --- .../lib/resources/status/GetRemoteCapabilitiesOperation.kt | 2 +- .../owncloud/android/lib/resources/status/RemoteCapability.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index d5ab846d..bb0cd872 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -124,7 +124,7 @@ class GetRemoteCapabilitiesOperation : RemoteOperation() { ) } if (respFilesSharing.has(PROPERTY_SEARCH_MIN_LENGTH)){ - capability.filesSharingMinLength = respFilesSharing.getInt( + capability.filesSharingSearchMinLength = respFilesSharing.getInt( PROPERTY_SEARCH_MIN_LENGTH) } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index 29b1780f..f880ccae 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -44,8 +44,7 @@ data class RemoteCapability( // Files Sharing var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, - var filesSharingSearchMinLength: Int = 0, - var filesSharingMinLength: Int = 0, + var filesSharingSearchMinLength: Int? = 2, var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, From 1aeacd62b8b184cd25730d9aa780b46b49186a32 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 3 Dec 2019 10:44:00 +0100 Subject: [PATCH 35/36] Apply changes requested in code review --- .../status/GetRemoteCapabilitiesOperation.kt | 1 + .../lib/resources/status/RemoteCapability.kt | 56 ++++++++++--------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index bb0cd872..e5cd965b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.lib.common.utils.Log_OC import org.json.JSONObject import java.net.URL +import com.owncloud.android.lib.resources.status.RemoteCapability.CapabilityBooleanType /** * Get the Capabilities from the server diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index f880ccae..6bd51efe 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -44,7 +44,7 @@ data class RemoteCapability( // Files Sharing var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, - var filesSharingSearchMinLength: Int? = 2, + var filesSharingSearchMinLength: Int? = DEFAULT_MIN_CHARACTERS_TO_SEARCH, var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, @@ -66,35 +66,39 @@ data class RemoteCapability( var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, var filesVersioning: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN -) +) { + /** + * Enum for Boolean Type in capabilities, with values: + * -1 - Unknown + * 0 - False + * 1 - True + */ + enum class CapabilityBooleanType constructor(val value: Int) { + UNKNOWN(-1), + FALSE(0), + TRUE(1); -/** - * Enum for Boolean Type in capabilities, with values: - * -1 - Unknown - * 0 - False - * 1 - True - */ -enum class CapabilityBooleanType constructor(val value: Int) { - UNKNOWN(-1), - FALSE(0), - TRUE(1); - - companion object { - fun fromValue(value: Int): CapabilityBooleanType? { - return when (value) { - -1 -> UNKNOWN - 0 -> FALSE - 1 -> TRUE - else -> null + companion object { + fun fromValue(value: Int): CapabilityBooleanType? { + return when (value) { + -1 -> UNKNOWN + 0 -> FALSE + 1 -> TRUE + else -> null + } } - } - fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType { - return if (boolValue) { - TRUE - } else { - FALSE + fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType { + return if (boolValue) { + TRUE + } else { + FALSE + } } } } + + companion object { + private const val DEFAULT_MIN_CHARACTERS_TO_SEARCH = 2 + } } From fdeb504d87e99ea9dcd87f14836da6480d8d69fc Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 11 Dec 2019 12:46:13 +0100 Subject: [PATCH 36/36] Update versionName and versionCode to 1.0.4 --- owncloudComLibrary/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 384dacf3..a00d52bb 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -22,8 +22,8 @@ android { minSdkVersion 19 targetSdkVersion 28 - versionCode = 10000300 - versionName = "1.0.3" + versionCode = 10000400 + versionName = "1.0.4" } lintOptions {