Chunked upload

fix upload test: upload needs userId

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-01-11 13:13:57 +01:00
parent cea480a772
commit 22641967d2
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
4 changed files with 42 additions and 26 deletions

View file

@ -210,9 +210,9 @@ dependencies {
// dependencies for app building
implementation 'androidx.multidex:multidex:2.0.1'
// implementation project('nextcloud-android-library')
genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
genericImplementation 'com.github.nextcloud:android-library:tests-SNAPSHOT'
gplayImplementation 'com.github.nextcloud:android-library:tests-SNAPSHOT'
versionDevImplementation 'com.github.nextcloud:android-library:tests-SNAPSHOT'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'

View file

@ -52,6 +52,7 @@ public abstract class AbstractIT {
Integer.toString(com.owncloud.android.authentication.AccountUtils.ACCOUNT_VERSION));
accountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_VERSION, "14.0.0.0");
accountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "http://" + baseUrl);
accountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, username);
}
account = com.owncloud.android.authentication.AccountUtils.getOwnCloudAccountByName(context,

View file

@ -20,6 +20,7 @@
package com.owncloud.android.operations;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
@ -39,8 +40,9 @@ import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.db.OCUpload;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
import com.owncloud.android.lib.common.network.ProgressiveDataTransfer;
import com.owncloud.android.lib.common.operations.OperationCancelledException;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -128,7 +130,7 @@ public class UploadFileOperation extends SyncOperation {
* Local path to file which is to be uploaded (before any possible renaming or moving).
*/
private String mOriginalStoragePath;
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<>();
private final Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<>();
private OnRenameListener mRenameUploadListener;
private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
@ -138,7 +140,7 @@ public class UploadFileOperation extends SyncOperation {
private UploadFileRemoteOperation mUploadOperation;
protected RequestEntity mEntity;
private RequestEntity mEntity;
private Account mAccount;
private OCUpload mUpload;
@ -317,10 +319,10 @@ public class UploadFileOperation extends SyncOperation {
mDataTransferListeners.add(listener);
}
if (mEntity != null) {
((ProgressiveDataTransferer) mEntity).addDatatransferProgressListener(listener);
((ProgressiveDataTransfer) mEntity).addDataTransferProgressListener(listener);
}
if (mUploadOperation != null) {
mUploadOperation.addDatatransferProgressListener(listener);
mUploadOperation.addDataTransferProgressListener(listener);
}
}
@ -329,10 +331,10 @@ public class UploadFileOperation extends SyncOperation {
mDataTransferListeners.remove(listener);
}
if (mEntity != null) {
((ProgressiveDataTransferer) mEntity).removeDatatransferProgressListener(listener);
((ProgressiveDataTransfer) mEntity).removeDataTransferProgressListener(listener);
}
if (mUploadOperation != null) {
mUploadOperation.removeDatatransferProgressListener(listener);
mUploadOperation.removeDataTransferProgressListener(listener);
}
}
@ -575,10 +577,17 @@ public class UploadFileOperation extends SyncOperation {
}
/// perform the upload
if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE) {
mUploadOperation = new ChunkedFileUploadRemoteOperation(mContext, encryptedTempFile.getAbsolutePath(),
mFile.getParentRemotePath() + encryptedFileName, mFile.getMimeType(),
mFile.getEtagInConflict(), timeStamp);
if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE_MOBILE) {
String userId = AccountManager.get(getContext()).getUserData(getAccount(),
AccountUtils.Constants.KEY_USER_ID);
boolean onWifiConnection = ConnectivityUtils.isOnlineWithWifi(mContext);
mUploadOperation = new ChunkedFileUploadRemoteOperation(encryptedTempFile.getAbsolutePath(),
mFile.getParentRemotePath() + encryptedFileName,
mFile.getMimeType(), mFile.getEtagInConflict(),
timeStamp, userId, onWifiConnection);
} else {
mUploadOperation = new UploadFileRemoteOperation(encryptedTempFile.getAbsolutePath(),
mFile.getParentRemotePath() + encryptedFileName, mFile.getMimeType(),
@ -586,7 +595,7 @@ public class UploadFileOperation extends SyncOperation {
}
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
mUploadOperation.addDatatransferProgressListener(mDataTransferListener);
mUploadOperation.addDataTransferProgressListener(mDataTransferListener);
}
if (mCancellationRequested.get()) {
@ -818,16 +827,23 @@ public class UploadFileOperation extends SyncOperation {
}
// perform the upload
if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE) {
mUploadOperation = new ChunkedFileUploadRemoteOperation(mContext, mFile.getStoragePath(),
mFile.getRemotePath(), mFile.getMimeType(), mFile.getEtagInConflict(), timeStamp);
if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE_MOBILE) {
String userId = AccountManager.get(getContext()).getUserData(getAccount(),
AccountUtils.Constants.KEY_USER_ID);
boolean onWifiConnection = ConnectivityUtils.isOnlineWithWifi(mContext);
mUploadOperation = new ChunkedFileUploadRemoteOperation(mFile.getStoragePath(),
mFile.getRemotePath(), mFile.getMimeType(),
mFile.getEtagInConflict(),
timeStamp, userId, onWifiConnection);
} else {
mUploadOperation = new UploadFileRemoteOperation(mFile.getStoragePath(),
mFile.getRemotePath(), mFile.getMimeType(), mFile.getEtagInConflict(), timeStamp);
}
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
mUploadOperation.addDatatransferProgressListener(mDataTransferListener);
mUploadOperation.addDataTransferProgressListener(mDataTransferListener);
}
if (mCancellationRequested.get()) {
@ -998,7 +1014,7 @@ public class UploadFileOperation extends SyncOperation {
* will be uploaded.
*/
private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) {
RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, mContext, false);
RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, false);
RemoteOperationResult result = operation.execute(client, true);
if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) {
SyncOperation syncOp = new CreateFolderOperation(pathToGrant, true);
@ -1117,8 +1133,7 @@ public class UploadFileOperation extends SyncOperation {
return false;
} else {
ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext,
false);
ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, false);
RemoteOperationResult result = existsOperation.execute(client);
return result.isSuccess();
}

View file

@ -75,7 +75,7 @@ public final class ConnectivityUtils {
if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) {
return !(status == HttpStatus.SC_NO_CONTENT &&
(get.getResponseContentLength() == -1 || get.getResponseContentLength() == 0));
(get.getResponseContentLength() == -1 || get.getResponseContentLength() == 0));
} else {
if (status == HttpStatus.SC_OK) {
try {
@ -99,14 +99,14 @@ public final class ConnectivityUtils {
} catch (OperationCanceledException | AuthenticatorException e) {
Log_OC.e(TAG, e.getMessage());
}
} else if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY)) {
return false;
} else {
return Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY);
}
return true;
}
private static boolean isOnlineWithWifi(Context context) {
public static boolean isOnlineWithWifi(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();