From 7613e50d481f2b68ec2309b45f4c7b4d910087f6 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 27 Nov 2024 09:51:09 +0100 Subject: [PATCH 1/9] Inject session time out to the constructors Signed-off-by: alperozturk --- .../GenerateAppPasswordRemoteOperation.java | 17 ++++++-- ...WorkspaceDirectEditingRemoteOperation.java | 19 ++++++--- .../com/nextcloud/common/SessionTimeOut.kt | 12 ++++++ .../e2ee/GetMetadataRemoteOperation.java | 17 +++++--- .../e2ee/LockFileRemoteOperation.java | 21 ++++++++-- .../e2ee/StoreMetadataRemoteOperation.java | 21 +++++++--- .../e2ee/StoreMetadataV2RemoteOperation.kt | 9 +++-- .../e2ee/ToggleEncryptionRemoteOperation.java | 16 ++++++-- .../e2ee/UnlockFileRemoteOperation.java | 15 +++++-- .../e2ee/UnlockFileV1RemoteOperation.kt | 13 +++--- .../e2ee/UpdateMetadataRemoteOperation.java | 22 +++++++--- .../e2ee/UpdateMetadataV2RemoteOperation.kt | 9 +++-- .../files/CheckEtagRemoteOperation.java | 22 ++++++---- .../files/CopyFileRemoteOperation.java | 38 +++++++++++------- .../files/CreateFolderRemoteOperation.java | 28 +++++++++---- .../files/MoveFileRemoteOperation.java | 40 ++++++++++--------- .../files/ReadFileRemoteOperation.java | 23 ++++++----- .../files/RemoveFileRemoteOperation.java | 21 ++++++---- .../files/RenameFileRemoteOperation.java | 31 ++++++++------ .../RestoreFileVersionRemoteOperation.java | 18 ++++++--- .../RemoveTrashbinFileRemoteOperation.java | 20 ++++++---- .../RestoreTrashbinFileRemoteOperation.java | 22 ++++++---- .../users/CheckRemoteWipeRemoteOperation.java | 23 +++++++---- .../RemoteWipeSuccessRemoteOperation.java | 21 ++++++---- 24 files changed, 336 insertions(+), 162 deletions(-) create mode 100644 library/src/main/java/com/nextcloud/common/SessionTimeOut.kt diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java index 39648d8d2..f4ad29df9 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java @@ -7,6 +7,9 @@ */ package com.nextcloud.android.lib.resources.users; + +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; @@ -23,8 +26,6 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { private static final String TAG = GenerateAppPasswordRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String DIRECT_ENDPOINT = "/ocs/v2.php/core/getapppassword"; // JSON node names @@ -32,6 +33,16 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { private static final String NODE_DATA = "data"; private static final String NODE_APPPASSWORD = "apppassword"; + private final SessionTimeOut sessionTimeOut; + + public GenerateAppPasswordRemoteOperation() { + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public GenerateAppPasswordRemoteOperation(SessionTimeOut sessionTimeOut) { + this.sessionTimeOut = sessionTimeOut; + } + protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; GetMethod getMethod = null; @@ -42,7 +53,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { // remote request getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(getMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); diff --git a/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java index d798d0f22..4f3daba65 100644 --- a/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java @@ -8,6 +8,8 @@ package com.nextcloud.android.lib.richWorkspace; import com.google.gson.GsonBuilder; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -27,15 +29,20 @@ public class RichWorkspaceDirectEditingRemoteOperation extends RemoteOperation { private static final String TAG = RichWorkspaceDirectEditingRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String DIRECT_ENDPOINT = "/ocs/v2.php/apps/text/workspace/direct"; private static final String PATH = "path"; + private final SessionTimeOut sessionTimeOut; private String path; public RichWorkspaceDirectEditingRemoteOperation(String path) { this.path = path; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public RichWorkspaceDirectEditingRemoteOperation(String path, SessionTimeOut sessionTimeOut) { + this.path = path; + this.sessionTimeOut = sessionTimeOut; } protected RemoteOperationResult run(OwnCloudClient client) { @@ -54,7 +61,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { postMethod.setRequestEntity(new StringRequestEntity(json)); - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(postMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); @@ -63,14 +70,14 @@ protected RemoteOperationResult run(OwnCloudClient client) { JSONObject respJSON = new JSONObject(response); String url = (String) respJSON.getJSONObject("ocs").getJSONObject("data").get("url"); - result = new RemoteOperationResult(true, postMethod); + result = new RemoteOperationResult<>(true, postMethod); result.setSingleData(url); } else { - result = new RemoteOperationResult(false, postMethod); + result = new RemoteOperationResult<>(false, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Get edit url for rich workspace failed: " + result.getLogMessage(), result.getException()); } finally { diff --git a/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt b/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt new file mode 100644 index 000000000..de4239e4a --- /dev/null +++ b/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt @@ -0,0 +1,12 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.nextcloud.common + +data class SessionTimeOut(val readTimeOut: Int, val connectionTimeOut: Int) + +val defaultSessionTimeOut = SessionTimeOut(40000, 5000) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java index 2d666baa3..e5e8286b7 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -25,8 +27,6 @@ public class GetMetadataRemoteOperation extends RemoteOperation { private static final String TAG = GetMetadataRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String METADATA_V1_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"; private static final String METADATA_V2_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/"; @@ -38,11 +38,19 @@ public class GetMetadataRemoteOperation extends RemoteOperation run(OwnCloudClient client) { getMethod = new GetMethod(client.getBaseUri() + METADATA_V2_URL + fileId + JSON_FORMAT); getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(getMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { // retry with v1 getMethod = new GetMethod(client.getBaseUri() + METADATA_V1_URL + fileId + JSON_FORMAT); getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + status = client.executeMethod(getMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); } if (status == HttpStatus.SC_OK) { @@ -102,5 +110,4 @@ protected RemoteOperationResult run(OwnCloudClient client) { } return result; } - } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java index 27a265f7e..1c94095a5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -23,8 +25,6 @@ public class LockFileRemoteOperation extends RemoteOperation { private static final String TAG = LockFileRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/"; private static final String COUNTER_HEADER = "X-NC-E2EE-COUNTER"; @@ -36,16 +36,31 @@ public class LockFileRemoteOperation extends RemoteOperation { private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; + private final SessionTimeOut sessionTimeOut; + /** * Constructor */ public LockFileRemoteOperation(long localId, long counter) { this.localId = localId; this.counter = counter; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public LockFileRemoteOperation(long localId) { this.localId = localId; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public LockFileRemoteOperation(long localId, long counter, SessionTimeOut sessionTimeOut) { + this.localId = localId; + this.counter = counter; + this.sessionTimeOut = sessionTimeOut; + } + + public LockFileRemoteOperation(long localId, SessionTimeOut sessionTimeOut) { + this.localId = localId; + this.sessionTimeOut = sessionTimeOut; } /** @@ -67,7 +82,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { postMethod.addRequestHeader(COUNTER_HEADER, String.valueOf(counter)); } - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(postMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java index 1c95b95d4..7b52356ff 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -26,8 +28,6 @@ public class StoreMetadataRemoteOperation extends RemoteOperation { private static final String TAG = StoreMetadataRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"; private static final String METADATA = "metaData"; @@ -39,12 +39,21 @@ public class StoreMetadataRemoteOperation extends RemoteOperation { private final long fileId; private final String encryptedMetadataJson; + private final SessionTimeOut sessionTimeOut; + /** * Constructor */ public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson) { this.fileId = fileId; this.encryptedMetadataJson = encryptedMetadataJson; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson, SessionTimeOut sessionTimeOut) { + this.fileId = fileId; + this.encryptedMetadataJson = encryptedMetadataJson; + this.sessionTimeOut = sessionTimeOut; } /** @@ -61,7 +70,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); postMethod.setParameter(METADATA, encryptedMetadataJson); - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(postMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); @@ -71,16 +80,16 @@ protected RemoteOperationResult run(OwnCloudClient client) { String metadata = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_META_DATA); - result = new RemoteOperationResult(true, postMethod); + result = new RemoteOperationResult<>(true, postMethod); ArrayList keys = new ArrayList<>(); keys.add(metadata); result.setData(keys); } else { - result = new RemoteOperationResult(false, postMethod); + result = new RemoteOperationResult<>(false, postMethod); client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Storing of metadata for folder " + fileId + " failed: " + result.getLogMessage(), result.getException()); } finally { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt index 85be51a80..9d80df17a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt @@ -8,6 +8,8 @@ package com.owncloud.android.lib.resources.e2ee import android.util.Log +import com.nextcloud.common.SessionTimeOut +import com.nextcloud.common.defaultSessionTimeOut import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult @@ -23,7 +25,8 @@ class StoreMetadataV2RemoteOperation( private val remoteId: String, private val encryptedMetadataJson: String, private val token: String, - private val signature: String + private val signature: String, + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { /** * @param client Client object @@ -40,7 +43,7 @@ class StoreMetadataV2RemoteOperation( postMethod.addRequestHeader(E2E_TOKEN, token) postMethod.addRequestHeader(HEADER_SIGNATURE, signature) postMethod.setParameter(METADATA, encryptedMetadataJson) - val status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT) + val status = client.executeMethod(postMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) if (status == HttpStatus.SC_OK) { val response = postMethod.responseBodyAsString @@ -77,8 +80,6 @@ class StoreMetadataV2RemoteOperation( companion object { private val TAG = StoreMetadataV2RemoteOperation::class.java.simpleName - private const val SYNC_READ_TIMEOUT = 40000 - private const val SYNC_CONNECTION_TIMEOUT = 5000 private const val METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" private const val METADATA = "metaData" private const val HEADER_SIGNATURE = "X-NC-E2EE-SIGNATURE" diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java index d6720a75f..02453450d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -26,14 +28,14 @@ public class ToggleEncryptionRemoteOperation extends RemoteOperation { private static final String TAG = ToggleEncryptionRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String ENCRYPTED_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/encrypted/"; private final long localId; private final String remotePath; private final boolean encryption; + private final SessionTimeOut sessionTimeOut; + /** * Constructor */ @@ -41,6 +43,14 @@ public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean this.localId = localId; this.remotePath = remotePath; this.encryption = encryption; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean encryption, SessionTimeOut sessionTimeOut) { + this.localId = localId; + this.remotePath = remotePath; + this.encryption = encryption; + this.sessionTimeOut = sessionTimeOut; } /** @@ -72,7 +82,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { method.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); method.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); - int status = client.executeMethod(method, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(method, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_OK) { result = new RemoteOperationResult<>(true, method); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java index db110881e..5d8b99405 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -22,19 +24,26 @@ public class UnlockFileRemoteOperation extends RemoteOperation { private static final String TAG = UnlockFileRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/lock/"; private final long localId; private final String token; + private final SessionTimeOut sessionTimeOut; + /** * Constructor */ public UnlockFileRemoteOperation(long localId, String token) { this.localId = localId; this.token = token; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public UnlockFileRemoteOperation(long localId, String token, SessionTimeOut sessionTimeOut) { + this.localId = localId; + this.token = token; + this.sessionTimeOut = sessionTimeOut; } /** @@ -52,7 +61,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); deleteMethod.addRequestHeader(E2E_TOKEN, token); - int status = client.executeMethod(deleteMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(deleteMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); result = new RemoteOperationResult<>(status == HttpStatus.SC_OK, deleteMethod); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt index c13e24694..b986718f0 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee +import com.nextcloud.common.SessionTimeOut +import com.nextcloud.common.defaultSessionTimeOut import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult @@ -19,11 +21,10 @@ import org.apache.commons.httpclient.methods.DeleteMethod */ class UnlockFileV1RemoteOperation( private val localId: Long, - private val token: String + private val token: String, + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { - /** - * @param client Client object - */ + @Deprecated("Deprecated in Java") @Suppress("Detekt.TooGenericExceptionCaught") override fun run(client: OwnCloudClient): RemoteOperationResult { @@ -36,7 +37,7 @@ class UnlockFileV1RemoteOperation( deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED) deleteMethod.addRequestHeader(E2E_TOKEN, token) val status = - client.executeMethod(deleteMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT) + client.executeMethod(deleteMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) result = RemoteOperationResult(status == HttpStatus.SC_OK, deleteMethod) client.exhaustResponse(deleteMethod.responseBodyAsStream) } catch (e: Exception) { @@ -54,8 +55,6 @@ class UnlockFileV1RemoteOperation( companion object { private val TAG = UnlockFileV1RemoteOperation::class.java.simpleName - private const val SYNC_READ_TIMEOUT = 40000 - private const val SYNC_CONNECTION_TIMEOUT = 5000 private const val LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/" } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java index 0ebe60f01..6d20dab92 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.e2ee; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -29,8 +31,6 @@ public class UpdateMetadataRemoteOperation extends RemoteOperation { private static final String TAG = UpdateMetadataRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"; private static final String FORMAT = "format"; @@ -43,6 +43,8 @@ public class UpdateMetadataRemoteOperation extends RemoteOperation { private final String encryptedMetadataJson; private final String token; + private final SessionTimeOut sessionTimeOut; + /** * Constructor */ @@ -50,6 +52,14 @@ public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, this.fileId = fileId; this.encryptedMetadataJson = URLEncoder.encode(encryptedMetadataJson); this.token = token; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, String token, SessionTimeOut sessionTimeOut) { + this.fileId = fileId; + this.encryptedMetadataJson = URLEncoder.encode(encryptedMetadataJson); + this.token = token; + this.sessionTimeOut = sessionTimeOut; } /** @@ -75,7 +85,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { "application/json", "UTF-8"); putMethod.setRequestEntity(data); - int status = client.executeMethod(putMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(putMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_OK) { String response = putMethod.getResponseBodyAsString(); @@ -85,16 +95,16 @@ protected RemoteOperationResult run(OwnCloudClient client) { String metadata = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA) .get(NODE_META_DATA); - result = new RemoteOperationResult(true, putMethod); + result = new RemoteOperationResult<>(true, putMethod); ArrayList keys = new ArrayList<>(); keys.add(metadata); result.setData(keys); } else { - result = new RemoteOperationResult(false, putMethod); + result = new RemoteOperationResult<>(false, putMethod); client.exhaustResponse(putMethod.getResponseBodyAsStream()); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Storing of metadata for folder " + fileId + " failed: " + result.getLogMessage(), result.getException()); } finally { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt index c8d6e5b14..d74144c2e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt @@ -8,6 +8,8 @@ package com.owncloud.android.lib.resources.e2ee import android.util.Log +import com.nextcloud.common.SessionTimeOut +import com.nextcloud.common.defaultSessionTimeOut import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult @@ -25,7 +27,8 @@ class UpdateMetadataV2RemoteOperation( private val remoteId: String, encryptedMetadataJson: String, private val token: String, - private val signature: String + private val signature: String, + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { private val encryptedMetadataJson: String @@ -62,7 +65,7 @@ class UpdateMetadataV2RemoteOperation( "UTF-8" ) putMethod.requestEntity = data - val status = client.executeMethod(putMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT) + val status = client.executeMethod(putMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) if (status == HttpStatus.SC_OK) { val response = putMethod.responseBodyAsString @@ -99,8 +102,6 @@ class UpdateMetadataV2RemoteOperation( companion object { private val TAG = UpdateMetadataV2RemoteOperation::class.java.simpleName - private const val SYNC_READ_TIMEOUT = 40000 - private const val SYNC_CONNECTION_TIMEOUT = 5000 private const val METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" private const val FORMAT = "format" diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java index 51f9dd33d..3e839cb80 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.files; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -29,18 +31,24 @@ */ public class CheckEtagRemoteOperation extends RemoteOperation { - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String TAG = CheckEtagRemoteOperation.class.getSimpleName(); private String path; private String expectedEtag; + private final SessionTimeOut sessionTimeOut; + public CheckEtagRemoteOperation(String path, String expectedEtag) { this.path = path; this.expectedEtag = expectedEtag; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } + public CheckEtagRemoteOperation(String path, String expectedEtag, SessionTimeOut sessionTimeOut) { + this.path = path; + this.expectedEtag = expectedEtag; + this.sessionTimeOut = sessionTimeOut; + } @Override protected RemoteOperationResult run(OwnCloudClient client) { @@ -53,7 +61,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { propfind = new PropFindMethod(client.getFilesDavUri(path), propSet, 0); - int status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(propfind, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK) { MultiStatusResponse resp = propfind.getResponseBodyAsMultiStatus().getResponses()[0]; @@ -62,9 +70,9 @@ protected RemoteOperationResult run(OwnCloudClient client) { .get(DavPropertyName.GETETAG).getValue()); if (etag.equals(expectedEtag)) { - return new RemoteOperationResult(ResultCode.ETAG_UNCHANGED); + return new RemoteOperationResult<>(ResultCode.ETAG_UNCHANGED); } else { - RemoteOperationResult result = new RemoteOperationResult(ResultCode.ETAG_CHANGED); + final var result = new RemoteOperationResult<>(ResultCode.ETAG_CHANGED); ArrayList list = new ArrayList<>(); list.add(etag); @@ -75,7 +83,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { } if (status == HttpStatus.SC_NOT_FOUND) { - return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND); + return new RemoteOperationResult<>(ResultCode.FILE_NOT_FOUND); } } catch (DavException | IOException e) { Log_OC.e(TAG, "Error while retrieving eTag"); @@ -85,6 +93,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { } } - return new RemoteOperationResult(ResultCode.ETAG_CHANGED); + return new RemoteOperationResult<>(ResultCode.ETAG_CHANGED); } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java index 3bec3c96a..043b0fb0f 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java @@ -8,6 +8,7 @@ import android.util.Log; +import com.nextcloud.common.SessionTimeOut; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -34,13 +35,13 @@ public class CopyFileRemoteOperation extends RemoteOperation { private static final String TAG = CopyFileRemoteOperation.class.getSimpleName(); - private static final int COPY_READ_TIMEOUT = 600000; - private static final int COPY_CONNECTION_TIMEOUT = 5000; - private String mSrcRemotePath; - private String mTargetRemotePath; + private final String mSrcRemotePath; + private final String mTargetRemotePath; - private boolean mOverwrite; + private final boolean mOverwrite; + + private final SessionTimeOut sessionTimeOut; /** @@ -51,14 +52,21 @@ public class CopyFileRemoteOperation extends RemoteOperation { * @param srcRemotePath Remote path of the file/folder to move. * @param targetRemotePath Remove path desired for the file/folder after moving it. */ - public CopyFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite - ) { + public CopyFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) { mSrcRemotePath = srcRemotePath; mTargetRemotePath = targetRemotePath; mOverwrite = overwrite; + this.sessionTimeOut = new SessionTimeOut(600000, 5000); } + public CopyFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite, SessionTimeOut sessionTimeOut) { + mSrcRemotePath = srcRemotePath; + mTargetRemotePath = targetRemotePath; + mOverwrite = overwrite; + this.sessionTimeOut = sessionTimeOut; + } + /** * Performs the rename operation. * @@ -70,11 +78,11 @@ protected RemoteOperationResult run(OwnCloudClient client) { /// check parameters if (mTargetRemotePath.equals(mSrcRemotePath)) { // nothing to do! - return new RemoteOperationResult(ResultCode.OK); + return new RemoteOperationResult<>(ResultCode.OK); } if (mTargetRemotePath.startsWith(mSrcRemotePath)) { - return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT); + return new RemoteOperationResult<>(ResultCode.INVALID_COPY_INTO_DESCENDANT); } /// perform remote operation @@ -86,7 +94,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { client.getFilesDavUri(mTargetRemotePath), mOverwrite ); - int status = client.executeMethod(copyMethod, COPY_READ_TIMEOUT, COPY_CONNECTION_TIMEOUT); + int status = client.executeMethod(copyMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); /// process response if (status == HttpStatus.SC_MULTI_STATUS) { @@ -94,7 +102,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { } else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { - result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); + result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); client.exhaustResponse(copyMethod.getResponseBodyAsStream()); @@ -102,14 +110,14 @@ protected RemoteOperationResult run(OwnCloudClient client) { /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 } else { - result = new RemoteOperationResult(isSuccess(status), copyMethod); + result = new RemoteOperationResult<>(isSuccess(status), copyMethod); client.exhaustResponse(copyMethod.getResponseBodyAsStream()); } Log.i(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + result.getLogMessage()); } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log.e(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + result.getLogMessage(), e); } finally { @@ -158,9 +166,9 @@ private RemoteOperationResult processPartialError(CopyMethod copyMethod) RemoteOperationResult result; if (failFound) { - result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE); + result = new RemoteOperationResult<>(ResultCode.PARTIAL_COPY_DONE); } else { - result = new RemoteOperationResult(true, copyMethod); + result = new RemoteOperationResult<>(true, copyMethod); } return result; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java index 328378d88..4fb2ff7e8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java @@ -8,6 +8,8 @@ import android.text.TextUtils; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -28,13 +30,11 @@ public class CreateFolderRemoteOperation extends RemoteOperation { private static final String TAG = CreateFolderRemoteOperation.class.getSimpleName(); - private static final int READ_TIMEOUT = 30000; - private static final int CONNECTION_TIMEOUT = 5000; - - private boolean createFullPath; - private String remotePath; + private final boolean createFullPath; + private final String remotePath; private String token; + private final SessionTimeOut sessionTimeOut; /** * Constructor @@ -46,6 +46,7 @@ public class CreateFolderRemoteOperation extends RemoteOperation { public CreateFolderRemoteOperation(String remotePath, boolean createFullPath) { this.remotePath = remotePath; this.createFullPath = createFullPath; + this.sessionTimeOut = new SessionTimeOut(30000, 5000); } public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, String token) { @@ -53,6 +54,19 @@ public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, St this.token = token; } + public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, SessionTimeOut sessionTimeOut) { + this.remotePath = remotePath; + this.createFullPath = createFullPath; + this.sessionTimeOut = sessionTimeOut; + } + + public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, String token, SessionTimeOut sessionTimeOut) { + this.remotePath = remotePath; + this.createFullPath = createFullPath; + this.token = token; + this.sessionTimeOut = sessionTimeOut; + } + /** * Performs the operation * @@ -86,7 +100,7 @@ private RemoteOperationResult createFolder(OwnCloudClient client) { mkCol.addRequestHeader(E2E_TOKEN, token); } - client.executeMethod(mkCol, READ_TIMEOUT, CONNECTION_TIMEOUT); + client.executeMethod(mkCol, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (HttpStatus.SC_METHOD_NOT_ALLOWED == mkCol.getStatusCode()) { result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS); @@ -120,6 +134,4 @@ private RemoteOperationResult createParentFolder(String parentPath, OwnC RemoteOperation operation = new CreateFolderRemoteOperation(parentPath, createFullPath); return operation.execute(client); } - - } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java index 4ca495a4a..d53a5a101 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java @@ -8,6 +8,8 @@ import android.util.Log; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -33,13 +35,11 @@ public class MoveFileRemoteOperation extends RemoteOperation { private static final String TAG = MoveFileRemoteOperation.class.getSimpleName(); - private static final int MOVE_READ_TIMEOUT = 600000; - private static final int MOVE_CONNECTION_TIMEOUT = 5000; + private final String mSrcRemotePath; + private final String mTargetRemotePath; + private final boolean mOverwrite; - private String mSrcRemotePath; - private String mTargetRemotePath; - - private boolean mOverwrite; + private final SessionTimeOut sessionTimeOut; /** @@ -50,13 +50,18 @@ public class MoveFileRemoteOperation extends RemoteOperation { * @param srcRemotePath Remote path of the file/folder to move. * @param targetRemotePath Remove path desired for the file/folder after moving it. */ - public MoveFileRemoteOperation( - String srcRemotePath, String targetRemotePath, boolean overwrite - ) { + public MoveFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) { + mSrcRemotePath = srcRemotePath; + mTargetRemotePath = targetRemotePath; + mOverwrite = overwrite; + sessionTimeOut = new SessionTimeOut(600000, 5000); + } + public MoveFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite, SessionTimeOut sessionTimeOut) { mSrcRemotePath = srcRemotePath; mTargetRemotePath = targetRemotePath; mOverwrite = overwrite; + this.sessionTimeOut = sessionTimeOut; } @@ -70,11 +75,11 @@ protected RemoteOperationResult run(OwnCloudClient client) { // check parameters if (mTargetRemotePath.equals(mSrcRemotePath)) { // nothing to do! - return new RemoteOperationResult(ResultCode.OK); + return new RemoteOperationResult<>(ResultCode.OK); } if (mTargetRemotePath.startsWith(mSrcRemotePath)) { - return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); + return new RemoteOperationResult<>(ResultCode.INVALID_MOVE_INTO_DESCENDANT); } @@ -87,7 +92,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { client.getFilesDavUri(mTargetRemotePath), mOverwrite ); - int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); + int status = client.executeMethod(move, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); /// process response if (status == HttpStatus.SC_MULTI_STATUS) { @@ -103,7 +108,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 } else { - result = new RemoteOperationResult(isSuccess(status), move); + result = new RemoteOperationResult<>(isSuccess(status), move); client.exhaustResponse(move.getResponseBodyAsStream()); } @@ -111,7 +116,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { result.getLogMessage()); } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + result.getLogMessage(), e); @@ -160,18 +165,15 @@ private RemoteOperationResult processPartialError(MoveMethod move) RemoteOperationResult result; if (failFound) { - result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); + result = new RemoteOperationResult<>(ResultCode.PARTIAL_MOVE_DONE); } else { - result = new RemoteOperationResult(true, move); + result = new RemoteOperationResult<>(true, move); } return result; - } - protected boolean isSuccess(int status) { return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT; } - } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java index bf350ac93..ec3cc460b 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java @@ -6,6 +6,8 @@ */ package com.owncloud.android.lib.resources.files; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavUtils; @@ -32,10 +34,8 @@ public class ReadFileRemoteOperation extends RemoteOperation { private static final String TAG = ReadFileRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; - - private String mRemotePath; + private final String mRemotePath; + private final SessionTimeOut sessionTimeOut; /** @@ -45,6 +45,12 @@ public class ReadFileRemoteOperation extends RemoteOperation { */ public ReadFileRemoteOperation(String remotePath) { mRemotePath = remotePath; + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public ReadFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { + mRemotePath = remotePath; + this.sessionTimeOut = sessionTimeOut; } /** @@ -64,7 +70,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { WebdavUtils.getFilePropSet(), // PropFind Properties DavConstants.DEPTH_0); int status; - status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + status = client.executeMethod(propfind, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); boolean isSuccess = ( status == HttpStatus.SC_MULTI_STATUS || @@ -80,16 +86,16 @@ protected RemoteOperationResult run(OwnCloudClient client) { files.add(remoteFile); // Result of the operation - result = new RemoteOperationResult(true, propfind); + result = new RemoteOperationResult<>(true, propfind); result.setData(files); } else { - result = new RemoteOperationResult(false, propfind); + result = new RemoteOperationResult<>(false, propfind); client.exhaustResponse(propfind.getResponseBodyAsStream()); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Read file " + mRemotePath + " failed: " + result.getLogMessage(), result.getException()); } finally { @@ -98,5 +104,4 @@ protected RemoteOperationResult run(OwnCloudClient client) { } return result; } - } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java index 42aaab3e7..0f1169273 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java @@ -6,6 +6,8 @@ */ package com.owncloud.android.lib.resources.files; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -23,10 +25,8 @@ public class RemoveFileRemoteOperation extends RemoteOperation { private static final String TAG = RemoveFileRemoteOperation.class.getSimpleName(); - private static final int REMOVE_READ_TIMEOUT = 30000; - private static final int REMOVE_CONNECTION_TIMEOUT = 5000; - - private String mRemotePath; + private final String mRemotePath; + private final SessionTimeOut sessionTimeOut; /** * Constructor @@ -35,6 +35,12 @@ public class RemoveFileRemoteOperation extends RemoteOperation { */ public RemoveFileRemoteOperation(String remotePath) { mRemotePath = remotePath; + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public RemoveFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { + mRemotePath = remotePath; + this.sessionTimeOut = sessionTimeOut; } /** @@ -49,17 +55,17 @@ protected RemoteOperationResult run(OwnCloudClient client) { try { delete = new DeleteMethod(client.getFilesDavUri(mRemotePath)); - int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); + int status = client.executeMethod(delete, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); delete.getResponseBodyAsString(); // exhaust the response, although not interesting - result = new RemoteOperationResult( + result = new RemoteOperationResult<>( (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), delete ); Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); } finally { @@ -69,5 +75,4 @@ protected RemoteOperationResult run(OwnCloudClient client) { return result; } - } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java index ec3300f0e..7975bcd6c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java @@ -6,6 +6,8 @@ */ package com.owncloud.android.lib.resources.files; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -27,14 +29,13 @@ public class RenameFileRemoteOperation extends RemoteOperation { private static final String TAG = RenameFileRemoteOperation.class.getSimpleName(); - private static final int RENAME_READ_TIMEOUT = 600000; - private static final int RENAME_CONNECTION_TIMEOUT = 5000; - private String mOldName; private String mOldRemotePath; private String mNewName; private String mNewRemotePath; + private final SessionTimeOut sessionTimeOut; + /** * Constructor @@ -44,19 +45,23 @@ public class RenameFileRemoteOperation extends RemoteOperation { * @param newName New name to set as the name of file. * @param isFolder 'true' for folder and 'false' for files */ - public RenameFileRemoteOperation(String oldName, String oldRemotePath, String newName, - boolean isFolder) { + public RenameFileRemoteOperation(String oldName, String oldRemotePath, String newName, boolean isFolder) { + this(oldName, oldRemotePath, newName, isFolder, new SessionTimeOut(600000, 5000)); + } + + public RenameFileRemoteOperation(String oldName, String oldRemotePath, String newName, boolean isFolder, SessionTimeOut sessionTimeOut) { mOldName = oldName; mOldRemotePath = oldRemotePath; mNewName = newName; String parent = (new File(mOldRemotePath)).getParent(); - parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + - FileUtils.PATH_SEPARATOR; + parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + FileUtils.PATH_SEPARATOR; mNewRemotePath = parent + mNewName; if (isFolder) { mNewRemotePath += FileUtils.PATH_SEPARATOR; } + + this.sessionTimeOut = sessionTimeOut; } /** @@ -71,27 +76,27 @@ protected RemoteOperationResult run(OwnCloudClient client) { MoveMethod move = null; try { if (mNewName.equals(mOldName)) { - return new RemoteOperationResult(ResultCode.OK); + return new RemoteOperationResult<>(ResultCode.OK); } // check if a file with the new name already exists - RemoteOperationResult existenceResult = new ExistenceCheckRemoteOperation(mNewRemotePath, false) + final var existenceResult = new ExistenceCheckRemoteOperation(mNewRemotePath, false) .execute(client); if (existenceResult.isSuccess()) { - return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); + return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); } move = new MoveMethod(client.getFilesDavUri(mOldRemotePath), client.getFilesDavUri(mNewRemotePath), true); - client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); - result = new RemoteOperationResult(move.succeeded(), move); + client.executeMethod(move, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); + result = new RemoteOperationResult<>(move.succeeded(), move); Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + result.getLogMessage() ); client.exhaustResponse(move.getResponseBodyAsStream()); } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + ((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " + result.getLogMessage(), e); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java index 1c283b956..7f22264d9 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java @@ -10,6 +10,8 @@ import android.net.Uri; import android.util.Log; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -27,11 +29,10 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation { private static final String TAG = RestoreFileVersionRemoteOperation.class.getSimpleName(); - private static final int RESTORE_READ_TIMEOUT = 30000; - private static final int RESTORE_CONNECTION_TIMEOUT = 5000; private final long fileId; private final String fileName; + private final SessionTimeOut sessionTimeOut; /** * Constructor @@ -42,6 +43,13 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation { public RestoreFileVersionRemoteOperation(long fileId, String fileName) { this.fileId = fileId; this.fileName = fileName; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public RestoreFileVersionRemoteOperation(long fileId, String fileName, SessionTimeOut sessionTimeOut) { + this.fileId = fileId; + this.fileName = fileName; + this.sessionTimeOut = sessionTimeOut; } /** @@ -60,13 +68,13 @@ protected RemoteOperationResult run(OwnCloudClient client) { String target = client.getDavUri() + "/versions/" + client.getUserId() + "/restore/" + fileId; move = new MoveMethod(source, target, true); - int status = client.executeMethod(move, RESTORE_READ_TIMEOUT, RESTORE_CONNECTION_TIMEOUT); + int status = client.executeMethod(move, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); - result = new RemoteOperationResult(isSuccess(status), move); + result = new RemoteOperationResult<>(isSuccess(status), move); client.exhaustResponse(move.getResponseBodyAsStream()); } catch (IOException e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log.e(TAG, "Restore file version with id " + fileId + " failed: " + result.getLogMessage(), e); } finally { if (move != null) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java index d6b325998..77811d3de 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.trashbin; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -22,10 +24,8 @@ public class RemoveTrashbinFileRemoteOperation extends RemoteOperation { private static final String TAG = RemoveTrashbinFileRemoteOperation.class.getSimpleName(); - private static final int REMOVE_READ_TIMEOUT = 30000; - private static final int REMOVE_CONNECTION_TIMEOUT = 5000; - - private String remotePath; + private final String remotePath; + private final SessionTimeOut sessionTimeOut; /** * Constructor @@ -34,6 +34,12 @@ public class RemoveTrashbinFileRemoteOperation extends RemoteOperation { */ public RemoveTrashbinFileRemoteOperation(String remotePath) { this.remotePath = remotePath; + this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public RemoveTrashbinFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { + this.remotePath = remotePath; + this.sessionTimeOut = sessionTimeOut; } /** @@ -48,14 +54,14 @@ protected RemoteOperationResult run(OwnCloudClient client) { try { delete = new DeleteMethod(client.getDavUri() + WebdavUtils.encodePath(remotePath)); - int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); + int status = client.executeMethod(delete, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); delete.getResponseBodyAsString(); // exhaust the response, although not interesting - result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), delete); + result = new RemoteOperationResult<>((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), delete); Log_OC.i(TAG, "Remove " + remotePath + ": " + result.getLogMessage()); } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Remove " + remotePath + ": " + result.getLogMessage(), e); } finally { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java index a1455f5a6..f623aadbe 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java @@ -10,6 +10,8 @@ import android.net.Uri; import android.util.Log; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -27,11 +29,10 @@ public class RestoreTrashbinFileRemoteOperation extends RemoteOperation { private static final String TAG = RestoreTrashbinFileRemoteOperation.class.getSimpleName(); - private static final int RESTORE_READ_TIMEOUT = 30000; - private static final int RESTORE_CONNECTION_TIMEOUT = 5000; - private String sourcePath; - private String fileName; + private final String sourcePath; + private final String fileName; + private final SessionTimeOut sessionTimeOut; /** * Constructor @@ -42,6 +43,13 @@ public class RestoreTrashbinFileRemoteOperation extends RemoteOperation { public RestoreTrashbinFileRemoteOperation(String sourcePath, String fileName) { this.sourcePath = sourcePath; this.fileName = fileName; + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public RestoreTrashbinFileRemoteOperation(String sourcePath, String fileName, SessionTimeOut sessionTimeOut) { + this.sourcePath = sourcePath; + this.fileName = fileName; + this.sessionTimeOut = sessionTimeOut; } /** @@ -60,13 +68,13 @@ protected RemoteOperationResult run(OwnCloudClient client) { Uri.encode(fileName); move = new MoveMethod(source, target, true); - int status = client.executeMethod(move, RESTORE_READ_TIMEOUT, RESTORE_CONNECTION_TIMEOUT); + int status = client.executeMethod(move, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); - result = new RemoteOperationResult(isSuccess(status), move); + result = new RemoteOperationResult<>(isSuccess(status), move); client.exhaustResponse(move.getResponseBodyAsStream()); } catch (IOException e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log.e(TAG, "Restore trashbin file " + sourcePath + " failed: " + result.getLogMessage(), e); } finally { if (move != null) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java index 3a1e4ae55..3f6cb44b4 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.users; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -24,12 +26,19 @@ public class CheckRemoteWipeRemoteOperation extends RemoteOperation { private static final String TAG = CheckRemoteWipeRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String REMOTE_WIPE_URL = "/index.php/core/wipe/check"; // JSON node names private static final String WIPE = "wipe"; + private final SessionTimeOut sessionTimeOut; + + public CheckRemoteWipeRemoteOperation() { + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public CheckRemoteWipeRemoteOperation(SessionTimeOut sessionTimeOut) { + this.sessionTimeOut = sessionTimeOut; + } /** * @param client Client object @@ -44,7 +53,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { postMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); postMethod.setParameter(REMOTE_WIPE_TOKEN, client.getCredentials().getAuthToken()); - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(postMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); if (HttpStatus.SC_OK == status) { String response = postMethod.getResponseBodyAsString(); @@ -52,17 +61,17 @@ protected RemoteOperationResult run(OwnCloudClient client) { JSONObject json = new JSONObject(response); if (json.getBoolean(WIPE)) { - result = new RemoteOperationResult(true, postMethod); + result = new RemoteOperationResult<>(true, postMethod); } else { - result = new RemoteOperationResult(false, postMethod); + result = new RemoteOperationResult<>(false, postMethod); } } else { - result = new RemoteOperationResult(false, postMethod); + result = new RemoteOperationResult<>(false, postMethod); } client.exhaustResponse(postMethod.getResponseBodyAsStream()); } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Getting remote wipe status failed: " + result.getLogMessage(), result.getException()); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java index 6a0a56c13..4c3c031a3 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java @@ -7,6 +7,8 @@ */ package com.owncloud.android.lib.resources.users; +import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -23,14 +25,19 @@ public class RemoteWipeSuccessRemoteOperation extends RemoteOperation { private static final String TAG = RemoteWipeSuccessRemoteOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 40000; - private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String REMOTE_WIPE_URL = "/index.php/core/wipe/success"; - private String appToken; + private final String appToken; + private final SessionTimeOut sessionTimeOut; public RemoteWipeSuccessRemoteOperation(String appToken) { this.appToken = appToken; + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + } + + public RemoteWipeSuccessRemoteOperation(String appToken, SessionTimeOut sessionTimeOut) { + this.appToken = appToken; + this.sessionTimeOut = sessionTimeOut; } /** @@ -46,17 +53,17 @@ protected RemoteOperationResult run(OwnCloudClient client) { postMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); postMethod.setParameter(REMOTE_WIPE_TOKEN, appToken); - int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + int status = client.executeMethod(postMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut()); client.exhaustResponse(postMethod.getResponseBodyAsStream()); if (HttpStatus.SC_OK == status) { - result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK); + result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.OK); } else { - result = new RemoteOperationResult( + result = new RemoteOperationResult<>( RemoteOperationResult.ResultCode.valueOf(String.valueOf(status))); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Setting status of remote wipe status failed: " + result.getLogMessage(), result.getException()); From b13183f7b6cb918068d2345c28751137d0814946 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 27 Nov 2024 10:08:19 +0100 Subject: [PATCH 2/9] fix kt constructors Signed-off-by: alperozturk --- .../GenerateAppPasswordRemoteOperation.java | 2 +- ...ichWorkspaceDirectEditingRemoteOperation.java | 4 ++-- .../e2ee/GetMetadataRemoteOperation.java | 2 +- .../resources/e2ee/LockFileRemoteOperation.java | 4 ++-- .../e2ee/StoreMetadataRemoteOperation.java | 2 +- .../e2ee/StoreMetadataV2RemoteOperation.kt | 16 ++++++++++++++-- .../e2ee/ToggleEncryptionRemoteOperation.java | 2 +- .../e2ee/UnlockFileRemoteOperation.java | 2 +- .../e2ee/UnlockFileV1RemoteOperation.kt | 8 ++++++-- .../e2ee/UpdateMetadataRemoteOperation.java | 2 +- .../e2ee/UpdateMetadataV2RemoteOperation.kt | 14 ++++++++++++-- .../files/CheckEtagRemoteOperation.java | 2 +- .../files/RestoreFileVersionRemoteOperation.java | 2 +- .../RemoveTrashbinFileRemoteOperation.java | 2 +- 14 files changed, 45 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java index f4ad29df9..9481edbb1 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java @@ -36,7 +36,7 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { private final SessionTimeOut sessionTimeOut; public GenerateAppPasswordRemoteOperation() { - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public GenerateAppPasswordRemoteOperation(SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java index 4f3daba65..1e0e72376 100644 --- a/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java @@ -33,11 +33,11 @@ public class RichWorkspaceDirectEditingRemoteOperation extends RemoteOperation { private static final String PATH = "path"; private final SessionTimeOut sessionTimeOut; - private String path; + private final String path; public RichWorkspaceDirectEditingRemoteOperation(String path) { this.path = path; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public RichWorkspaceDirectEditingRemoteOperation(String path, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java index e5e8286b7..01cec1d87 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java @@ -45,7 +45,7 @@ public class GetMetadataRemoteOperation extends RemoteOperation { public LockFileRemoteOperation(long localId, long counter) { this.localId = localId; this.counter = counter; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public LockFileRemoteOperation(long localId) { this.localId = localId; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public LockFileRemoteOperation(long localId, long counter, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java index 7b52356ff..828a26672 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java @@ -47,7 +47,7 @@ public class StoreMetadataRemoteOperation extends RemoteOperation { public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson) { this.fileId = fileId; this.encryptedMetadataJson = encryptedMetadataJson; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt index 9d80df17a..2f06b6ea5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt @@ -25,9 +25,21 @@ class StoreMetadataV2RemoteOperation( private val remoteId: String, private val encryptedMetadataJson: String, private val token: String, - private val signature: String, - private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + private val signature: String ) : RemoteOperation() { + + private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + + constructor( + remoteId: String, + encryptedMetadataJson: String, + token: String, + signature: String, + sessionTimeOut: SessionTimeOut + ): this(remoteId, encryptedMetadataJson, token, signature) { + this.sessionTimeOut = sessionTimeOut + } + /** * @param client Client object */ diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java index 02453450d..7e813c4c5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java @@ -43,7 +43,7 @@ public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean this.localId = localId; this.remotePath = remotePath; this.encryption = encryption; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean encryption, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java index 5d8b99405..bc4b81dd7 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java @@ -37,7 +37,7 @@ public class UnlockFileRemoteOperation extends RemoteOperation { public UnlockFileRemoteOperation(long localId, String token) { this.localId = localId; this.token = token; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public UnlockFileRemoteOperation(long localId, String token, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt index b986718f0..228cd25ee 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt @@ -21,9 +21,13 @@ import org.apache.commons.httpclient.methods.DeleteMethod */ class UnlockFileV1RemoteOperation( private val localId: Long, - private val token: String, - private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + private val token: String ) : RemoteOperation() { + private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + + constructor(localId: Long, token: String, sessionTimeOut: SessionTimeOut) : this(localId, token) { + this.sessionTimeOut = sessionTimeOut + } @Deprecated("Deprecated in Java") @Suppress("Detekt.TooGenericExceptionCaught") diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java index 6d20dab92..e1a1ae71c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java @@ -52,7 +52,7 @@ public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, this.fileId = fileId; this.encryptedMetadataJson = URLEncoder.encode(encryptedMetadataJson); this.token = token; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, String token, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt index d74144c2e..440d2be0b 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt @@ -27,10 +27,10 @@ class UpdateMetadataV2RemoteOperation( private val remoteId: String, encryptedMetadataJson: String, private val token: String, - private val signature: String, - private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + private val signature: String ) : RemoteOperation() { private val encryptedMetadataJson: String + private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut /** * Constructor @@ -40,6 +40,16 @@ class UpdateMetadataV2RemoteOperation( // this.encryptedMetadataJson = encryptedMetadataJson; } + constructor( + remoteId: String, + encryptedMetadataJson: String, + token: String, + signature: String, + sessionTimeOut: SessionTimeOut + ) : this(remoteId,encryptedMetadataJson, token, signature) { + this.sessionTimeOut = sessionTimeOut + } + /** * @param client Client object */ diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java index 3e839cb80..5b3d6a8e6 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java @@ -41,7 +41,7 @@ public class CheckEtagRemoteOperation extends RemoteOperation { public CheckEtagRemoteOperation(String path, String expectedEtag) { this.path = path; this.expectedEtag = expectedEtag; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public CheckEtagRemoteOperation(String path, String expectedEtag, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java index 7f22264d9..fbafa2831 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java @@ -43,7 +43,7 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation { public RestoreFileVersionRemoteOperation(long fileId, String fileName) { this.fileId = fileId; this.fileName = fileName; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public RestoreFileVersionRemoteOperation(long fileId, String fileName, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java index 77811d3de..5c261fb9d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java @@ -34,7 +34,7 @@ public class RemoveTrashbinFileRemoteOperation extends RemoteOperation { */ public RemoveTrashbinFileRemoteOperation(String remotePath) { this.remotePath = remotePath; - this.sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); } public RemoveTrashbinFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { From 5f21c760d494dda406dfe17b000f50da7af9963d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 27 Nov 2024 10:15:09 +0100 Subject: [PATCH 3/9] Fix code analytics Signed-off-by: alperozturk --- library/src/main/java/com/nextcloud/common/SessionTimeOut.kt | 1 + .../lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt | 3 +-- .../lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt b/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt index de4239e4a..3d9013e3e 100644 --- a/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt +++ b/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt @@ -9,4 +9,5 @@ package com.nextcloud.common data class SessionTimeOut(val readTimeOut: Int, val connectionTimeOut: Int) +@Suppress("Detekt.MagicNumber") val defaultSessionTimeOut = SessionTimeOut(40000, 5000) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt index 2f06b6ea5..7ac406ae6 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt @@ -27,7 +27,6 @@ class StoreMetadataV2RemoteOperation( private val token: String, private val signature: String ) : RemoteOperation() { - private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut constructor( @@ -36,7 +35,7 @@ class StoreMetadataV2RemoteOperation( token: String, signature: String, sessionTimeOut: SessionTimeOut - ): this(remoteId, encryptedMetadataJson, token, signature) { + ) : this(remoteId, encryptedMetadataJson, token, signature) { this.sessionTimeOut = sessionTimeOut } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt index 440d2be0b..dbc7bec7c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt @@ -46,7 +46,7 @@ class UpdateMetadataV2RemoteOperation( token: String, signature: String, sessionTimeOut: SessionTimeOut - ) : this(remoteId,encryptedMetadataJson, token, signature) { + ) : this(remoteId, encryptedMetadataJson, token, signature) { this.sessionTimeOut = sessionTimeOut } From 6baf4903a97348a7c1163f9ed02da6c68f5906e1 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 28 Nov 2024 12:50:48 +0100 Subject: [PATCH 4/9] Use secondary constructors Signed-off-by: alperozturk --- .../GenerateAppPasswordRemoteOperation.java | 2 +- ...WorkspaceDirectEditingRemoteOperation.java | 3 +-- .../e2ee/GetMetadataRemoteOperation.java | 3 +-- .../e2ee/LockFileRemoteOperation.java | 20 +++++++++---------- .../e2ee/StoreMetadataRemoteOperation.java | 4 +--- .../e2ee/ToggleEncryptionRemoteOperation.java | 5 +---- .../e2ee/UnlockFileRemoteOperation.java | 4 +--- .../e2ee/UpdateMetadataRemoteOperation.java | 5 +---- .../files/CheckEtagRemoteOperation.java | 8 +++----- .../files/CopyFileRemoteOperation.java | 5 +---- .../files/CreateFolderRemoteOperation.java | 13 ++++-------- .../files/MoveFileRemoteOperation.java | 5 +---- .../files/ReadFileRemoteOperation.java | 3 +-- .../files/RemoveFileRemoteOperation.java | 3 +-- .../files/RenameFileRemoteOperation.java | 2 +- .../RestoreFileVersionRemoteOperation.java | 4 +--- .../RemoveTrashbinFileRemoteOperation.java | 3 +-- .../RestoreTrashbinFileRemoteOperation.java | 4 +--- .../users/CheckRemoteWipeRemoteOperation.java | 2 +- .../RemoteWipeSuccessRemoteOperation.java | 3 +-- 20 files changed, 33 insertions(+), 68 deletions(-) diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java index 9481edbb1..957108f46 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java @@ -36,7 +36,7 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { private final SessionTimeOut sessionTimeOut; public GenerateAppPasswordRemoteOperation() { - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(SessionTimeOutKt.getDefaultSessionTimeOut()); } public GenerateAppPasswordRemoteOperation(SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java index 1e0e72376..8644643b3 100644 --- a/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/richWorkspace/RichWorkspaceDirectEditingRemoteOperation.java @@ -36,8 +36,7 @@ public class RichWorkspaceDirectEditingRemoteOperation extends RemoteOperation { private final String path; public RichWorkspaceDirectEditingRemoteOperation(String path) { - this.path = path; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(path, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RichWorkspaceDirectEditingRemoteOperation(String path, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java index 01cec1d87..ec21af37e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java @@ -44,8 +44,7 @@ public class GetMetadataRemoteOperation extends RemoteOperation { private static final String COUNTER_HEADER = "X-NC-E2EE-COUNTER"; private final long localId; - private long counter = -1; + private final long counter; + + private static final long defaultCounter = -1; // JSON node names private static final String NODE_OCS = "ocs"; @@ -42,24 +44,20 @@ public class LockFileRemoteOperation extends RemoteOperation { * Constructor */ public LockFileRemoteOperation(long localId, long counter) { - this.localId = localId; - this.counter = counter; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(localId, counter, SessionTimeOutKt.getDefaultSessionTimeOut()); } public LockFileRemoteOperation(long localId) { - this.localId = localId; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(localId, SessionTimeOutKt.getDefaultSessionTimeOut()); } - public LockFileRemoteOperation(long localId, long counter, SessionTimeOut sessionTimeOut) { - this.localId = localId; - this.counter = counter; - this.sessionTimeOut = sessionTimeOut; + public LockFileRemoteOperation(long localId, SessionTimeOut sessionTimeOut) { + this(localId, defaultCounter, sessionTimeOut); } - public LockFileRemoteOperation(long localId, SessionTimeOut sessionTimeOut) { + public LockFileRemoteOperation(long localId, long counter, SessionTimeOut sessionTimeOut) { this.localId = localId; + this.counter = counter; this.sessionTimeOut = sessionTimeOut; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java index 828a26672..a7345cf3d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java @@ -45,9 +45,7 @@ public class StoreMetadataRemoteOperation extends RemoteOperation { * Constructor */ public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson) { - this.fileId = fileId; - this.encryptedMetadataJson = encryptedMetadataJson; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(fileId, encryptedMetadataJson, SessionTimeOutKt.getDefaultSessionTimeOut()); } public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java index 7e813c4c5..3651b826d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java @@ -40,10 +40,7 @@ public class ToggleEncryptionRemoteOperation extends RemoteOperation { * Constructor */ public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean encryption) { - this.localId = localId; - this.remotePath = remotePath; - this.encryption = encryption; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(localId, remotePath, encryption, SessionTimeOutKt.getDefaultSessionTimeOut()); } public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean encryption, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java index bc4b81dd7..ae5e34b21 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java @@ -35,9 +35,7 @@ public class UnlockFileRemoteOperation extends RemoteOperation { * Constructor */ public UnlockFileRemoteOperation(long localId, String token) { - this.localId = localId; - this.token = token; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(localId, token, SessionTimeOutKt.getDefaultSessionTimeOut()); } public UnlockFileRemoteOperation(long localId, String token, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java index e1a1ae71c..1033d0e95 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java @@ -49,10 +49,7 @@ public class UpdateMetadataRemoteOperation extends RemoteOperation { * Constructor */ public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, String token) { - this.fileId = fileId; - this.encryptedMetadataJson = URLEncoder.encode(encryptedMetadataJson); - this.token = token; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(fileId, encryptedMetadataJson, token, SessionTimeOutKt.getDefaultSessionTimeOut()); } public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, String token, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java index 5b3d6a8e6..32d87b8c8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CheckEtagRemoteOperation.java @@ -33,15 +33,13 @@ public class CheckEtagRemoteOperation extends RemoteOperation { private static final String TAG = CheckEtagRemoteOperation.class.getSimpleName(); - private String path; - private String expectedEtag; + private final String path; + private final String expectedEtag; private final SessionTimeOut sessionTimeOut; public CheckEtagRemoteOperation(String path, String expectedEtag) { - this.path = path; - this.expectedEtag = expectedEtag; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(path, expectedEtag, SessionTimeOutKt.getDefaultSessionTimeOut()); } public CheckEtagRemoteOperation(String path, String expectedEtag, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java index 043b0fb0f..d012273a0 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java @@ -53,10 +53,7 @@ public class CopyFileRemoteOperation extends RemoteOperation { * @param targetRemotePath Remove path desired for the file/folder after moving it. */ public CopyFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) { - mSrcRemotePath = srcRemotePath; - mTargetRemotePath = targetRemotePath; - mOverwrite = overwrite; - this.sessionTimeOut = new SessionTimeOut(600000, 5000); + this(srcRemotePath, targetRemotePath, overwrite, new SessionTimeOut(600000, 5000)); } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java index 4fb2ff7e8..820c09931 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java @@ -33,7 +33,7 @@ public class CreateFolderRemoteOperation extends RemoteOperation { private final boolean createFullPath; private final String remotePath; - private String token; + private final String token; private final SessionTimeOut sessionTimeOut; /** @@ -44,20 +44,15 @@ public class CreateFolderRemoteOperation extends RemoteOperation { * if don't exist yet. */ public CreateFolderRemoteOperation(String remotePath, boolean createFullPath) { - this.remotePath = remotePath; - this.createFullPath = createFullPath; - this.sessionTimeOut = new SessionTimeOut(30000, 5000); + this(remotePath, createFullPath, SessionTimeOutKt.getDefaultSessionTimeOut()); } public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, String token) { - this(remotePath, createFullPath); - this.token = token; + this(remotePath, createFullPath, token, SessionTimeOutKt.getDefaultSessionTimeOut()); } public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, SessionTimeOut sessionTimeOut) { - this.remotePath = remotePath; - this.createFullPath = createFullPath; - this.sessionTimeOut = sessionTimeOut; + this(remotePath, createFullPath, "", sessionTimeOut); } public CreateFolderRemoteOperation(String remotePath, boolean createFullPath, String token, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java index d53a5a101..31f836658 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/MoveFileRemoteOperation.java @@ -51,10 +51,7 @@ public class MoveFileRemoteOperation extends RemoteOperation { * @param targetRemotePath Remove path desired for the file/folder after moving it. */ public MoveFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) { - mSrcRemotePath = srcRemotePath; - mTargetRemotePath = targetRemotePath; - mOverwrite = overwrite; - sessionTimeOut = new SessionTimeOut(600000, 5000); + this(srcRemotePath, targetRemotePath, overwrite, SessionTimeOutKt.getDefaultSessionTimeOut()); } public MoveFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java index ec3cc460b..52a97a839 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileRemoteOperation.java @@ -44,8 +44,7 @@ public class ReadFileRemoteOperation extends RemoteOperation { * @param remotePath Remote path of the file. */ public ReadFileRemoteOperation(String remotePath) { - mRemotePath = remotePath; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(remotePath, SessionTimeOutKt.getDefaultSessionTimeOut()); } public ReadFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java index 0f1169273..0c856ddbf 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RemoveFileRemoteOperation.java @@ -34,8 +34,7 @@ public class RemoveFileRemoteOperation extends RemoteOperation { * @param remotePath RemotePath of the remote file or folder to remove from the server */ public RemoveFileRemoteOperation(String remotePath) { - mRemotePath = remotePath; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(remotePath, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RemoveFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java index 7975bcd6c..a2a85a010 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java @@ -46,7 +46,7 @@ public class RenameFileRemoteOperation extends RemoteOperation { * @param isFolder 'true' for folder and 'false' for files */ public RenameFileRemoteOperation(String oldName, String oldRemotePath, String newName, boolean isFolder) { - this(oldName, oldRemotePath, newName, isFolder, new SessionTimeOut(600000, 5000)); + this(oldName, oldRemotePath, newName, isFolder, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RenameFileRemoteOperation(String oldName, String oldRemotePath, String newName, boolean isFolder, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java index fbafa2831..c4f63ccff 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java @@ -41,9 +41,7 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation { * @param fileName version date in unixtime */ public RestoreFileVersionRemoteOperation(long fileId, String fileName) { - this.fileId = fileId; - this.fileName = fileName; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(fileId, fileName, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RestoreFileVersionRemoteOperation(long fileId, String fileName, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java index 5c261fb9d..2417e1ea9 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RemoveTrashbinFileRemoteOperation.java @@ -33,8 +33,7 @@ public class RemoveTrashbinFileRemoteOperation extends RemoteOperation { * @param remotePath RemotePath of the remote file or folder to remove from the server */ public RemoveTrashbinFileRemoteOperation(String remotePath) { - this.remotePath = remotePath; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(remotePath, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RemoveTrashbinFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java index f623aadbe..331ea4e2c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/RestoreTrashbinFileRemoteOperation.java @@ -41,9 +41,7 @@ public class RestoreTrashbinFileRemoteOperation extends RemoteOperation { * @param fileName original filename */ public RestoreTrashbinFileRemoteOperation(String sourcePath, String fileName) { - this.sourcePath = sourcePath; - this.fileName = fileName; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(sourcePath, fileName, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RestoreTrashbinFileRemoteOperation(String sourcePath, String fileName, SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java index 3f6cb44b4..527a127cb 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperation.java @@ -33,7 +33,7 @@ public class CheckRemoteWipeRemoteOperation extends RemoteOperation { private final SessionTimeOut sessionTimeOut; public CheckRemoteWipeRemoteOperation() { - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(SessionTimeOutKt.getDefaultSessionTimeOut()); } public CheckRemoteWipeRemoteOperation(SessionTimeOut sessionTimeOut) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java index 4c3c031a3..a7dd57675 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/RemoteWipeSuccessRemoteOperation.java @@ -31,8 +31,7 @@ public class RemoteWipeSuccessRemoteOperation extends RemoteOperation { private final SessionTimeOut sessionTimeOut; public RemoteWipeSuccessRemoteOperation(String appToken) { - this.appToken = appToken; - sessionTimeOut = SessionTimeOutKt.getDefaultSessionTimeOut(); + this(appToken, SessionTimeOutKt.getDefaultSessionTimeOut()); } public RemoteWipeSuccessRemoteOperation(String appToken, SessionTimeOut sessionTimeOut) { From bbcfc8f608ef5e8b2eb098391d144e678eb7edfe Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 28 Nov 2024 12:51:09 +0100 Subject: [PATCH 5/9] Increase default timeout values Signed-off-by: alperozturk --- library/src/main/java/com/nextcloud/common/SessionTimeOut.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt b/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt index 3d9013e3e..4e2fe838a 100644 --- a/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt +++ b/library/src/main/java/com/nextcloud/common/SessionTimeOut.kt @@ -10,4 +10,4 @@ package com.nextcloud.common data class SessionTimeOut(val readTimeOut: Int, val connectionTimeOut: Int) @Suppress("Detekt.MagicNumber") -val defaultSessionTimeOut = SessionTimeOut(40000, 5000) +val defaultSessionTimeOut = SessionTimeOut(60000, 15000) From d490c2fede16a23e06e8df08e3f783390e0e18bc Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 28 Nov 2024 12:54:18 +0100 Subject: [PATCH 6/9] Use increased default timeout values Signed-off-by: alperozturk --- .../android/lib/resources/files/CopyFileRemoteOperation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java index d012273a0..0ca980caf 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/CopyFileRemoteOperation.java @@ -9,6 +9,7 @@ import android.util.Log; import com.nextcloud.common.SessionTimeOut; +import com.nextcloud.common.SessionTimeOutKt; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -53,7 +54,7 @@ public class CopyFileRemoteOperation extends RemoteOperation { * @param targetRemotePath Remove path desired for the file/folder after moving it. */ public CopyFileRemoteOperation(String srcRemotePath, String targetRemotePath, boolean overwrite) { - this(srcRemotePath, targetRemotePath, overwrite, new SessionTimeOut(600000, 5000)); + this(srcRemotePath, targetRemotePath, overwrite, SessionTimeOutKt.getDefaultSessionTimeOut()); } From 635e112725fe1f195039891abcedd33fb7d2a8e2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 28 Nov 2024 13:05:58 +0100 Subject: [PATCH 7/9] use JvmOverloads Signed-off-by: alperozturk --- .../e2ee/StoreMetadataV2RemoteOperation.kt | 16 +++--------- .../e2ee/UnlockFileV1RemoteOperation.kt | 10 +++---- .../e2ee/UpdateMetadataV2RemoteOperation.kt | 26 +++---------------- 3 files changed, 10 insertions(+), 42 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt index 7ac406ae6..af34bf231 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt @@ -21,23 +21,13 @@ import org.json.JSONObject /** * Remote operation to store the folder metadata */ -class StoreMetadataV2RemoteOperation( +class StoreMetadataV2RemoteOperation @JvmOverloads constructor( private val remoteId: String, private val encryptedMetadataJson: String, private val token: String, - private val signature: String + private val signature: String, + var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { - private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut - - constructor( - remoteId: String, - encryptedMetadataJson: String, - token: String, - signature: String, - sessionTimeOut: SessionTimeOut - ) : this(remoteId, encryptedMetadataJson, token, signature) { - this.sessionTimeOut = sessionTimeOut - } /** * @param client Client object diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt index 228cd25ee..64e5069db 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt @@ -19,15 +19,11 @@ import org.apache.commons.httpclient.methods.DeleteMethod /** * Unlock a file */ -class UnlockFileV1RemoteOperation( +class UnlockFileV1RemoteOperation @JvmOverloads constructor( private val localId: Long, - private val token: String + private val token: String, + var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { - private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut - - constructor(localId: Long, token: String, sessionTimeOut: SessionTimeOut) : this(localId, token) { - this.sessionTimeOut = sessionTimeOut - } @Deprecated("Deprecated in Java") @Suppress("Detekt.TooGenericExceptionCaught") diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt index dbc7bec7c..3bc6acb2f 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt @@ -23,32 +23,14 @@ import java.net.URLEncoder /** * Remote operation to update the folder metadata */ -class UpdateMetadataV2RemoteOperation( +class UpdateMetadataV2RemoteOperation @JvmOverloads constructor( private val remoteId: String, encryptedMetadataJson: String, private val token: String, - private val signature: String + private val signature: String, + var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { - private val encryptedMetadataJson: String - private var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut - - /** - * Constructor - */ - init { - this.encryptedMetadataJson = URLEncoder.encode(encryptedMetadataJson) - // this.encryptedMetadataJson = encryptedMetadataJson; - } - - constructor( - remoteId: String, - encryptedMetadataJson: String, - token: String, - signature: String, - sessionTimeOut: SessionTimeOut - ) : this(remoteId, encryptedMetadataJson, token, signature) { - this.sessionTimeOut = sessionTimeOut - } + private val encryptedMetadataJson: String = URLEncoder.encode(encryptedMetadataJson) /** * @param client Client object From 0aa9c37b899283ed39a4362840fe4d9a877fbee2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 28 Nov 2024 13:07:44 +0100 Subject: [PATCH 8/9] use JvmOverloads Signed-off-by: alperozturk --- .../lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt | 2 +- .../android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt | 2 +- .../lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt index af34bf231..1eb1b8462 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt @@ -26,7 +26,7 @@ class StoreMetadataV2RemoteOperation @JvmOverloads constructor( private val encryptedMetadataJson: String, private val token: String, private val signature: String, - var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { /** diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt index 64e5069db..f98374a4a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt @@ -22,7 +22,7 @@ import org.apache.commons.httpclient.methods.DeleteMethod class UnlockFileV1RemoteOperation @JvmOverloads constructor( private val localId: Long, private val token: String, - var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { @Deprecated("Deprecated in Java") diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt index 3bc6acb2f..d3da509c8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt @@ -28,7 +28,7 @@ class UpdateMetadataV2RemoteOperation @JvmOverloads constructor( encryptedMetadataJson: String, private val token: String, private val signature: String, - var sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut ) : RemoteOperation() { private val encryptedMetadataJson: String = URLEncoder.encode(encryptedMetadataJson) From 97b8c7718cd57fde12550d4792e254bc5df876e9 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 28 Nov 2024 13:54:54 +0100 Subject: [PATCH 9/9] fix code analytics Signed-off-by: alperozturk --- .../e2ee/StoreMetadataV2RemoteOperation.kt | 125 +++++++-------- .../e2ee/UnlockFileV1RemoteOperation.kt | 73 ++++----- .../e2ee/UpdateMetadataV2RemoteOperation.kt | 143 +++++++++--------- 3 files changed, 174 insertions(+), 167 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt index 1eb1b8462..a2a49c215 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataV2RemoteOperation.kt @@ -21,73 +21,76 @@ import org.json.JSONObject /** * Remote operation to store the folder metadata */ -class StoreMetadataV2RemoteOperation @JvmOverloads constructor( - private val remoteId: String, - private val encryptedMetadataJson: String, - private val token: String, - private val signature: String, - private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut -) : RemoteOperation() { +class StoreMetadataV2RemoteOperation + @JvmOverloads + constructor( + private val remoteId: String, + private val encryptedMetadataJson: String, + private val token: String, + private val signature: String, + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + ) : RemoteOperation() { + /** + * @param client Client object + */ + @Deprecated("Deprecated in Java") + @Suppress("Detekt.TooGenericExceptionCaught") + override fun run(client: OwnCloudClient): RemoteOperationResult { + var postMethod: Utf8PostMethod? = null + var result: RemoteOperationResult + try { + // remote request + postMethod = Utf8PostMethod(client.baseUri.toString() + METADATA_URL + remoteId + JSON_FORMAT) + postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) + postMethod.addRequestHeader(E2E_TOKEN, token) + postMethod.addRequestHeader(HEADER_SIGNATURE, signature) + postMethod.setParameter(METADATA, encryptedMetadataJson) + val status = + client + .executeMethod(postMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) + if (status == HttpStatus.SC_OK) { + val response = postMethod.responseBodyAsString - /** - * @param client Client object - */ - @Deprecated("Deprecated in Java") - @Suppress("Detekt.TooGenericExceptionCaught") - override fun run(client: OwnCloudClient): RemoteOperationResult { - var postMethod: Utf8PostMethod? = null - var result: RemoteOperationResult - try { - // remote request - postMethod = Utf8PostMethod(client.baseUri.toString() + METADATA_URL + remoteId + JSON_FORMAT) - postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) - postMethod.addRequestHeader(E2E_TOKEN, token) - postMethod.addRequestHeader(HEADER_SIGNATURE, signature) - postMethod.setParameter(METADATA, encryptedMetadataJson) - val status = client.executeMethod(postMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) - if (status == HttpStatus.SC_OK) { - val response = postMethod.responseBodyAsString - - // Parse the response - val respJSON = JSONObject(response) - val metadata = - respJSON - .getJSONObject(NODE_OCS) - .getJSONObject(NODE_DATA) - .getString(NODE_META_DATA) - result = RemoteOperationResult(true, postMethod) - result.setResultData(metadata) - } else { - result = RemoteOperationResult(false, postMethod) - Log.e( + // Parse the response + val respJSON = JSONObject(response) + val metadata = + respJSON + .getJSONObject(NODE_OCS) + .getJSONObject(NODE_DATA) + .getString(NODE_META_DATA) + result = RemoteOperationResult(true, postMethod) + result.setResultData(metadata) + } else { + result = RemoteOperationResult(false, postMethod) + Log.e( + TAG, + "Storing of metadata for folder " + remoteId + " failed: " + postMethod.responseBodyAsString, + result.exception + ) + client.exhaustResponse(postMethod.responseBodyAsStream) + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e( TAG, - "Storing of metadata for folder " + remoteId + " failed: " + postMethod.responseBodyAsString, + "Storing of metadata for folder " + remoteId + " failed: " + result.logMessage, result.exception ) - client.exhaustResponse(postMethod.responseBodyAsStream) + } finally { + postMethod?.releaseConnection() } - } catch (e: Exception) { - result = RemoteOperationResult(e) - Log_OC.e( - TAG, - "Storing of metadata for folder " + remoteId + " failed: " + result.logMessage, - result.exception - ) - } finally { - postMethod?.releaseConnection() + return result } - return result - } - companion object { - private val TAG = StoreMetadataV2RemoteOperation::class.java.simpleName - private const val METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" - private const val METADATA = "metaData" - private const val HEADER_SIGNATURE = "X-NC-E2EE-SIGNATURE" + companion object { + private val TAG = StoreMetadataV2RemoteOperation::class.java.simpleName + private const val METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" + private const val METADATA = "metaData" + private const val HEADER_SIGNATURE = "X-NC-E2EE-SIGNATURE" - // JSON node names - private const val NODE_OCS = "ocs" - private const val NODE_DATA = "data" - private const val NODE_META_DATA = "meta-data" + // JSON node names + private const val NODE_OCS = "ocs" + private const val NODE_DATA = "data" + private const val NODE_META_DATA = "meta-data" + } } -} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt index f98374a4a..dc7b5bc73 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileV1RemoteOperation.kt @@ -19,42 +19,43 @@ import org.apache.commons.httpclient.methods.DeleteMethod /** * Unlock a file */ -class UnlockFileV1RemoteOperation @JvmOverloads constructor( - private val localId: Long, - private val token: String, - private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut -) : RemoteOperation() { - - @Deprecated("Deprecated in Java") - @Suppress("Detekt.TooGenericExceptionCaught") - override fun run(client: OwnCloudClient): RemoteOperationResult { - var result: RemoteOperationResult - var deleteMethod: DeleteMethod? = null - try { - // remote request - deleteMethod = DeleteMethod(client.baseUri.toString() + LOCK_FILE_URL + localId) - deleteMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) - deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED) - deleteMethod.addRequestHeader(E2E_TOKEN, token) - val status = - client.executeMethod(deleteMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) - result = RemoteOperationResult(status == HttpStatus.SC_OK, deleteMethod) - client.exhaustResponse(deleteMethod.responseBodyAsStream) - } catch (e: Exception) { - result = RemoteOperationResult(e) - Log_OC.e( - TAG, - "Unlock file with id " + localId + " failed: " + result.logMessage, - result.exception - ) - } finally { - deleteMethod?.releaseConnection() +class UnlockFileV1RemoteOperation + @JvmOverloads + constructor( + private val localId: Long, + private val token: String, + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + ) : RemoteOperation() { + @Deprecated("Deprecated in Java") + @Suppress("Detekt.TooGenericExceptionCaught") + override fun run(client: OwnCloudClient): RemoteOperationResult { + var result: RemoteOperationResult + var deleteMethod: DeleteMethod? = null + try { + // remote request + deleteMethod = DeleteMethod(client.baseUri.toString() + LOCK_FILE_URL + localId) + deleteMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) + deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED) + deleteMethod.addRequestHeader(E2E_TOKEN, token) + val status = + client.executeMethod(deleteMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) + result = RemoteOperationResult(status == HttpStatus.SC_OK, deleteMethod) + client.exhaustResponse(deleteMethod.responseBodyAsStream) + } catch (e: Exception) { + result = RemoteOperationResult(e) + Log_OC.e( + TAG, + "Unlock file with id " + localId + " failed: " + result.logMessage, + result.exception + ) + } finally { + deleteMethod?.releaseConnection() + } + return result } - return result - } - companion object { - private val TAG = UnlockFileV1RemoteOperation::class.java.simpleName - private const val LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/" + companion object { + private val TAG = UnlockFileV1RemoteOperation::class.java.simpleName + private const val LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/" + } } -} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt index d3da509c8..986361a29 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataV2RemoteOperation.kt @@ -23,84 +23,87 @@ import java.net.URLEncoder /** * Remote operation to update the folder metadata */ -class UpdateMetadataV2RemoteOperation @JvmOverloads constructor( - private val remoteId: String, - encryptedMetadataJson: String, - private val token: String, - private val signature: String, - private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut -) : RemoteOperation() { - private val encryptedMetadataJson: String = URLEncoder.encode(encryptedMetadataJson) +class UpdateMetadataV2RemoteOperation + @JvmOverloads + constructor( + private val remoteId: String, + encryptedMetadataJson: String, + private val token: String, + private val signature: String, + private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut + ) : RemoteOperation() { + private val encryptedMetadataJson: String = URLEncoder.encode(encryptedMetadataJson) - /** - * @param client Client object - */ - @Deprecated("Deprecated in Java") - @Suppress("Detekt.TooGenericExceptionCaught") - override fun run(client: OwnCloudClient): RemoteOperationResult { - var putMethod: PutMethod? = null - var result: RemoteOperationResult - try { - // remote request - putMethod = PutMethod(client.baseUri.toString() + METADATA_URL + remoteId) - putMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) - putMethod.addRequestHeader(E2E_TOKEN, token) - putMethod.addRequestHeader(HEADER_SIGNATURE, signature) - putMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED) - val putParams = arrayOfNulls(1) - putParams[0] = NameValuePair(FORMAT, "json") - putMethod.setQueryString(putParams) - val data = - StringRequestEntity( - "metaData=$encryptedMetadataJson", - "application/json", - "UTF-8" - ) - putMethod.requestEntity = data - val status = client.executeMethod(putMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) - if (status == HttpStatus.SC_OK) { - val response = putMethod.responseBodyAsString + /** + * @param client Client object + */ + @Deprecated("Deprecated in Java") + @Suppress("Detekt.TooGenericExceptionCaught") + override fun run(client: OwnCloudClient): RemoteOperationResult { + var putMethod: PutMethod? = null + var result: RemoteOperationResult + try { + // remote request + putMethod = PutMethod(client.baseUri.toString() + METADATA_URL + remoteId) + putMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) + putMethod.addRequestHeader(E2E_TOKEN, token) + putMethod.addRequestHeader(HEADER_SIGNATURE, signature) + putMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED) + val putParams = arrayOfNulls(1) + putParams[0] = NameValuePair(FORMAT, "json") + putMethod.setQueryString(putParams) + val data = + StringRequestEntity( + "metaData=$encryptedMetadataJson", + "application/json", + "UTF-8" + ) + putMethod.requestEntity = data + val status = + client + .executeMethod(putMethod, sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut) + if (status == HttpStatus.SC_OK) { + val response = putMethod.responseBodyAsString - // Parse the response - val respJSON = JSONObject(response) - val metadata = - respJSON - .getJSONObject(NODE_OCS) - .getJSONObject(NODE_DATA) - .getString(NODE_META_DATA) - result = RemoteOperationResult(true, putMethod) - result.setResultData(metadata) - } else { - result = RemoteOperationResult(false, putMethod) + val respJSON = JSONObject(response) + val metadata = + respJSON + .getJSONObject(NODE_OCS) + .getJSONObject(NODE_DATA) + .getString(NODE_META_DATA) + result = RemoteOperationResult(true, putMethod) + result.setResultData(metadata) + } else { + result = RemoteOperationResult(false, putMethod) + Log.e( + TAG, + "Updating metadata for folder " + remoteId + " failed: " + putMethod.responseBodyAsString, + result.exception + ) + client.exhaustResponse(putMethod.responseBodyAsStream) + } + } catch (e: Exception) { + result = RemoteOperationResult(e) Log.e( TAG, - "Updating metadata for folder " + remoteId + " failed: " + putMethod.responseBodyAsString, + "Updating metadata for folder " + remoteId + " failed: " + result.logMessage, result.exception ) - client.exhaustResponse(putMethod.responseBodyAsStream) + } finally { + putMethod?.releaseConnection() } - } catch (e: Exception) { - result = RemoteOperationResult(e) - Log.e( - TAG, - "Updating metadata for folder " + remoteId + " failed: " + result.logMessage, - result.exception - ) - } finally { - putMethod?.releaseConnection() + return result } - return result - } - companion object { - private val TAG = UpdateMetadataV2RemoteOperation::class.java.simpleName - private const val METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" - private const val FORMAT = "format" + companion object { + private val TAG = UpdateMetadataV2RemoteOperation::class.java.simpleName + private const val METADATA_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/" + private const val FORMAT = "format" - // JSON node names - private const val NODE_OCS = "ocs" - private const val NODE_DATA = "data" - private const val NODE_META_DATA = "meta-data" - private const val HEADER_SIGNATURE = "X-NC-E2EE-SIGNATURE" + // JSON node names + private const val NODE_OCS = "ocs" + private const val NODE_DATA = "data" + private const val NODE_META_DATA = "meta-data" + private const val HEADER_SIGNATURE = "X-NC-E2EE-SIGNATURE" + } } -}