From 93497ca225ab7ce7638d441148a42ab1d64c93e1 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 15 May 2021 07:00:04 +0200 Subject: [PATCH 01/11] Gradle 6.9 It comes with Apple Silicon support --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 28ff446a..549d8442 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From c02a4dea91fceffc1c7f3683a3a1d7a3973f7266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Wed, 26 May 2021 08:57:03 +0200 Subject: [PATCH 02/11] Bump kotlin version --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 1e026bbc..b06d72dd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - kotlinVersion = '1.4.32' + kotlinVersion = '1.5.10' moshiVersion = "1.12.0" } @@ -11,7 +11,7 @@ buildscript { } dependencies { classpath "org.jlleitschuh.gradle:ktlint-gradle:10.0.0" - classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.android.tools.build:gradle:4.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } From 58ac89cb3001ad0b457fc1ba99042e4705307496 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 3 Jun 2021 06:49:43 +0000 Subject: [PATCH 03/11] Bump ktlint-gradle from 10.0.0 to 10.1.0 Bumps ktlint-gradle from 10.0.0 to 10.1.0. --- updated-dependencies: - dependency-name: org.jlleitschuh.gradle:ktlint-gradle dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b06d72dd..cae27df6 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath "org.jlleitschuh.gradle:ktlint-gradle:10.0.0" + classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0" classpath 'com.android.tools.build:gradle:4.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } From b491641eff8da4c1cf4971c133bf1e002d57d8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Fri, 2 Jul 2021 09:57:38 +0200 Subject: [PATCH 04/11] Bump kotlin to 1.5.20 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index cae27df6..d3baae95 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - kotlinVersion = '1.5.10' + kotlinVersion = '1.5.20' moshiVersion = "1.12.0" } @@ -11,7 +11,7 @@ buildscript { } dependencies { classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0" - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } From 99e636e8f6101545cd09b7a86c6ad3950feb3ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Thu, 24 Jun 2021 10:19:11 +0200 Subject: [PATCH 05/11] Add a new operation to upload files directly with a content uri --- .../UploadFileFromContentUriOperation.kt | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt new file mode 100644 index 00000000..75c031eb --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt @@ -0,0 +1,70 @@ +package com.owncloud.android.lib.resources.files + +import android.content.ContentResolver +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.webdav.PutMethod +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 okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody +import okio.BufferedSink +import okio.source +import timber.log.Timber +import java.io.IOException +import java.net.URL + +class UploadFileFromContentUriOperation( + private val uploadPath: String, + private val lastModified: String, + private val requestBody: ContentUriRequestBody +) : RemoteOperation() { + + override fun run(client: OwnCloudClient): RemoteOperationResult { + val putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply { + setRetryOnConnectionFailure(false) + addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString()) + addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified) + } + + return try { + val status = client.executeHttpMethod(putMethod) + if (isSuccess(status)) { + RemoteOperationResult(RemoteOperationResult.ResultCode.OK) + } else { + RemoteOperationResult(putMethod) + } + } catch (e: Exception) { + val result = RemoteOperationResult(e) + Timber.e(e, "Upload from content uri failed : ${result.logMessage}") + result + } + } + + fun isSuccess(status: Int): Boolean { + return status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT + } +} + +class ContentUriRequestBody( + private val contentResolver: ContentResolver, + private val contentUri: Uri +) : RequestBody() { + + override fun contentType(): MediaType? { + val contentType = contentResolver.getType(contentUri) ?: return null + return contentType.toMediaTypeOrNull() + } + + override fun writeTo(sink: BufferedSink) { + val inputStream = contentResolver.openInputStream(contentUri) + ?: throw IOException("Couldn't open content URI for reading: $contentUri") + + inputStream.source().use { source -> + sink.writeAll(source) + } + } +} From 5c2be25d665fbb7c217383626d6085cc14d2abcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Thu, 1 Jul 2021 08:58:05 +0200 Subject: [PATCH 06/11] Override contentLength in content uri request body to fix uploads to ocis --- .../resources/files/UploadFileFromContentUriOperation.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt index 75c031eb..e539e019 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt @@ -2,6 +2,7 @@ package com.owncloud.android.lib.resources.files import android.content.ContentResolver import android.net.Uri +import android.provider.OpenableColumns import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.webdav.PutMethod @@ -59,6 +60,14 @@ class ContentUriRequestBody( return contentType.toMediaTypeOrNull() } + override fun contentLength(): Long { + contentResolver.query(contentUri, null, null, null, null)?.use { cursor -> + val sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE) + cursor.moveToFirst() + return cursor.getLong(sizeIndex) + } ?: return -1 + } + override fun writeTo(sink: BufferedSink) { val inputStream = contentResolver.openInputStream(contentUri) ?: throw IOException("Couldn't open content URI for reading: $contentUri") From 12b009e37893ff2680c6744c0a2a189eee21bc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Fri, 2 Jul 2021 09:13:39 +0200 Subject: [PATCH 07/11] Update operation --- .../UploadFileFromContentUriOperation.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt index e539e019..580fab06 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt @@ -1,3 +1,27 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2021 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.files import android.content.ContentResolver From 22719c8f40fd804a104d92819b2c304d58e9c085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Thu, 8 Jul 2021 12:24:21 +0200 Subject: [PATCH 08/11] Return unit in the remote operation --- .../lib/resources/files/UploadFileFromContentUriOperation.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt index 580fab06..9a1e1b19 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromContentUriOperation.kt @@ -58,7 +58,7 @@ class UploadFileFromContentUriOperation( return try { val status = client.executeHttpMethod(putMethod) if (isSuccess(status)) { - RemoteOperationResult(RemoteOperationResult.ResultCode.OK) + RemoteOperationResult(RemoteOperationResult.ResultCode.OK).apply { data = Unit } } else { RemoteOperationResult(putMethod) } From 3025ddce23f90b33fe7708f92a655ee956bc5177 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Jul 2021 07:06:34 +0000 Subject: [PATCH 09/11] Bump kotlinVersion from 1.5.20 to 1.5.21 Bumps `kotlinVersion` from 1.5.20 to 1.5.21. Updates `kotlin-gradle-plugin` from 1.5.20 to 1.5.21 - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/v1.5.21/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/compare/v1.5.20...v1.5.21) Updates `kotlin-stdlib-jdk8` from 1.5.20 to 1.5.21 - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/v1.5.21/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/compare/v1.5.20...v1.5.21) --- updated-dependencies: - dependency-name: org.jetbrains.kotlin:kotlin-gradle-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.jetbrains.kotlin:kotlin-stdlib-jdk8 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d3baae95..cc00a901 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - kotlinVersion = '1.5.20' + kotlinVersion = '1.5.21' moshiVersion = "1.12.0" } From 20070775d73aee12db7420d91fff792ae967d995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Tue, 6 Jul 2021 18:31:39 +0200 Subject: [PATCH 10/11] Add parameters required for PKCE --- .../com/owncloud/android/lib/common/http/HttpConstants.java | 1 + .../android/lib/resources/oauth/params/TokenRequestParams.kt | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java index ad8c6d1c..12a2c3f6 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java @@ -56,6 +56,7 @@ public class HttpConstants { public static final String OAUTH_HEADER_GRANT_TYPE = "grant_type"; public static final String OAUTH_HEADER_REDIRECT_URI = "redirect_uri"; public static final String OAUTH_HEADER_REFRESH_TOKEN = "refresh_token"; + public static final String OAUTH_HEADER_CODE_VERIFIER = "code_verifier"; /*********************************************************************************************************** ************************************************ CONTENT TYPES ******************************************** diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/oauth/params/TokenRequestParams.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/oauth/params/TokenRequestParams.kt index 367af463..c3dff9cd 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/oauth/params/TokenRequestParams.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/oauth/params/TokenRequestParams.kt @@ -39,7 +39,8 @@ sealed class TokenRequestParams( clientAuth: String, grantType: String, val authorizationCode: String, - val redirectUri: String + val redirectUri: String, + val codeVerifier: String, ) : TokenRequestParams(tokenEndpoint, clientAuth, grantType) { override fun toRequestBody(): RequestBody = @@ -47,6 +48,7 @@ sealed class TokenRequestParams( .add(HttpConstants.OAUTH_HEADER_AUTHORIZATION_CODE, authorizationCode) .add(HttpConstants.OAUTH_HEADER_GRANT_TYPE, grantType) .add(HttpConstants.OAUTH_HEADER_REDIRECT_URI, redirectUri) + .add(HttpConstants.OAUTH_HEADER_CODE_VERIFIER, codeVerifier) .build() } From 7b5c070175478518102170f22de6241e6e0d00bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Thu, 15 Jul 2021 09:55:21 +0200 Subject: [PATCH 11/11] Update version name and version code --- owncloudComLibrary/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 175bb0bd..b343af5f 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -25,8 +25,8 @@ android { minSdkVersion 21 targetSdkVersion 29 - versionCode = 10001100 - versionName = "1.0.11" + versionCode = 10001200 + versionName = "1.0.12" } lintOptions {