diff --git a/README.md b/README.md index b86531b1..ae89e67f 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,6 @@ ownCloud Android Library uses OkHttp version 4.6.0, licensed under Apache Licens ### Compatibility -ownCloud Android Library is valid for Android systems from version Android 5 (android:minSdkVersion="21" android:targetSdkVersion="29"). +ownCloud Android Library is valid for Android systems from version Android 6 (android:minSdkVersion="23" android:targetSdkVersion="33"). ownCloud Android library supports ownCloud server from version 4.5. diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index e626c033..3721ad37 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -25,7 +25,7 @@ android { compileSdkVersion 33 defaultConfig { - minSdkVersion 21 + minSdkVersion 23 targetSdkVersion 33 } diff --git a/owncloudComLibrary/src/main/AndroidManifest.xml b/owncloudComLibrary/src/main/AndroidManifest.xml index baef71f2..b9c2a7c2 100644 --- a/owncloudComLibrary/src/main/AndroidManifest.xml +++ b/owncloudComLibrary/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ - - - diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt index 217f3ca9..dece5053 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt @@ -36,7 +36,7 @@ import java.net.URL class CopyMethod( val url: URL, private val destinationUrl: String, - private val forceOverride: Boolean = false + val forceOverride: Boolean = false ) : DavMethod(url) { @Throws(Exception::class) public override fun onDavExecute(davResource: DavOCResource): Int { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt index 8cb4c0e9..0921f180 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt @@ -36,7 +36,7 @@ import java.net.URL class MoveMethod( url: URL, private val destinationUrl: String, - private val forceOverride: Boolean = false + val forceOverride: Boolean = false ) : DavMethod(url) { @Throws(Exception::class) override fun onDavExecute(davResource: DavOCResource): Int { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/GetRemoteAppRegistryOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/GetRemoteAppRegistryOperation.kt index 60367ff0..e8ea864a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/GetRemoteAppRegistryOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/GetRemoteAppRegistryOperation.kt @@ -37,14 +37,14 @@ import com.squareup.moshi.Moshi import timber.log.Timber import java.net.URL -class GetRemoteAppRegistryOperation : RemoteOperation() { +class GetRemoteAppRegistryOperation(private val appUrl: String?) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { var result: RemoteOperationResult try { val uriBuilder = client.baseUri.buildUpon().apply { - appendEncodedPath(APP_REGISTRY_ENDPOINT) + appendEncodedPath(appUrl) } val getMethod = GetMethod(URL(uriBuilder.build().toString())) val status = client.executeHttpMethod(getMethod) @@ -75,8 +75,4 @@ class GetRemoteAppRegistryOperation : RemoteOperation() { return result } - - companion object { - private const val APP_REGISTRY_ENDPOINT = "app/list" - } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/AppRegistryService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/AppRegistryService.kt index 50145892..789129bd 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/AppRegistryService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/AppRegistryService.kt @@ -28,7 +28,7 @@ import com.owncloud.android.lib.resources.Service import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse interface AppRegistryService : Service { - fun getAppRegistry(): RemoteOperationResult + fun getAppRegistry(appUrl: String?): RemoteOperationResult fun getUrlToOpenInWeb( openWebEndpoint: String, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/OCAppRegistryService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/OCAppRegistryService.kt index e07ac100..34693103 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/OCAppRegistryService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/appregistry/services/OCAppRegistryService.kt @@ -31,8 +31,8 @@ import com.owncloud.android.lib.resources.appregistry.GetUrlToOpenInWebRemoteOpe import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse class OCAppRegistryService(override val client: OwnCloudClient) : AppRegistryService { - override fun getAppRegistry(): RemoteOperationResult = - GetRemoteAppRegistryOperation().execute(client) + override fun getAppRegistry(appUrl: String?): RemoteOperationResult = + GetRemoteAppRegistryOperation(appUrl).execute(client) override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String, appName: String): RemoteOperationResult = GetUrlToOpenInWebRemoteOperation( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt index da9b685f..a367d0ab 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt @@ -54,9 +54,8 @@ class CheckPathExistenceRemoteOperation( ) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { - val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.baseFilesWebDavUri.toString() - else client.userFilesWebDavUri.toString() - val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath) + val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.userFilesWebDavUri.toString() else client.baseFilesWebDavUri.toString() + val stringUrl = if (isUserLoggedIn) baseStringUrl + WebdavUtils.encodePath(remotePath) else baseStringUrl return try { val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropSet).apply { @@ -81,6 +80,7 @@ class CheckPathExistenceRemoteOperation( e, "Existence check for $stringUrl : ${result.logMessage}" ) + result.data = false result } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt index 949d72e9..3f0990c6 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt @@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit * @author Christian Schabesberger * @author David González V. * @author Juan Carlos Garrote Gascón + * @author Manuel Plazas Palacio * * @param sourceRemotePath Remote path of the file/folder to copy. * @param targetRemotePath Remote path desired for the file/folder to copy it. @@ -54,6 +55,7 @@ class CopyRemoteFileOperation( private val targetRemotePath: String, private val sourceSpaceWebDavUrl: String? = null, private val targetSpaceWebDavUrl: String? = null, + private val forceOverride: Boolean = false, ) : RemoteOperation() { /** @@ -74,9 +76,11 @@ class CopyRemoteFileOperation( var result: RemoteOperationResult try { val copyMethod = CopyMethod( - URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), - (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), + url = URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), + destinationUrl = (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), + forceOverride = forceOverride, ).apply { + addRequestHeaders(this) setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS) setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) } @@ -87,6 +91,7 @@ class CopyRemoteFileOperation( result = RemoteOperationResult(ResultCode.OK) result.setData(fileRemoteId) } + isPreconditionFailed(status) -> { result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE) client.exhaustResponse(copyMethod.getResponseBodyAsStream()) @@ -94,6 +99,7 @@ class CopyRemoteFileOperation( /// for other errors that could be explicitly handled, check first: /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 } + else -> { result = RemoteOperationResult(copyMethod) client.exhaustResponse(copyMethod.getResponseBodyAsStream()) @@ -107,6 +113,13 @@ class CopyRemoteFileOperation( return result } + private fun addRequestHeaders(copyMethod: CopyMethod) { + //Adding this because the library has an error with override + if (copyMethod.forceOverride) { + copyMethod.setRequestHeader(OVERWRITE, TRUE) + } + } + private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT) private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED @@ -114,5 +127,7 @@ class CopyRemoteFileOperation( companion object { private const val COPY_READ_TIMEOUT = 10L private const val COPY_CONNECTION_TIMEOUT = 6L + private const val OVERWRITE = "overwrite" + private const val TRUE = "T" } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt index 6689c5f9..6f9fb3d2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt @@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit * @author David González Verdugo * @author Abel García de Prada * @author Juan Carlos Garrote Gascón + * @author Manuel Plazas Palacio * * @param sourceRemotePath Remote path of the file/folder to copy. * @param targetRemotePath Remote path desired for the file/folder to copy it. @@ -54,6 +55,7 @@ open class MoveRemoteFileOperation( private val sourceRemotePath: String, private val targetRemotePath: String, private val spaceWebDavUrl: String? = null, + private val forceOverride: Boolean = false, ) : RemoteOperation() { /** @@ -80,6 +82,7 @@ open class MoveRemoteFileOperation( val moveMethod = MoveMethod( url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), + forceOverride = forceOverride, ).apply { addRequestHeaders(this) setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS) @@ -92,6 +95,7 @@ open class MoveRemoteFileOperation( isSuccess(status) -> { result = RemoteOperationResult(ResultCode.OK) } + isPreconditionFailed(status) -> { result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE) client.exhaustResponse(moveMethod.getResponseBodyAsStream()) @@ -99,6 +103,7 @@ open class MoveRemoteFileOperation( /// for other errors that could be explicitly handled, check first: /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 } + else -> { result = RemoteOperationResult(moveMethod) client.exhaustResponse(moveMethod.getResponseBodyAsStream()) @@ -125,6 +130,10 @@ open class MoveRemoteFileOperation( * In case new headers are needed, override this method */ open fun addRequestHeaders(moveMethod: MoveMethod) { + //Adding this because the library has an error with override + if (moveMethod.forceOverride) { + moveMethod.setRequestHeader(OVERWRITE, TRUE) + } } private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT) @@ -134,5 +143,7 @@ open class MoveRemoteFileOperation( companion object { private const val MOVE_READ_TIMEOUT = 10L private const val MOVE_CONNECTION_TIMEOUT = 6L + private const val OVERWRITE = "overwrite" + private const val TRUE = "T" } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.kt index 9a0a4b30..71329a97 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.kt @@ -106,7 +106,7 @@ class RenameRemoteFileOperation( * @return 'True' if the target path is already used by an existing file. */ private fun targetPathIsUsed(client: OwnCloudClient): Boolean { - val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation(newRemotePath, false) + val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation(newRemotePath, true) val exists = checkPathExistenceRemoteOperation.execute(client) return exists.isSuccess } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt index b524dc3f..43f5c57c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt @@ -39,7 +39,8 @@ interface FileService : Service { targetRemotePath: String, sourceSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?, - ): RemoteOperationResult + replace: Boolean, + ): RemoteOperationResult fun createFolder( remotePath: String, @@ -57,6 +58,7 @@ interface FileService : Service { sourceRemotePath: String, targetRemotePath: String, spaceWebDavUrl: String?, + replace: Boolean, ): RemoteOperationResult fun readFile( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt index 7b86a4fa..4d110858 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt @@ -54,12 +54,14 @@ class OCFileService(override val client: OwnCloudClient) : FileService { targetRemotePath: String, sourceSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?, - ): RemoteOperationResult = + replace: Boolean, + ): RemoteOperationResult = CopyRemoteFileOperation( sourceRemotePath = sourceRemotePath, targetRemotePath = targetRemotePath, sourceSpaceWebDavUrl = sourceSpaceWebDavUrl, targetSpaceWebDavUrl = targetSpaceWebDavUrl, + forceOverride = replace, ).execute(client) override fun createFolder( @@ -88,11 +90,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService { sourceRemotePath: String, targetRemotePath: String, spaceWebDavUrl: String?, + replace: Boolean, ): RemoteOperationResult = MoveRemoteFileOperation( sourceRemotePath = sourceRemotePath, targetRemotePath = targetRemotePath, spaceWebDavUrl = spaceWebDavUrl, + forceOverride = replace, ).execute(client) override fun readFile( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt index 0997f712..56715fcd 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt @@ -40,7 +40,7 @@ class OCServerInfoService : ServerInfoService { ): RemoteOperationResult = CheckPathExistenceRemoteOperation( remotePath = path, - isUserLoggedIn = true, + isUserLoggedIn = isUserLoggedIn, ).execute(client) override fun getRemoteStatus(