diff options
author | Álvaro Brey <alvaro.brey@nextcloud.com> | 2022-09-16 18:30:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-16 18:30:49 +0300 |
commit | fe0d1126a66f35e276c3d77626d4566394e7f7df (patch) | |
tree | 3f8c440a03dc63a9d57de3eafdf0e341556fb936 | |
parent | b9c511f774ef051188f88fc62a65b1551cad0bba (diff) | |
parent | a9c01f7e48bba42664be3a6ba4040f24797d28ab (diff) |
Merge pull request #966 from nextcloud/dependabot/gradle/com.android.tools.build-gradle-7.3.0
Bump gradle from 7.1.3 to 7.3.0
8 files changed, 399 insertions, 397 deletions
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b41eb9d7..6c4c3649 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 26 10:28:13 CET 2022 +#Fri Sep 16 08:12:41 CEST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library/build.gradle b/library/build.gradle index 6f6fdcc1..8daba518 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -6,7 +6,7 @@ buildscript { lombokVersion = "1.18.24" } dependencies { - classpath 'com.android.tools.build:gradle:7.1.3' + classpath 'com.android.tools.build:gradle:7.3.0' classpath 'com.hiya:jacoco-android:0.2' classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.12' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperation.kt b/library/src/main/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperation.kt index efe58be8..16b04dfe 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperation.kt +++ b/library/src/main/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperation.kt @@ -22,7 +22,6 @@ */ package com.nextcloud.android.lib.resources.search -import androidx.annotation.NonNull import com.google.gson.reflect.TypeToken import com.nextcloud.common.NextcloudClient import com.nextcloud.operations.GetMethod @@ -39,8 +38,8 @@ import java.net.URLEncoder */ @Suppress("TooGenericExceptionCaught") class UnifiedSearchRemoteOperation( - @NonNull val provider: String, - @NonNull val query: String, + val provider: String, + val query: String, val cursor: Int? = null, val limit: Int = 5 ) : diff --git a/library/src/main/java/com/nextcloud/common/OkHttpMethodBase.kt b/library/src/main/java/com/nextcloud/common/OkHttpMethodBase.kt index c55bfae5..05b71f34 100644 --- a/library/src/main/java/com/nextcloud/common/OkHttpMethodBase.kt +++ b/library/src/main/java/com/nextcloud/common/OkHttpMethodBase.kt @@ -55,7 +55,7 @@ abstract class OkHttpMethodBase( private val requestBuilder: Request.Builder = Request.Builder() private var request: Request? = null - fun OkHttpMethodBase() { + init { requestHeaders["http.protocol.single-cookie-header"] = "true" } diff --git a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java index e2e27093..bf725a5c 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java +++ b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java @@ -41,7 +41,7 @@ import java.io.IOException; /** * OwnCloud Account - * + * * @author David A. Velasco */ public class OwnCloudAccount implements Parcelable { @@ -56,7 +56,7 @@ public class OwnCloudAccount implements Parcelable { /** * Constructor for already saved OC accounts. - * + * <p> * Do not use for anonymous credentials. */ public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException { @@ -74,7 +74,7 @@ public class OwnCloudAccount implements Parcelable { AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseUrl = ama.getUserData(this.savedAccount, AccountUtils.Constants.KEY_OC_BASE_URL); - if (baseUrl == null ) { + if (baseUrl == null) { throw new AccountNotFoundException(this.savedAccount, "Account not found", null); } baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, this.savedAccount)); @@ -85,8 +85,8 @@ public class OwnCloudAccount implements Parcelable { /** * Constructor for non yet saved OC accounts. * - * @param baseUri URI to the OC server to get access to. - * @param credentials Credentials to authenticate in the server. NULL is valid for anonymous credentials. + * @param baseUri URI to the OC server to get access to. + * @param credentials Credentials to authenticate in the server. NULL is valid for anonymous credentials. */ public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) { if (baseUri == null) { @@ -113,16 +113,16 @@ public class OwnCloudAccount implements Parcelable { */ public void loadCredentials(Context context) throws AuthenticatorException, - IOException, OperationCanceledException { + IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } - if (savedAccount != null) { - credentials = AccountUtils.getCredentialsForAccount(context, savedAccount); - } - } + if (savedAccount != null) { + credentials = AccountUtils.getCredentialsForAccount(context, savedAccount); + } + } public String getDisplayName() { if (displayName != null && displayName.length() > 0) { diff --git a/library/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/library/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index 3962306b..8c94dbbf 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/library/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -1,23 +1,23 @@ /* ownCloud Android Library is available under MIT license * Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2012 Bartek Przybylski - * + * * 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, + * + * 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 + * 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. * @@ -44,46 +44,46 @@ import org.apache.commons.httpclient.Cookie; import java.io.IOException; public class AccountUtils { - - private static final String TAG = AccountUtils.class.getSimpleName(); - public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; + private static final String TAG = AccountUtils.class.getSimpleName(); + + public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String DAV_UPLOAD = "/remote.php/dav/uploads"; public static final String STATUS_PATH = "/status.php"; - + /** * Extracts url server from the account - * - * @deprecated This method will be removed in version 1.0. - * Use {@link #getBaseUrlForAccount(Context, Account)} - * instead. - * + * * @param context * @param account * @return url server or null on failure - * @throws AccountNotFoundException When 'account' is unknown for the AccountManager + * @throws AccountNotFoundException When 'account' is unknown for the AccountManager + * @deprecated This method will be removed in version 1.0. + * Use {@link #getBaseUrlForAccount(Context, Account)} + * instead. */ @Deprecated - public static String constructBasicURLForAccount(Context context, Account account) - throws AccountNotFoundException { - return getBaseUrlForAccount(context, account); + public static String constructBasicURLForAccount(Context context, Account account) + throws AccountNotFoundException { + return getBaseUrlForAccount(context, account); } /** * Extracts url server from the account + * * @param context * @param account * @return url server or null on failure - * @throws AccountNotFoundException When 'account' is unknown for the AccountManager + * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ - public static String getBaseUrlForAccount(Context context, Account account) - throws AccountNotFoundException { + public static String getBaseUrlForAccount(Context context, Account account) + throws AccountNotFoundException { AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); - - if (baseurl == null ) + + if (baseurl == null) throw new AccountNotFoundException(account, "Account not found", null); - + return baseurl; } @@ -91,8 +91,8 @@ public class AccountUtils { /** * Get the username corresponding to an OC account. * - * @param account An OC account - * @return Username for the given account, extracted from the account.name + * @param account An OC account + * @return Username for the given account, extracted from the account.name */ public static String getUsernameForAccount(Account account) { String username = null; @@ -104,54 +104,53 @@ public class AccountUtils { return username; } - /** - * Get the stored server version corresponding to an OC account. - * - * @param account An OC account - * @param context Application context - * @return Version of the OC server, according to last check - */ - public static OwnCloudVersion getServerVersionForAccount(Account account, Context context) { - AccountManager ama = AccountManager.get(context); - OwnCloudVersion version = null; - try { - String versionString = ama.getUserData(account, Constants.KEY_OC_VERSION); - version = new OwnCloudVersion(versionString); - - } catch (Exception e) { - Log_OC.e(TAG, "Couldn't get a the server version for an account", e); - } - return version; - } + /** + * Get the stored server version corresponding to an OC account. + * + * @param account An OC account + * @param context Application context + * @return Version of the OC server, according to last check + */ + public static OwnCloudVersion getServerVersionForAccount(Account account, Context context) { + AccountManager ama = AccountManager.get(context); + OwnCloudVersion version = null; + try { + String versionString = ama.getUserData(account, Constants.KEY_OC_VERSION); + version = new OwnCloudVersion(versionString); + + } catch (Exception e) { + Log_OC.e(TAG, "Couldn't get a the server version for an account", e); + } + return version; + } /** - * * @return - * @throws IOException - * @throws AuthenticatorException - * @throws OperationCanceledException + * @throws IOException + * @throws AuthenticatorException + * @throws OperationCanceledException */ - public static OwnCloudCredentials getCredentialsForAccount(Context context, Account account) - throws OperationCanceledException, AuthenticatorException, IOException { + public static OwnCloudCredentials getCredentialsForAccount(Context context, Account account) + throws OperationCanceledException, AuthenticatorException, IOException { - OwnCloudCredentials credentials; + OwnCloudCredentials credentials; AccountManager am = AccountManager.get(context); String username = AccountUtils.getUsernameForAccount(account); - String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), - false); + String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), + false); - credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password); + credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password); return credentials; - } + } + - public static String buildAccountNameOld(Uri serverBaseUrl, String username) { - if (serverBaseUrl.getScheme() == null) { - serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString()); - } + if (serverBaseUrl.getScheme() == null) { + serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString()); + } String accountName = username + "@" + serverBaseUrl.getHost(); if (serverBaseUrl.getPort() >= 0) { accountName += ":" + serverBaseUrl.getPort(); @@ -159,10 +158,10 @@ public class AccountUtils { return accountName; } - public static String buildAccountName(Uri serverBaseUrl, String loginName) { - if (serverBaseUrl.getScheme() == null) { - serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString()); - } + public static String buildAccountName(Uri serverBaseUrl, String loginName) { + if (serverBaseUrl.getScheme() == null) { + serverBaseUrl = Uri.parse("https://" + serverBaseUrl.toString()); + } // Remove http:// or https:// String url = serverBaseUrl.toString(); @@ -170,149 +169,153 @@ public class AccountUtils { url = url.substring(serverBaseUrl.toString().indexOf("://") + 3); } - return loginName + "@" + url; + return loginName + "@" + url; + } + + public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) { + + // Account Manager + AccountManager ac = AccountManager.get(context.getApplicationContext()); + + if (client != null) { + String cookiesString = client.getCookiesString(); + if (!"".equals(cookiesString)) { + ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString); + // Log_OC.d(TAG, "Saving Cookies: "+ cookiesString ); + } + } + + } + + + /** + * Restore the client cookies + * + * @param account + * @param client + * @param context + */ + public static void restoreCookies(Account account, OwnCloudClient client, Context context) { + + Log_OC.d(TAG, "Restoring cookies for " + account.name); + + // Account Manager + AccountManager am = AccountManager.get(context.getApplicationContext()); + + Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getDavUri(); + + String cookiesString = null; + try { + cookiesString = am.getUserData(account, Constants.KEY_COOKIES); + } catch (SecurityException e) { + Log_OC.e(TAG, e.getMessage()); + } + + if (cookiesString != null) { + String[] cookies = cookiesString.split(";"); + if (cookies.length > 0) { + for (int i = 0; i < cookies.length; i++) { + Cookie cookie = new Cookie(); + int equalPos = cookies[i].indexOf('='); + cookie.setName(cookies[i].substring(0, equalPos)); + cookie.setValue(cookies[i].substring(equalPos + 1)); + cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT + cookie.setPath(serverUri.getPath()); // VERY IMPORTANT + + client.getState().addCookie(cookie); + } + } + } + } + + /** + * Restore the client cookies from accountName + * + * @param accountName + * @param client + * @param context + */ + public static void restoreCookies(String accountName, OwnCloudClient client, Context context) { + Log_OC.d(TAG, "Restoring cookies for " + accountName); + + // Account Manager + AccountManager am = AccountManager.get(context.getApplicationContext()); + + // Get account + Account account = null; + Account accounts[] = am.getAccounts(); + for (Account a : accounts) { + if (a.name.equals(accountName)) { + account = a; + break; + } + } + + // Restoring cookies + if (account != null) { + restoreCookies(account, client, context); + } } - public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) { - - // Account Manager - AccountManager ac = AccountManager.get(context.getApplicationContext()); - - if (client != null) { - String cookiesString = client.getCookiesString(); - if (!"".equals(cookiesString)) { - ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString); - // Log_OC.d(TAG, "Saving Cookies: "+ cookiesString ); - } - } - - } - - - /** - * Restore the client cookies - * @param account - * @param client - * @param context - */ - public static void restoreCookies(Account account, OwnCloudClient client, Context context) { - - Log_OC.d(TAG, "Restoring cookies for " + account.name); - - // Account Manager - AccountManager am = AccountManager.get(context.getApplicationContext()); - - Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getDavUri(); - - String cookiesString = null; - try { - cookiesString = am.getUserData(account, Constants.KEY_COOKIES); - } catch (SecurityException e) { - Log_OC.e(TAG, e.getMessage()); - } - - if (cookiesString != null) { - String[] cookies = cookiesString.split(";"); - if (cookies.length > 0) { - for (int i=0; i< cookies.length; i++) { - Cookie cookie = new Cookie(); - int equalPos = cookies[i].indexOf('='); - cookie.setName(cookies[i].substring(0, equalPos)); - cookie.setValue(cookies[i].substring(equalPos + 1)); - cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT - cookie.setPath(serverUri.getPath()); // VERY IMPORTANT - - client.getState().addCookie(cookie); - } - } - } - } - - /** - * Restore the client cookies from accountName - * @param accountName - * @param client - * @param context - */ - public static void restoreCookies(String accountName, OwnCloudClient client, Context context) { - Log_OC.d(TAG, "Restoring cookies for " + accountName); - - // Account Manager - AccountManager am = AccountManager.get(context.getApplicationContext()); - - // Get account - Account account = null; - Account accounts[] = am.getAccounts(); - for (Account a : accounts) { - if (a.name.equals(accountName)) { - account = a; - break; - } - } - - // Restoring cookies - if (account != null) { - restoreCookies(account, client, context); - } - } - public static class AccountNotFoundException extends AccountsException { - - /** Generated - should be refreshed every time the class changes!! */ - private static final long serialVersionUID = -1684392454798508693L; - - private Account mFailedAccount; - + + /** + * Generated - should be refreshed every time the class changes!! + */ + private static final long serialVersionUID = -1684392454798508693L; + + private Account mFailedAccount; + public AccountNotFoundException(Account failedAccount, String message, Throwable cause) { super(message, cause); mFailedAccount = failedAccount; } - + public Account getFailedAccount() { return mFailedAccount; } } - public static class Constants { - /** - * Value under this key should handle path to webdav php script. Will be - * removed and usage should be replaced by combining - * {@link com.owncloud.android.authentication.AuthenticatorActivity.KEY_OC_BASE_URL} and - * {@link com.owncloud.android.lib.resources.status.OwnCloudVersion} - * - * @deprecated - */ - public static final String KEY_OC_URL = "oc_url"; - /** - * Version should be 3 numbers separated by dot so it can be parsed by - * {@link com.owncloud.android.lib.resources.status.OwnCloudVersion} - */ - public static final String KEY_OC_VERSION = "oc_version"; - /** - * Base url should point to owncloud installation without trailing / ie: - * http://server/path or https://owncloud.server - */ - public static final String KEY_OC_BASE_URL = "oc_base_url"; - /** - * OC account cookies - */ - public static final String KEY_COOKIES = "oc_account_cookies"; + public static class Constants { + /** + * Value under this key should handle path to webdav php script. Will be + * removed and usage should be replaced by combining + * {@link com.owncloud.android.authentication.AuthenticatorActivity.KEY_OC_BASE_URL} and + * {@link com.owncloud.android.lib.resources.status.OwnCloudVersion} + * + * @deprecated + */ + public static final String KEY_OC_URL = "oc_url"; + /** + * Version should be 3 numbers separated by dot so it can be parsed by + * {@link com.owncloud.android.lib.resources.status.OwnCloudVersion} + */ + public static final String KEY_OC_VERSION = "oc_version"; + /** + * Base url should point to owncloud installation without trailing / ie: + * http://server/path or https://owncloud.server + */ + public static final String KEY_OC_BASE_URL = "oc_base_url"; + /** + * OC account cookies + */ + public static final String KEY_COOKIES = "oc_account_cookies"; /** * OC account version */ public static final String KEY_OC_ACCOUNT_VERSION = "oc_account_version"; - /** - * User's display name, name chosen by user, only displayed, no real usage - */ - public static final String KEY_DISPLAY_NAME = "oc_display_name"; + /** + * User's display name, name chosen by user, only displayed, no real usage + */ + public static final String KEY_DISPLAY_NAME = "oc_display_name"; - /** - * User ID, internally and never changing id of user, used by e.g. dav/trashbin/$userId/trash - */ - public static final String KEY_USER_ID = "oc_id"; - } + /** + * User ID, internally and never changing id of user, used by e.g. dav/trashbin/$userId/trash + */ + public static final String KEY_USER_ID = "oc_id"; + } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java index b8c52eae..fe87377f 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperation.java @@ -1,22 +1,22 @@ /* ownCloud Android Library is available under MIT license * Copyright (C) 2015 ownCloud Inc. - * + * * 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, + * + * 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 + * 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. * @@ -55,73 +55,73 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class UploadFileRemoteOperation extends RemoteOperation<String> { - private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; - private static final String IF_MATCH_HEADER = "If-Match"; - protected static final String RESULT_ETAG_HEADER = "etag"; - protected static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; - protected static final String OC_X_OC_CTIME_HEADER = "X-OC-Ctime"; - - protected String localPath; - protected String remotePath; - protected String mimeType; - private String lastModificationTimestamp; - protected Long creationTimestamp = null; - protected boolean disableRetries = false; - PutMethod putMethod = null; - private String requiredEtag = null; - String token = null; - - final AtomicBoolean cancellationRequested = new AtomicBoolean(false); - RemoteOperationResult.ResultCode cancellationReason = null; - final Set<OnDatatransferProgressListener> dataTransferListeners = new HashSet<>(); - - protected RequestEntity entity = null; - - @VisibleForTesting - public UploadFileRemoteOperation() { - // empty - } - - public UploadFileRemoteOperation(String localPath, - String remotePath, - String mimeType, - String requiredEtag, - String lastModificationTimestamp) { - this(localPath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, null); - } - - public UploadFileRemoteOperation(String localPath, - String remotePath, - String mimeType, - String requiredEtag, - String lastModificationTimestamp, - Long creationTimestamp, - boolean disableRetries) { - this(localPath, - remotePath, - mimeType, - requiredEtag, - lastModificationTimestamp, - creationTimestamp, - null, - disableRetries); - } - - public UploadFileRemoteOperation(String localPath, - String remotePath, - String mimeType, - String lastModificationTimestamp) { - this(localPath, remotePath, mimeType, lastModificationTimestamp, true); - } - - public UploadFileRemoteOperation(String localPath, - String remotePath, - String mimeType, - String lastModificationTimestamp, - boolean disableRetries) { - this.localPath = localPath; - this.remotePath = remotePath; - this.mimeType = mimeType; + private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; + private static final String IF_MATCH_HEADER = "If-Match"; + protected static final String RESULT_ETAG_HEADER = "etag"; + protected static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; + protected static final String OC_X_OC_CTIME_HEADER = "X-OC-Ctime"; + + protected String localPath; + protected String remotePath; + protected String mimeType; + private String lastModificationTimestamp; + protected Long creationTimestamp = null; + protected boolean disableRetries = false; + PutMethod putMethod = null; + private String requiredEtag = null; + String token = null; + + final AtomicBoolean cancellationRequested = new AtomicBoolean(false); + RemoteOperationResult.ResultCode cancellationReason = null; + final Set<OnDatatransferProgressListener> dataTransferListeners = new HashSet<>(); + + protected RequestEntity entity = null; + + @VisibleForTesting + public UploadFileRemoteOperation() { + // empty + } + + public UploadFileRemoteOperation(String localPath, + String remotePath, + String mimeType, + String requiredEtag, + String lastModificationTimestamp) { + this(localPath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, null); + } + + public UploadFileRemoteOperation(String localPath, + String remotePath, + String mimeType, + String requiredEtag, + String lastModificationTimestamp, + Long creationTimestamp, + boolean disableRetries) { + this(localPath, + remotePath, + mimeType, + requiredEtag, + lastModificationTimestamp, + creationTimestamp, + null, + disableRetries); + } + + public UploadFileRemoteOperation(String localPath, + String remotePath, + String mimeType, + String lastModificationTimestamp) { + this(localPath, remotePath, mimeType, lastModificationTimestamp, true); + } + + public UploadFileRemoteOperation(String localPath, + String remotePath, + String mimeType, + String lastModificationTimestamp, + boolean disableRetries) { + this.localPath = localPath; + this.remotePath = remotePath; + this.mimeType = mimeType; if (lastModificationTimestamp == null) { throw new AssertionError("LastModificationTimestamp may NOT be null!"); @@ -129,9 +129,9 @@ public class UploadFileRemoteOperation extends RemoteOperation<String> { // TODO check for max value of lastModificationTimestamp - this.lastModificationTimestamp = lastModificationTimestamp; + this.lastModificationTimestamp = lastModificationTimestamp; this.disableRetries = disableRetries; - } + } public UploadFileRemoteOperation(String localPath, String remotePath, @@ -139,118 +139,118 @@ public class UploadFileRemoteOperation extends RemoteOperation<String> { String requiredEtag, String lastModificationTimestamp, String token) { - this(localPath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, null, token, true); - } - - public UploadFileRemoteOperation(String localPath, - String remotePath, - String mimeType, - String requiredEtag, - String lastModificationTimestamp, - Long creationTimestamp, - String token, - boolean disableRetries) { - this(localPath, remotePath, mimeType, lastModificationTimestamp, disableRetries); - this.requiredEtag = requiredEtag; - this.token = token; - this.creationTimestamp = creationTimestamp; - } - - @Override - protected RemoteOperationResult<String> run(OwnCloudClient client) { - RemoteOperationResult<String> result; - DefaultHttpMethodRetryHandler oldRetryHandler = - (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); - - try { - if (disableRetries) { - // prevent that uploads are retried automatically by network library - DefaultHttpMethodRetryHandler noRetryHandler = new DefaultHttpMethodRetryHandler(0, false); - client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, noRetryHandler); - } - - putMethod = new PutMethod(client.getFilesDavUri(remotePath)); - - if (token != null) { - putMethod.addRequestHeader(E2E_TOKEN, token); - } - - if (cancellationRequested.get()) { - // the operation was cancelled before getting it's turn to be executed in the queue of uploads - result = new RemoteOperationResult<>(new OperationCancelledException()); - - } else { - // perform the upload - result = uploadFile(client); - } - - } catch (Exception e) { - if (putMethod != null && putMethod.isAborted()) { + this(localPath, remotePath, mimeType, requiredEtag, lastModificationTimestamp, null, token, true); + } + + public UploadFileRemoteOperation(String localPath, + String remotePath, + String mimeType, + String requiredEtag, + String lastModificationTimestamp, + Long creationTimestamp, + String token, + boolean disableRetries) { + this(localPath, remotePath, mimeType, lastModificationTimestamp, disableRetries); + this.requiredEtag = requiredEtag; + this.token = token; + this.creationTimestamp = creationTimestamp; + } + + @Override + protected RemoteOperationResult<String> run(OwnCloudClient client) { + RemoteOperationResult<String> result; + DefaultHttpMethodRetryHandler oldRetryHandler = + (DefaultHttpMethodRetryHandler) client.getParams().getParameter(HttpMethodParams.RETRY_HANDLER); + + try { + if (disableRetries) { + // prevent that uploads are retried automatically by network library + DefaultHttpMethodRetryHandler noRetryHandler = new DefaultHttpMethodRetryHandler(0, false); + client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, noRetryHandler); + } + + putMethod = new PutMethod(client.getFilesDavUri(remotePath)); + + if (token != null) { + putMethod.addRequestHeader(E2E_TOKEN, token); + } + + if (cancellationRequested.get()) { + // the operation was cancelled before getting it's turn to be executed in the queue of uploads + result = new RemoteOperationResult<>(new OperationCancelledException()); + + } else { + // perform the upload + result = uploadFile(client); + } + + } catch (Exception e) { + if (putMethod != null && putMethod.isAborted()) { if (cancellationRequested.get() && cancellationReason != null) { result = new RemoteOperationResult<>(cancellationReason); } else { result = new RemoteOperationResult<>(new OperationCancelledException()); } - } else { - result = new RemoteOperationResult<>(e); - } - } finally { - if (disableRetries) { - // reset previous retry handler - client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, oldRetryHandler); - } - } - return result; - } - - public boolean isSuccess(int status) { - return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || + } else { + result = new RemoteOperationResult<>(e); + } + } finally { + if (disableRetries) { + // reset previous retry handler + client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, oldRetryHandler); + } + } + return result; + } + + public boolean isSuccess(int status) { + return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT)); - } - - protected RemoteOperationResult<String> uploadFile(OwnCloudClient client) throws IOException { - int status; - RemoteOperationResult<String> result; - - try { - File f = new File(localPath); - entity = new FileRequestEntity(f, mimeType); - synchronized (dataTransferListeners) { - ((ProgressiveDataTransfer) entity) - .addDataTransferProgressListeners(dataTransferListeners); - } - if (requiredEtag != null && requiredEtag.length() > 0) { - putMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + requiredEtag + "\""); - } - putMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); - putMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, lastModificationTimestamp); - - if (creationTimestamp != null && creationTimestamp > 0) { - putMethod.addRequestHeader(OC_X_OC_CTIME_HEADER, String.valueOf(creationTimestamp)); - } - - putMethod.setRequestEntity(entity); - status = client.executeMethod(putMethod); - - result = new RemoteOperationResult<>(isSuccess(status), putMethod); - - final Header resultEtagHeader = putMethod.getResponseHeader(RESULT_ETAG_HEADER); - if (resultEtagHeader != null) { - result.setResultData(resultEtagHeader.getValue().replace("\"", "")); - } - - client.exhaustResponse(putMethod.getResponseBodyAsStream()); - - } finally { - putMethod.releaseConnection(); // let the connection available for other methods - } - return result; - } + } + + protected RemoteOperationResult<String> uploadFile(OwnCloudClient client) throws IOException { + int status; + RemoteOperationResult<String> result; + + try { + File f = new File(localPath); + entity = new FileRequestEntity(f, mimeType); + synchronized (dataTransferListeners) { + ((ProgressiveDataTransfer) entity) + .addDataTransferProgressListeners(dataTransferListeners); + } + if (requiredEtag != null && requiredEtag.length() > 0) { + putMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + requiredEtag + "\""); + } + putMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); + putMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, lastModificationTimestamp); + + if (creationTimestamp != null && creationTimestamp > 0) { + putMethod.addRequestHeader(OC_X_OC_CTIME_HEADER, String.valueOf(creationTimestamp)); + } + + putMethod.setRequestEntity(entity); + status = client.executeMethod(putMethod); + + result = new RemoteOperationResult<>(isSuccess(status), putMethod); + + final Header resultEtagHeader = putMethod.getResponseHeader(RESULT_ETAG_HEADER); + if (resultEtagHeader != null) { + result.setResultData(resultEtagHeader.getValue().replace("\"", "")); + } + + client.exhaustResponse(putMethod.getResponseBodyAsStream()); + + } finally { + putMethod.releaseConnection(); // let the connection available for other methods + } + return result; + } public Set<OnDatatransferProgressListener> getDataTransferListeners() { return dataTransferListeners; } - + public void addDataTransferProgressListener(OnDatatransferProgressListener listener) { synchronized (dataTransferListeners) { dataTransferListeners.add(listener); @@ -259,7 +259,7 @@ public class UploadFileRemoteOperation extends RemoteOperation<String> { ((ProgressiveDataTransfer) entity).addDataTransferProgressListener(listener); } } - + public void removeDataTransferProgressListener(OnDatatransferProgressListener listener) { synchronized (dataTransferListeners) { dataTransferListeners.remove(listener); @@ -273,13 +273,13 @@ public class UploadFileRemoteOperation extends RemoteOperation<String> { synchronized (cancellationRequested) { cancellationRequested.set(true); - if (cancellationReason != null) { - this.cancellationReason = cancellationReason; - } + if (cancellationReason != null) { + this.cancellationReason = cancellationReason; + } - if (putMethod != null) { - putMethod.abort(); - } - } - } + if (putMethod != null) { + putMethod.abort(); + } + } + } } diff --git a/sample_client/build.gradle b/sample_client/build.gradle index bdce1a90..6ed6c040 100644 --- a/sample_client/build.gradle +++ b/sample_client/build.gradle @@ -1,6 +1,6 @@ buildscript { dependencies { - classpath 'com.android.tools.build:gradle:7.1.3' + classpath 'com.android.tools.build:gradle:7.3.0' classpath 'com.hiya:jacoco-android:0.2' classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.12' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |