mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Fix by Alper
Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
This commit is contained in:
parent
a9ff057fe0
commit
e850b67139
5 changed files with 83 additions and 33 deletions
|
@ -24,7 +24,9 @@ import com.nextcloud.model.WorkerStateLiveData
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager
|
||||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||||
|
import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus
|
||||||
import com.owncloud.android.db.OCUpload
|
import com.owncloud.android.db.OCUpload
|
||||||
|
import com.owncloud.android.db.UploadResult
|
||||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
|
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
|
||||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
|
||||||
|
@ -32,6 +34,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC
|
import com.owncloud.android.lib.common.utils.Log_OC
|
||||||
import com.owncloud.android.operations.UploadFileOperation
|
import com.owncloud.android.operations.UploadFileOperation
|
||||||
|
import com.owncloud.android.operations.UploadFileOperation.uploadedSourcePath
|
||||||
import com.owncloud.android.utils.ErrorMessageAdapter
|
import com.owncloud.android.utils.ErrorMessageAdapter
|
||||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -235,13 +238,32 @@ class FileUploadWorker(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, operation: UploadFileOperation) {
|
private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, operation: UploadFileOperation) {
|
||||||
|
if (operation.originalStoragePath == uploadedSourcePath) {
|
||||||
|
// TODO
|
||||||
|
// This is not ideal fix. When uploading file to the encrypted folder server returns 404 FILE_NOT_FOUND
|
||||||
|
// However file upload successfully completed. This fix mimic success, if upload successfully completed with
|
||||||
|
// receiving path
|
||||||
|
val localPath: String? =
|
||||||
|
if (LOCAL_BEHAVIOUR_MOVE == operation.localBehaviour) operation.storagePath else null
|
||||||
|
|
||||||
|
uploadsStorageManager.updateUploadStatus(
|
||||||
|
operation.ocUploadId,
|
||||||
|
UploadStatus.UPLOAD_SUCCEEDED,
|
||||||
|
UploadResult.UPLOADED,
|
||||||
|
operation.remotePath,
|
||||||
|
localPath
|
||||||
|
)
|
||||||
|
notificationManager.dismissOldErrorNotification(operation)
|
||||||
|
} else {
|
||||||
if (!(isStopped && result.isCancelled)) {
|
if (!(isStopped && result.isCancelled)) {
|
||||||
uploadsStorageManager.updateDatabaseUploadResult(result, operation)
|
uploadsStorageManager.updateDatabaseUploadResult(result, operation)
|
||||||
notifyUploadResult(operation, result)
|
notifyUploadResult(operation, result)
|
||||||
notificationManager.dismissWorkerNotifications()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notificationManager.dismissWorkerNotifications()
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("ReturnCount")
|
@Suppress("ReturnCount")
|
||||||
private fun notifyUploadResult(
|
private fun notifyUploadResult(
|
||||||
uploadFileOperation: UploadFileOperation,
|
uploadFileOperation: UploadFileOperation,
|
||||||
|
@ -288,17 +310,18 @@ class FileUploadWorker(
|
||||||
context.resources
|
context.resources
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME SYNC_CONFLICT passes wrong OCFile, check ConflictsResolveActivity.createIntent usage
|
|
||||||
val conflictResolveIntent = if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
|
val conflictResolveIntent = if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
|
||||||
intents.conflictResolveActionIntents(context, uploadFileOperation)
|
intents.conflictResolveActionIntents(context, uploadFileOperation)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
val credentialIntent: PendingIntent? = if (uploadResult.code == ResultCode.UNAUTHORIZED) {
|
val credentialIntent: PendingIntent? = if (uploadResult.code == ResultCode.UNAUTHORIZED) {
|
||||||
intents.credentialIntent(uploadFileOperation)
|
intents.credentialIntent(uploadFileOperation)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyForFailedResult(uploadResult.code, conflictResolveIntent, credentialIntent, errorMessage)
|
notifyForFailedResult(uploadResult.code, conflictResolveIntent, credentialIntent, errorMessage)
|
||||||
showNewNotification(uploadFileOperation)
|
showNewNotification(uploadFileOperation)
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,7 @@ public class UploadsStorageManager extends Observable {
|
||||||
* @param localPath path of the file to upload in the device storage
|
* @param localPath path of the file to upload in the device storage
|
||||||
* @return 1 if file status was updated, else 0.
|
* @return 1 if file status was updated, else 0.
|
||||||
*/
|
*/
|
||||||
private int updateUploadStatus(long id, UploadStatus status, UploadResult result, String remotePath,
|
public int updateUploadStatus(long id, UploadStatus status, UploadResult result, String remotePath,
|
||||||
String localPath) {
|
String localPath) {
|
||||||
//Log_OC.v(TAG, "Updating "+filepath+" with uploadStatus="+status +" and result="+result);
|
//Log_OC.v(TAG, "Updating "+filepath+" with uploadStatus="+status +" and result="+result);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ package com.owncloud.android.operations;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
@ -98,6 +99,9 @@ import javax.crypto.Cipher;
|
||||||
|
|
||||||
import androidx.annotation.CheckResult;
|
import androidx.annotation.CheckResult;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
import static com.owncloud.android.ui.activity.FileDisplayActivity.REFRESH_FOLDER_EVENT_RECEIVER;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -466,6 +470,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** E2E *****/
|
/***** E2E *****/
|
||||||
// Only on V2+: whenever we change something, increase counter
|
// Only on V2+: whenever we change something, increase counter
|
||||||
long counter = -1;
|
long counter = -1;
|
||||||
|
@ -485,12 +490,6 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
|
|
||||||
// Update metadata
|
// Update metadata
|
||||||
EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2();
|
EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2();
|
||||||
// kotlin.Pair<Boolean, DecryptedFolderMetadataFile> metadataPair =
|
|
||||||
// encryptionUtilsV2.retrieveMetadata(parentFile,
|
|
||||||
// client,
|
|
||||||
// user,
|
|
||||||
// mContext);
|
|
||||||
|
|
||||||
Object object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
|
Object object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
|
||||||
if (object instanceof DecryptedFolderMetadataFileV1 decrypted && decrypted.getMetadata() != null) {
|
if (object instanceof DecryptedFolderMetadataFileV1 decrypted && decrypted.getMetadata() != null) {
|
||||||
metadataExists = true;
|
metadataExists = true;
|
||||||
|
@ -706,10 +705,6 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
|
|
||||||
// unlock
|
// unlock
|
||||||
result = EncryptionUtils.unlockFolderV1(parentFile, client, token);
|
result = EncryptionUtils.unlockFolderV1(parentFile, client, token);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
|
||||||
token = null;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
DecryptedFolderMetadataFile metadata = (DecryptedFolderMetadataFile) object;
|
DecryptedFolderMetadataFile metadata = (DecryptedFolderMetadataFile) object;
|
||||||
encryptionUtilsV2.addFileToMetadata(
|
encryptionUtilsV2.addFileToMetadata(
|
||||||
|
@ -733,10 +728,6 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
|
|
||||||
// unlock
|
// unlock
|
||||||
result = EncryptionUtils.unlockFolder(parentFile, client, token);
|
result = EncryptionUtils.unlockFolder(parentFile, client, token);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
|
||||||
token = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptedTempFile.delete();
|
encryptedTempFile.delete();
|
||||||
|
@ -751,6 +742,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
} finally {
|
} finally {
|
||||||
mUploadStarted.set(false);
|
mUploadStarted.set(false);
|
||||||
|
sendRefreshFolderEventBroadcast();
|
||||||
|
|
||||||
if (fileLock != null) {
|
if (fileLock != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -768,6 +760,17 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
logResult(result, mFile.getStoragePath(), mFile.getRemotePath());
|
logResult(result, mFile.getStoragePath(), mFile.getRemotePath());
|
||||||
|
|
||||||
|
// unlock must be done always
|
||||||
|
if (token != null) {
|
||||||
|
RemoteOperationResult<Void> unlockFolderResult = EncryptionUtils.unlockFolder(parentFile,
|
||||||
|
client,
|
||||||
|
token);
|
||||||
|
|
||||||
|
if (!unlockFolderResult.isSuccess()) {
|
||||||
|
result = unlockFolderResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
|
@ -776,17 +779,6 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
getStorageManager().saveConflict(mFile, mFile.getEtagInConflict());
|
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
|
// delete temporal file
|
||||||
if (temporalFile != null && temporalFile.exists() && !temporalFile.delete()) {
|
if (temporalFile != null && temporalFile.exists() && !temporalFile.delete()) {
|
||||||
Log_OC.e(TAG, "Could not delete temporal file " + temporalFile.getAbsolutePath());
|
Log_OC.e(TAG, "Could not delete temporal file " + temporalFile.getAbsolutePath());
|
||||||
|
@ -795,6 +787,11 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendRefreshFolderEventBroadcast() {
|
||||||
|
Intent intent = new Intent(REFRESH_FOLDER_EVENT_RECEIVER);
|
||||||
|
LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
|
||||||
private RemoteOperationResult checkConditions(File originalFile) {
|
private RemoteOperationResult checkConditions(File originalFile) {
|
||||||
RemoteOperationResult remoteOperationResult = null;
|
RemoteOperationResult remoteOperationResult = null;
|
||||||
|
|
||||||
|
@ -1001,8 +998,11 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String uploadedSourcePath;
|
||||||
|
|
||||||
private void logResult(RemoteOperationResult result, String sourcePath, String targetPath) {
|
private void logResult(RemoteOperationResult result, String sourcePath, String targetPath) {
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
|
uploadedSourcePath = sourcePath;
|
||||||
Log_OC.i(TAG, "Upload of " + sourcePath + " to " + targetPath + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Upload of " + sourcePath + " to " + targetPath + ": " + result.getLogMessage());
|
||||||
} else {
|
} else {
|
||||||
if (result.getException() != null) {
|
if (result.getException() != null) {
|
||||||
|
|
|
@ -69,6 +69,7 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper;
|
||||||
import com.nextcloud.client.jobs.download.FileDownloadWorker;
|
import com.nextcloud.client.jobs.download.FileDownloadWorker;
|
||||||
import com.nextcloud.client.jobs.upload.FileUploadHelper;
|
import com.nextcloud.client.jobs.upload.FileUploadHelper;
|
||||||
import com.nextcloud.client.jobs.upload.FileUploadWorker;
|
import com.nextcloud.client.jobs.upload.FileUploadWorker;
|
||||||
|
import com.nextcloud.client.jobs.upload.UploadNotificationManager;
|
||||||
import com.nextcloud.client.media.PlayerServiceConnection;
|
import com.nextcloud.client.media.PlayerServiceConnection;
|
||||||
import com.nextcloud.client.network.ClientFactory;
|
import com.nextcloud.client.network.ClientFactory;
|
||||||
import com.nextcloud.client.network.ConnectivityService;
|
import com.nextcloud.client.network.ConnectivityService;
|
||||||
|
@ -229,6 +230,8 @@ public class FileDisplayActivity extends FileActivity
|
||||||
public static final String KEY_IS_SEARCH_OPEN = "IS_SEARCH_OPEN";
|
public static final String KEY_IS_SEARCH_OPEN = "IS_SEARCH_OPEN";
|
||||||
public static final String KEY_SEARCH_QUERY = "SEARCH_QUERY";
|
public static final String KEY_SEARCH_QUERY = "SEARCH_QUERY";
|
||||||
|
|
||||||
|
public static final String REFRESH_FOLDER_EVENT_RECEIVER = "REFRESH_FOLDER_EVENT";
|
||||||
|
|
||||||
private String searchQuery = "";
|
private String searchQuery = "";
|
||||||
private boolean searchOpen;
|
private boolean searchOpen;
|
||||||
|
|
||||||
|
@ -236,6 +239,7 @@ public class FileDisplayActivity extends FileActivity
|
||||||
private PlayerServiceConnection mPlayerConnection;
|
private PlayerServiceConnection mPlayerConnection;
|
||||||
private Optional<User> lastDisplayedUser = Optional.empty();
|
private Optional<User> lastDisplayedUser = Optional.empty();
|
||||||
private int menuItemId = -1;
|
private int menuItemId = -1;
|
||||||
|
|
||||||
@Inject AppPreferences preferences;
|
@Inject AppPreferences preferences;
|
||||||
|
|
||||||
@Inject AppInfo appInfo;
|
@Inject AppInfo appInfo;
|
||||||
|
@ -283,6 +287,7 @@ public class FileDisplayActivity extends FileActivity
|
||||||
|
|
||||||
initSyncBroadcastReceiver();
|
initSyncBroadcastReceiver();
|
||||||
observeWorkerState();
|
observeWorkerState();
|
||||||
|
registerRefreshFolderEventReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -2296,6 +2301,24 @@ public class FileDisplayActivity extends FileActivity
|
||||||
checkForNewDevVersionNecessary(getApplicationContext());
|
checkForNewDevVersionNecessary(getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerRefreshFolderEventReceiver() {
|
||||||
|
IntentFilter filter = new IntentFilter(REFRESH_FOLDER_EVENT_RECEIVER);
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(refreshFolderEventReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final BroadcastReceiver refreshFolderEventReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
syncAndUpdateFolder(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(refreshFolderEventReceiver);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRestart() {
|
protected void onRestart() {
|
||||||
super.onRestart();
|
super.onRestart();
|
||||||
|
|
|
@ -516,9 +516,13 @@ public final class EncryptionUtils {
|
||||||
new TypeToken<>() {
|
new TypeToken<>() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (v2 != null) {
|
||||||
if ("2.0".equals(v2.getVersion()) || "2".equals(v2.getVersion())) {
|
if ("2.0".equals(v2.getVersion()) || "2".equals(v2.getVersion())) {
|
||||||
return E2EVersion.V2_0;
|
return E2EVersion.V2_0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return E2EVersion.UNKNOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return E2EVersion.UNKNOWN;
|
return E2EVersion.UNKNOWN;
|
||||||
|
|
Loading…
Reference in a new issue