From bcc5a0633511aef88da14213a7a63104d94596ed Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 29 Aug 2019 10:55:48 +0200 Subject: [PATCH 1/8] Get rid of conditions for <10 servers --- .../lib/common/DynamicSessionManager.java | 62 ------------- .../common/OwnCloudClientManagerFactory.java | 14 ++- .../lib/common/accounts/AccountUtils.java | 8 +- .../OwnCloudCredentialsFactory.java | 6 -- .../files/CopyRemoteFileOperation.java | 14 +-- .../files/CreateRemoteFolderOperation.java | 25 +----- .../files/MoveRemoteFileOperation.java | 11 --- .../files/RenameRemoteFileOperation.java | 12 +-- .../lib/resources/shares/RemoteShare.kt | 10 +-- .../ShareToRemoteOperationResultParser.kt | 2 +- .../lib/resources/shares/ShareUtils.java | 13 +-- .../lib/resources/status/OwnCloudVersion.kt | 86 +++---------------- 12 files changed, 31 insertions(+), 232 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.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 deleted file mode 100644 index 4a69fac4..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.owncloud.android.lib.common; - -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.content.Context; - -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; - -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} - * - * @author David A. Velasco - */ - -public class DynamicSessionManager implements OwnCloudClientManager { - - private SimpleFactoryManager mSimpleFactoryManager = new SimpleFactoryManager(); - - private SingleSessionManager mSingleSessionManager = new SingleSessionManager(); - - @Override - public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) - throws OperationCanceledException, AuthenticatorException, IOException { - - OwnCloudVersion ownCloudVersion = null; - if (account.getSavedAccount() != null) { - ownCloudVersion = AccountUtils.getServerVersionForAccount( - account.getSavedAccount(), context - ); - } - - if (ownCloudVersion != null && ownCloudVersion.isSessionMonitoringSupported()) { - return mSingleSessionManager.getClientFor(account, context); - } else { - return mSimpleFactoryManager.getClientFor(account, context); - } - } - - @Override - public OwnCloudClient removeClientFor(OwnCloudAccount account) { - OwnCloudClient clientRemovedFromFactoryManager = mSimpleFactoryManager.removeClientFor(account); - OwnCloudClient clientRemovedFromSingleSessionManager = mSingleSessionManager.removeClientFor(account); - if (clientRemovedFromSingleSessionManager != null) { - return clientRemovedFromSingleSessionManager; - } else { - return clientRemovedFromFactoryManager; - } - // clientRemoved and clientRemoved2 should not be != null at the same time - } - - @Override - public void saveAllClients(Context context, String accountType) { - mSimpleFactoryManager.saveAllClients(context, accountType); - mSingleSessionManager.saveAllClients(context, accountType); - } -} 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 14944a15..02304502 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 @@ -29,17 +29,17 @@ public class OwnCloudClientManagerFactory { private static OwnCloudClientManager sDefaultSingleton; private static String sUserAgent; - public static OwnCloudClientManager newDefaultOwnCloudClientManager() { + private static OwnCloudClientManager newDefaultOwnCloudClientManager() { return newOwnCloudClientManager(sDefaultPolicy); } - public static OwnCloudClientManager newOwnCloudClientManager(Policy policy) { + private static OwnCloudClientManager newOwnCloudClientManager(Policy policy) { switch (policy) { case ALWAYS_NEW_CLIENT: return new SimpleFactoryManager(); - case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING: - return new DynamicSessionManager(); + case SINGLE_SESSION_PER_ACCOUNT: + return new SingleSessionManager(); default: throw new IllegalArgumentException("Unknown policy"); @@ -53,10 +53,6 @@ public class OwnCloudClientManagerFactory { return sDefaultSingleton; } - public static Policy getDefaultPolicy() { - return sDefaultPolicy; - } - public static void setDefaultPolicy(Policy policy) { if (policy == null) { throw new IllegalArgumentException("Default policy cannot be NULL"); @@ -84,6 +80,6 @@ public class OwnCloudClientManagerFactory { public enum Policy { ALWAYS_NEW_CLIENT, - SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING + SINGLE_SESSION_PER_ACCOUNT } } 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 0b5911b2..649fb630 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 @@ -143,7 +143,6 @@ public class AccountUtils { boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE"); String username = AccountUtils.getUsernameForAccount(account); - OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION)); if (isOauth2) { String accessToken = am.blockingGetAuthToken( @@ -152,7 +151,6 @@ public class AccountUtils { false); credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken); - } else { String password = am.blockingGetAuthToken( account, @@ -161,8 +159,7 @@ public class AccountUtils { credentials = OwnCloudCredentialsFactory.newBasicCredentials( username, - password, - version.isPreemptiveAuthenticationPreferred() + password ); } @@ -201,9 +198,8 @@ public class AccountUtils { if (url.contains("://")) { url = url.substring(serverBaseUrl.toString().indexOf("://") + 3); } - String accountName = username + "@" + url; - return accountName; + return username + "@" + url; } public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) { 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 822ef760..6e1172fa 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 @@ -38,12 +38,6 @@ public class OwnCloudCredentialsFactory { return new OwnCloudBasicCredentials(username, password); } - public static OwnCloudCredentials newBasicCredentials( - String username, String password, boolean preemptiveMode - ) { - return new OwnCloudBasicCredentials(username, password, preemptiveMode); - } - public static OwnCloudCredentials newBearerCredentials(String username, String authToken) { return new OwnCloudBearerCredentials(username, authToken); } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java index 79852444..f41c8220 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import java.net.URL; import java.util.concurrent.TimeUnit; @@ -41,11 +40,12 @@ import java.util.concurrent.TimeUnit; /** * Remote operation moving a remote file or folder in the ownCloud server to a different folder * in the same account. - *

+ * * Allows renaming the moving file/folder at the same time. * * @author David A. Velasco * @author Christian Schabesberger + * @author David González V. */ public class CopyRemoteFileOperation extends RemoteOperation { @@ -81,14 +81,6 @@ public class CopyRemoteFileOperation extends RemoteOperation { */ @Override protected RemoteOperationResult run(OwnCloudClient client) { - OwnCloudVersion version = client.getOwnCloudVersion(); - boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); - - /// check parameters - if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) { - return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); - } if (mTargetRemotePath.equals(mSrcRemotePath)) { // nothing to do! @@ -100,7 +92,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { } /// perform remote operation - RemoteOperationResult result; + RemoteOperationResult result; try { CopyMethod copyMethod = new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)), diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java index 4e8ccd52..becb85e4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.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 @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import timber.log.Timber; import java.net.URL; @@ -73,25 +72,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation { */ @Override protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - OwnCloudVersion version = client.getOwnCloudVersion(); - boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); - boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, versionWithForbiddenChars); - if (noInvalidChars) { - result = createFolder(client); - if (!result.isSuccess() && mCreateFullPath && - RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { - result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); - if (result.isSuccess()) { - result = createFolder(client); // second (and last) try - } - } - } else { - result = new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); - } - - return result; + return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); } private RemoteOperationResult createFolder(OwnCloudClient client) { @@ -121,4 +102,4 @@ public class CreateRemoteFolderOperation extends RemoteOperation { RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, mCreateFullPath); return operation.execute(client); } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java index 2bebe540..d6275c1d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java @@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import java.net.URL; import java.util.concurrent.TimeUnit; @@ -87,16 +86,6 @@ public class MoveRemoteFileOperation extends RemoteOperation { */ @Override protected RemoteOperationResult run(OwnCloudClient client) { - - OwnCloudVersion version = client.getOwnCloudVersion(); - boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); - - /// check parameters - if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) { - return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); - } - if (mTargetRemotePath.equals(mSrcRemotePath)) { // nothing to do! return new RemoteOperationResult<>(ResultCode.OK); diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index a1c289fa..221a133c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.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 @@ -31,7 +31,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import timber.log.Timber; import java.io.File; @@ -84,15 +83,6 @@ public class RenameRemoteFileOperation extends RemoteOperation { */ @Override protected RemoteOperationResult run(OwnCloudClient client) { - - final OwnCloudVersion version = client.getOwnCloudVersion(); - final boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); - - if (!FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars)) { - return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); - } - try { if (mNewName.equals(mOldName)) { return new RemoteOperationResult<>(ResultCode.OK); 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 a0a4afea..47184f4a 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 @@ -66,16 +66,14 @@ data class RemoteShare( const val MAXIMUM_PERMISSIONS_FOR_FOLDER = MAXIMUM_PERMISSIONS_FOR_FILE + CREATE_PERMISSION_FLAG + DELETE_PERMISSION_FLAG - const val FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 = READ_PERMISSION_FLAG + UPDATE_PERMISSION_FLAG - const val FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 = READ_PERMISSION_FLAG + + const val FEDERATED_PERMISSIONS_FOR_FILE = READ_PERMISSION_FLAG + UPDATE_PERMISSION_FLAG + SHARE_PERMISSION_FLAG - const val FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 = READ_PERMISSION_FLAG + + const val FEDERATED_PERMISSIONS_FOR_FOLDER = READ_PERMISSION_FLAG + UPDATE_PERMISSION_FLAG + CREATE_PERMISSION_FLAG + - DELETE_PERMISSION_FLAG - const val FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 = - FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 + SHARE_PERMISSION_FLAG + DELETE_PERMISSION_FLAG + + SHARE_PERMISSION_FLAG const val INIT_EXPIRATION_DATE_IN_MILLIS: Long = 0 const val INIT_SHARED_DATE: Long = 0 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 490f9c2b..31fcff51 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 @@ -72,7 +72,7 @@ class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLPar } if (serverBaseUri != null) { - val sharingLinkPath = ShareUtils.getSharingLinkPath(ownCloudVersion) + val sharingLinkPath = ShareUtils.SHARING_LINK_PATH share.shareLink = serverBaseUri.toString() + sharingLinkPath + share.token } else { Timber.e("Couldn't build link for public share :(") diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java index 4d4b80ae..f09642de 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java @@ -39,14 +39,5 @@ public class ShareUtils { public static final String SHARING_API_PATH = "ocs/v2.php/apps/files_sharing/api/v1/shares"; // String to build the link with the token of a share: - public static final String SHARING_LINK_PATH_BEFORE_VERSION_8 = "/public.php?service=files&t="; - public static final String SHARING_LINK_PATH_AFTER_VERSION_8 = "/index.php/s/"; - - public static String getSharingLinkPath(OwnCloudVersion version) { - if (version != null && version.isAfter8Version()) { - return SHARING_LINK_PATH_AFTER_VERSION_8; - } else { - return SHARING_LINK_PATH_BEFORE_VERSION_8; - } - } -} \ No newline at end of file + public static final String SHARING_LINK_PATH = "/index.php/s/"; +} 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 e395e5ab..d71114fb 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 @@ -45,46 +45,9 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable INVALID_ZERO_VERSION } - val isChunkedUploadSupported: Boolean - get() = mVersion >= MINIMUN_VERSION_FOR_CHUNKED_UPLOADS - - val isSharedSupported: Boolean - get() = mVersion >= MINIMUM_VERSION_FOR_SHARING_API - - val isVersionWithForbiddenCharacters: Boolean - get() = mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS - - val isAfter8Version: Boolean - get() = mVersion >= VERSION_8 - - val isSearchUsersSupported: Boolean - get() = mVersion >= MINIMUM_VERSION_FOR_SEARCHING_USERS - - val isVersionWithCapabilitiesAPI: Boolean - get() = mVersion >= MINIMUM_VERSION_CAPABILITIES_API - - val isNotReshareableFederatedSupported: Boolean - get() = mVersion >= MINIMUM_VERSION_WITH_NOT_RESHAREABLE_FEDERATED - - val isSessionMonitoringSupported: Boolean - get() = mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING - - /** - * From OC 9.1 session tracking is a feature, but to get it working in the OC app we need the preemptive - * mode of basic authentication is disabled. This changes in OC 9.1.3, where preemptive mode is compatible - * with session tracking again. - * - * @return True for every version before 9.1 and from 9.1.3, false otherwise - */ - val isPreemptiveAuthenticationPreferred: Boolean - get() = mVersion < MINIMUM_VERSION_WITH_SESSION_MONITORING || mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE - val isVersionLowerThan10: Boolean get() = mVersion < VERSION_10 - val isMultiplePublicSharingSupported: Boolean - get() = mVersion >= MINIMUM_VERSION_WITH_MULTIPLE_PUBLIC_SHARING - val isPublicSharingWriteOnlySupported: Boolean get() = mVersion >= MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING @@ -94,17 +57,17 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable mVersion > MINIMUN_MICRO_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION) init { - var version = version + var versionToParse = version mVersion = 0 isVersionValid = false - val countDots = version.length - version.replace(".", "").length + val countDots = versionToParse.length - versionToParse.replace(".", "").length // Complete the version. Version must have 3 dots for (i in countDots until MAX_DOTS) { - version = "$version.0" + versionToParse = "$versionToParse.0" } - parseVersion(version) + parseVersion(versionToParse) } @@ -122,10 +85,10 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable return versionToString } - override fun compareTo(another: OwnCloudVersion): Int { - return if (another.mVersion == mVersion) + override fun compareTo(other: OwnCloudVersion): Int { + return if (other.mVersion == mVersion) 0 - else if (another.mVersion < mVersion) 1 else -1 + else if (other.mVersion < mVersion) 1 else -1 } private fun parseVersion(version: String) { @@ -137,20 +100,18 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable isVersionValid = false // if invalid, the instance will respond as if server is 8.1, minimum with capabilities API, // and "dead" : https://github.com/owncloud/core/wiki/Maintenance-and-Release-Schedule - mVersion = MINIMUM_VERSION_CAPABILITIES_API } - } @Throws(NumberFormatException::class) private fun getParsedVersion(version: String): Int { - var version = version + var versionToParse = version var versionValue = 0 // get only numeric part - version = version.replace("[^\\d.]".toRegex(), "") + versionToParse = versionToParse.replace("[^\\d.]".toRegex(), "") - val nums = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() + val nums = versionToParse.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() var i = 0 while (i < nums.size && i <= MAX_DOTS) { versionValue += Integer.parseInt(nums[i]) @@ -163,10 +124,6 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable return versionValue } - fun supportsRemoteThumbnails(): Boolean { - return mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS - } - override fun describeContents(): Int { return super.hashCode() } @@ -181,31 +138,8 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable private const val MINIMUN_MICRO_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0x03000000 // 3.0.0 - const val MINIMUN_VERSION_FOR_CHUNKED_UPLOADS = 0x04050000 // 4.5 - - const val MINIMUM_VERSION_FOR_SHARING_API = 0x05001B00 // 5.0.27 - - const val MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000 // 8.1 - - const val MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS = 0x07080000 // 7.8.0 - - const val MINIMUM_VERSION_FOR_SEARCHING_USERS = 0x08020000 //8.2 - - const val VERSION_8 = 0x08000000 // 8.0 - - const val MINIMUM_VERSION_CAPABILITIES_API = 0x08010000 // 8.1 - - private const val MINIMUM_VERSION_WITH_NOT_RESHAREABLE_FEDERATED = 0x09010000 // 9.1 - - private const val MINIMUM_VERSION_WITH_SESSION_MONITORING = 0x09010000 // 9.1 - - private const val MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE = 0x09010301 - // 9.1.3.1, final 9.1.3: https://github.com/owncloud/core/commit/f9a867b70c217463289a741d4d26079eb2a80dfd - private const val VERSION_10 = 0xA000000 // 10.0.0 - private const val MINIMUM_VERSION_WITH_MULTIPLE_PUBLIC_SHARING = 0xA000000 // 10.0.0 - private const val MINIMUN_MAJOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0xA000000 // 10.0.0 private const val MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING = 0xA000100 // 10.0.1 From 234add959a7d2c537e5a2fd550616174684c8ccb Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 2 Sep 2019 10:02:47 +0200 Subject: [PATCH 2/8] Apply changes requested in PR --- .../owncloud/android/lib/resources/files/FileUtils.java | 9 --------- 1 file changed, 9 deletions(-) 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 48969f90..fbf5a359 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 @@ -26,19 +26,10 @@ package com.owncloud.android.lib.resources.files; import timber.log.Timber; -import java.io.File; - public class FileUtils { - public static final String PATH_SEPARATOR = "/"; public static final String FINAL_CHUNKS_FILE = ".file"; - public static String getParentPath(String remotePath) { - String parentPath = new File(remotePath).getParent(); - parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR; - return parentPath; - } - /** * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , * : , " , | , ? , * From 495e3321e2bb961465da76aaec963995216b33cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gonz=C3=A1lez?= Date: Tue, 10 Sep 2019 15:24:50 +0200 Subject: [PATCH 3/8] Fix folder creation --- .../files/CreateRemoteFolderOperation.java | 10 +++++++++- .../android/lib/resources/files/FileUtils.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java index becb85e4..3985ab2c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java @@ -72,7 +72,15 @@ public class CreateRemoteFolderOperation extends RemoteOperation { */ @Override protected RemoteOperationResult run(OwnCloudClient client) { - return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); + RemoteOperationResult result = createFolder(client); + if (!result.isSuccess() && mCreateFullPath && + RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { + result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); + if (result.isSuccess()) { + result = createFolder(client); // second (and last) try + } + } + return result; } private RemoteOperationResult createFolder(OwnCloudClient client) { 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 fbf5a359..0fb8248a 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 @@ -66,4 +66,21 @@ public class FileUtils { } return result; } + + /** + * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , + * : , " , | , ? , * + * + * @param fileName + * @return + */ + public static boolean isValidName(String fileName) { + boolean result = true; + + Log_OC.d(TAG, "fileName =======" + fileName); + if (fileName.contains(PATH_SEPARATOR)) { + result = false; + } + return result; + } } From 8ba4fa5960cb3f5f756a3cba6ff0af31d2ee4fa9 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 23 Sep 2019 09:32:04 +0200 Subject: [PATCH 4/8] Handle specific bad request error --- .../lib/common/operations/RemoteOperationResult.java | 12 ++++++++---- .../android/lib/resources/files/FileUtils.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) 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 db86e6b8..eacb4e69 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 @@ -188,8 +188,12 @@ public class RemoteOperationResult try { if (xmlParser.parseXMLResponse(is)) { mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER; + } else { + parseErrorMessageAndSetCode( + httpMethod.getResponseBodyAsString(), + ResultCode.SPECIFIC_BAD_REQUEST + ); } - } catch (Exception e) { Timber.w("Error reading exception from server: %s", e.getMessage()); // mCode stays as set in this(success, httpCode, headers) @@ -305,13 +309,12 @@ public class RemoteOperationResult * @param resultCode our own custom result code */ private void parseErrorMessageAndSetCode(String bodyResponse, ResultCode resultCode) { - if (bodyResponse != null && bodyResponse.length() > 0) { InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); ErrorMessageParser xmlParser = new ErrorMessageParser(); try { String errorMessage = xmlParser.parseXMLResponse(is); - if (errorMessage != null && !errorMessage.equals("")) { + if (!errorMessage.equals("")) { mCode = resultCode; mHttpPhrase = errorMessage; } @@ -566,6 +569,7 @@ public class RemoteOperationResult SERVICE_UNAVAILABLE, SPECIFIC_SERVICE_UNAVAILABLE, SPECIFIC_UNSUPPORTED_MEDIA_TYPE, - SPECIFIC_METHOD_NOT_ALLOWED + SPECIFIC_METHOD_NOT_ALLOWED, + SPECIFIC_BAD_REQUEST } } 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 0fb8248a..8a6c9f67 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 @@ -77,7 +77,7 @@ public class FileUtils { public static boolean isValidName(String fileName) { boolean result = true; - Log_OC.d(TAG, "fileName =======" + fileName); + Timber.d("fileName =======%s", fileName); if (fileName.contains(PATH_SEPARATOR)) { result = false; } From 20e4317bd9153bc7ba7a917c96fae8dd5823a2c5 Mon Sep 17 00:00:00 2001 From: davigonz Date: Tue, 3 Dec 2019 18:14:09 +0100 Subject: [PATCH 5/8] Include new isServerVersionSupported parameter to log out <10 accounts --- .../owncloud/android/lib/common/OwnCloudClient.java | 11 +++++++---- .../android/lib/resources/status/OwnCloudVersion.kt | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) 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 fc970891..dd4fdf37 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 @@ -381,16 +381,19 @@ public class OwnCloudClient extends HttpClient { * cannot be invalidated with the given arguments. */ private boolean shouldInvalidateAccountCredentials(int httpStatusCode) { + boolean isServerVersionSupported = AccountUtils.getServerVersionForAccount(getAccount().getSavedAccount(), + getContext()).isServerVersionSupported(); - boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); // invalid credentials + boolean shouldInvalidateAccountCredentials = + (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED || !isServerVersionSupported); - should &= (mCredentials != null && // real credentials + shouldInvalidateAccountCredentials &= (mCredentials != null && // real credentials !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); // test if have all the needed to effectively invalidate ... - should &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null); + shouldInvalidateAccountCredentials &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null); - return should; + return shouldInvalidateAccountCredentials; } /** 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 d71114fb..5cadbcf9 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 @@ -45,8 +45,8 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable INVALID_ZERO_VERSION } - val isVersionLowerThan10: Boolean - get() = mVersion < VERSION_10 + val isServerVersionSupported: Boolean + get() = mVersion >= MINIMUN_VERSION_SUPPORTED val isPublicSharingWriteOnlySupported: Boolean get() = mVersion >= MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING @@ -144,6 +144,8 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable private const val MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING = 0xA000100 // 10.0.1 + private const val MINIMUN_VERSION_SUPPORTED = 0xA000000 // 10.0.0 + private const val INVALID_ZERO_VERSION = "0.0.0" private const val MAX_DOTS = 3 From 52463707c7c8a2b21972580839182a4f08c83287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Fri, 20 Dec 2019 13:24:04 +0100 Subject: [PATCH 6/8] Remove unused constants --- .../lib/resources/status/OwnCloudVersion.kt | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) 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 5cadbcf9..c8c75653 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 @@ -51,11 +51,6 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable val isPublicSharingWriteOnlySupported: Boolean get() = mVersion >= MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING - val isPublicUploadPermissionNeeded: Boolean - get() = mVersion >= MINIMUN_MAJOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION && - (mVersion > MINIMUN_MINOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION || - mVersion > MINIMUN_MICRO_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION) - init { var versionToParse = version mVersion = 0 @@ -134,18 +129,10 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable } companion object { - private const val MINIMUN_MINOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0x01000000 // 1.0.0 - - private const val MINIMUN_MICRO_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0x03000000 // 3.0.0 - - private const val VERSION_10 = 0xA000000 // 10.0.0 - - private const val MINIMUN_MAJOR_VERSION_WITHOUT_PUBLIC_UPLOAD_PERMISSION = 0xA000000 // 10.0.0 + private const val MINIMUN_VERSION_SUPPORTED = 0xA000000 // 10.0.0 private const val MINIMUM_VERSION_WITH_WRITE_ONLY_PUBLIC_SHARING = 0xA000100 // 10.0.1 - private const val MINIMUN_VERSION_SUPPORTED = 0xA000000 // 10.0.0 - private const val INVALID_ZERO_VERSION = "0.0.0" private const val MAX_DOTS = 3 From 03e30ae6983bb6f269643912d82466a7559e84a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Fri, 20 Dec 2019 13:25:00 +0100 Subject: [PATCH 7/8] Fix log with old server version --- .../java/com/owncloud/android/lib/common/OwnCloudClient.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 dd4fdf37..ccfb8ebf 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 @@ -381,11 +381,8 @@ public class OwnCloudClient extends HttpClient { * cannot be invalidated with the given arguments. */ private boolean shouldInvalidateAccountCredentials(int httpStatusCode) { - boolean isServerVersionSupported = AccountUtils.getServerVersionForAccount(getAccount().getSavedAccount(), - getContext()).isServerVersionSupported(); - boolean shouldInvalidateAccountCredentials = - (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED || !isServerVersionSupported); + (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); shouldInvalidateAccountCredentials &= (mCredentials != null && // real credentials !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); From 4cd317d929af90034370e5183cd6322ee64435af Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 17 Jan 2020 11:13:21 +0100 Subject: [PATCH 8/8] Fix build after rebasing with master --- .../lib/resources/files/FileUtils.java | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) 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 8a6c9f67..b3bbb844 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 @@ -26,45 +26,16 @@ package com.owncloud.android.lib.resources.files; import timber.log.Timber; +import java.io.File; + public class FileUtils { public static final String PATH_SEPARATOR = "/"; public static final String FINAL_CHUNKS_FILE = ".file"; - /** - * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , - * : , " , | , ? , * - */ - public static boolean isValidName(String fileName, boolean versionSupportsForbiddenChars) { - boolean result = true; - - Timber.d("fileName =======%s", fileName); - if ((versionSupportsForbiddenChars && fileName.contains(PATH_SEPARATOR)) || - (!versionSupportsForbiddenChars && (fileName.contains(PATH_SEPARATOR) || - fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") || - fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") || - fileName.contains("?") || fileName.contains("*")))) { - - result = false; - } - return result; - } - - /** - * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , - * ? , * - */ - public static boolean isValidPath(String path, boolean versionSupportsForbidenChars) { - boolean result = true; - - Timber.d("path ....... %s", path); - if (!versionSupportsForbidenChars && - (path.contains("\\") || path.contains("<") || path.contains(">") || - path.contains(":") || path.contains("\"") || path.contains("|") || - path.contains("?") || path.contains("*"))) { - - result = false; - } - return result; + static String getParentPath(String remotePath) { + String parentPath = new File(remotePath).getParent(); + parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR; + return parentPath; } /**