|
@@ -23,6 +23,7 @@ package com.owncloud.android.operations;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.text.TextUtils;
|
|
|
|
|
@@ -98,6 +99,9 @@ import javax.crypto.Cipher;
|
|
|
|
|
|
import androidx.annotation.CheckResult;
|
|
|
import androidx.annotation.Nullable;
|
|
|
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
+
|
|
|
+import static com.owncloud.android.ui.activity.FileDisplayActivity.REFRESH_FOLDER_EVENT_RECEIVER;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -455,6 +459,7 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
|
|
|
boolean metadataExists = false;
|
|
|
String token = null;
|
|
|
+ Object object = null;
|
|
|
|
|
|
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProviderImpl(getContext());
|
|
|
String publicKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY);
|
|
@@ -466,6 +471,7 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
if (result != null) {
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
/***** E2E *****/
|
|
|
// Only on V2+: whenever we change something, increase counter
|
|
|
long counter = -1;
|
|
@@ -485,13 +491,7 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
|
|
|
// Update metadata
|
|
|
EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2();
|
|
|
-// kotlin.Pair<Boolean, DecryptedFolderMetadataFile> metadataPair =
|
|
|
-// encryptionUtilsV2.retrieveMetadata(parentFile,
|
|
|
-// client,
|
|
|
-// user,
|
|
|
-// mContext);
|
|
|
-
|
|
|
- Object object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
|
|
|
+ object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
|
|
|
if (object instanceof DecryptedFolderMetadataFileV1 decrypted && decrypted.getMetadata() != null) {
|
|
|
metadataExists = true;
|
|
|
}
|
|
@@ -703,13 +703,6 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
"",
|
|
|
arbitraryDataProvider,
|
|
|
user);
|
|
|
-
|
|
|
- // unlock
|
|
|
- result = EncryptionUtils.unlockFolderV1(parentFile, client, token);
|
|
|
-
|
|
|
- if (result.isSuccess()) {
|
|
|
- token = null;
|
|
|
- }
|
|
|
} else {
|
|
|
DecryptedFolderMetadataFile metadata = (DecryptedFolderMetadataFile) object;
|
|
|
encryptionUtilsV2.addFileToMetadata(
|
|
@@ -730,13 +723,6 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
mContext,
|
|
|
user,
|
|
|
getStorageManager());
|
|
|
-
|
|
|
- // unlock
|
|
|
- result = EncryptionUtils.unlockFolder(parentFile, client, token);
|
|
|
-
|
|
|
- if (result.isSuccess()) {
|
|
|
- token = null;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
encryptedTempFile.delete();
|
|
@@ -751,6 +737,7 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
result = new RemoteOperationResult(e);
|
|
|
} finally {
|
|
|
mUploadStarted.set(false);
|
|
|
+ sendRefreshFolderEventBroadcast();
|
|
|
|
|
|
if (fileLock != null) {
|
|
|
try {
|
|
@@ -768,6 +755,18 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
}
|
|
|
|
|
|
logResult(result, mFile.getStoragePath(), mFile.getRemotePath());
|
|
|
+
|
|
|
+ // Unlock must be done otherwise folder stays locked and user can't upload any file
|
|
|
+ RemoteOperationResult<Void> unlockFolderResult;
|
|
|
+ if (object instanceof DecryptedFolderMetadataFileV1) {
|
|
|
+ unlockFolderResult = EncryptionUtils.unlockFolderV1(parentFile, client, token);
|
|
|
+ } else {
|
|
|
+ unlockFolderResult = EncryptionUtils.unlockFolder(parentFile, client, token);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (unlockFolderResult != null && !unlockFolderResult.isSuccess()) {
|
|
|
+ result = unlockFolderResult;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (result.isSuccess()) {
|
|
@@ -776,17 +775,6 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
getStorageManager().saveConflict(mFile, mFile.getEtagInConflict());
|
|
|
}
|
|
|
|
|
|
- // unlock must be done always
|
|
|
- if (token != null) {
|
|
|
- RemoteOperationResult unlockFolderResult = EncryptionUtils.unlockFolder(parentFile,
|
|
|
- client,
|
|
|
- token);
|
|
|
-
|
|
|
- if (!unlockFolderResult.isSuccess()) {
|
|
|
- return unlockFolderResult;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// delete temporal file
|
|
|
if (temporalFile != null && temporalFile.exists() && !temporalFile.delete()) {
|
|
|
Log_OC.e(TAG, "Could not delete temporal file " + temporalFile.getAbsolutePath());
|
|
@@ -795,6 +783,11 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void sendRefreshFolderEventBroadcast() {
|
|
|
+ Intent intent = new Intent(REFRESH_FOLDER_EVENT_RECEIVER);
|
|
|
+ LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
|
|
|
+ }
|
|
|
+
|
|
|
private RemoteOperationResult checkConditions(File originalFile) {
|
|
|
RemoteOperationResult remoteOperationResult = null;
|
|
|
|