mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Checking Network Connection failed uploads
This commit is contained in:
parent
66ec45f633
commit
b6f8e93504
6 changed files with 322 additions and 201 deletions
|
@ -118,6 +118,8 @@
|
|||
<string name="uploader_upload_failed_ticker">Upload failed</string>
|
||||
<string name="uploader_upload_failed_content_single">Upload of %1$s could not be completed</string>
|
||||
<string name="uploader_upload_failed_credentials_error">Upload failed, you need to relogin</string>
|
||||
<string name="uploads_view_upload_status_failed_connection_error">Connection error</string>
|
||||
<string name="uploads_view_upload_status_failed_retry">Upload will be retried shortly</string>
|
||||
<string name="downloader_download_in_progress_ticker">Downloading …</string>
|
||||
<string name="downloader_download_in_progress_content">%1$d%% Downloading %2$s</string>
|
||||
<string name="downloader_download_succeeded_ticker">Download succeeded</string>
|
||||
|
|
|
@ -56,7 +56,6 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
|
|||
|
||||
private static final String TAG = OCFile.class.getSimpleName();
|
||||
|
||||
|
||||
private long mId;
|
||||
private long mParentId;
|
||||
private long mLength;
|
||||
|
|
|
@ -22,6 +22,8 @@ package com.owncloud.android.db;
|
|||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -38,7 +40,7 @@ import java.util.GregorianCalendar;
|
|||
* be stored persistently by {@link UploadsStorageManager}.
|
||||
*
|
||||
*/
|
||||
public class OCUpload {
|
||||
public class OCUpload implements Parcelable{
|
||||
|
||||
/** Generated - should be refreshed every time the class changes!! */
|
||||
// private static final long serialVersionUID = 2647551318657321611L;
|
||||
|
@ -336,4 +338,74 @@ public class OCUpload {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****
|
||||
* PARCELABLE METHODS
|
||||
*/
|
||||
public static final Parcelable.Creator<OCUpload> CREATOR = new Parcelable.Creator<OCUpload>() {
|
||||
|
||||
@Override
|
||||
public OCUpload createFromParcel(Parcel source) {
|
||||
return new OCUpload(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OCUpload[] newArray(int size) {
|
||||
return new OCUpload[size];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reconstruct from parcel
|
||||
*
|
||||
* @param source The source parcel
|
||||
*/
|
||||
protected OCUpload(Parcel source) {
|
||||
readFromParcel(source);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel source) {
|
||||
mId = source.readLong();
|
||||
mFile = source.readParcelable(OCFile.class.getClassLoader());
|
||||
mLocalAction = source.readInt();
|
||||
mForceOverwrite = source.readInt() == 0;
|
||||
mIsCreateRemoteFolder = source.readInt() == 0;
|
||||
mIsUseWifiOnly = source.readInt() == 0;
|
||||
mIsWhileChargingOnly = source.readInt() == 0;
|
||||
mUploadTimestamp = source.readLong();
|
||||
mAccountName = source.readString();
|
||||
try {
|
||||
mUploadStatus = UploadStatus.valueOf(source.readString());
|
||||
} catch (IllegalArgumentException x) {
|
||||
mUploadStatus = UploadStatus.UPLOAD_LATER;
|
||||
}
|
||||
try {
|
||||
mLastResult = UploadResult.valueOf(source.readString());
|
||||
} catch (IllegalArgumentException x) {
|
||||
mLastResult = UploadResult.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return this.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(mId);
|
||||
dest.writeParcelable(mFile, flags);
|
||||
dest.writeInt(mLocalAction);
|
||||
//dest.writeLong(mUploadTime);
|
||||
dest.writeInt(mForceOverwrite ? 1 : 0);
|
||||
dest.writeInt(mIsCreateRemoteFolder ? 1 : 0);
|
||||
dest.writeInt(mIsUseWifiOnly ? 1 : 0);
|
||||
dest.writeInt(mIsWhileChargingOnly ? 1 : 0);
|
||||
dest.writeLong(mUploadTimestamp);
|
||||
dest.writeString(mAccountName);
|
||||
dest.writeString(mUploadStatus.name());
|
||||
dest.writeString(((mLastResult == null) ? "" : mLastResult.name()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -504,19 +504,19 @@ public class FileOperationsHelper {
|
|||
getString(R.string.wait_a_moment));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Retry uploading a failed or cancelled upload with force.
|
||||
// */
|
||||
// public void retryUpload(OCUpload upload) {
|
||||
// Account account = mFileActivity.getAccount();
|
||||
// FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
|
||||
// if (uploaderBinder != null) {
|
||||
// upload.removeAllUploadRestrictions(); //only this object, upload DB stays untouched.
|
||||
// uploaderBinder.retry(account, upload);
|
||||
// } else {
|
||||
// Log_OC.w(TAG, "uploaderBinder not set. Cannot remove " + upload.getOCFile());
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Retry uploading a failed or cancelled upload with force.
|
||||
*/
|
||||
public void retryUpload(OCUpload upload) {
|
||||
Account account = mFileActivity.getAccount();
|
||||
FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
|
||||
if (uploaderBinder != null) {
|
||||
upload.removeAllUploadRestrictions(); //only this object, upload DB stays untouched.
|
||||
uploaderBinder.retry(account, upload);
|
||||
} else {
|
||||
Log_OC.w(TAG, "uploaderBinder not set. Cannot remove " + upload.getOCFile());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove upload from upload list.
|
||||
|
|
|
@ -112,15 +112,20 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
|
||||
public static final String KEY_MIME_TYPE = "MIME_TYPE";
|
||||
|
||||
// /**
|
||||
// * Call this Service with only this Intent key if all pending uploads are to be retried.
|
||||
// */
|
||||
// private static final String KEY_RETRY = "KEY_RETRY";
|
||||
/**
|
||||
* Call this Service with KEY_RETRY and KEY_RETRY_REMOTE_PATH to retry
|
||||
* download of file identified by KEY_RETRY_REMOTE_PATH.
|
||||
* Call this Service with only this Intent key if all pending uploads are to be retried.
|
||||
*/
|
||||
private static final String KEY_RETRY_REMOTE_PATH = "KEY_RETRY_REMOTE_PATH";
|
||||
private static final String KEY_RETRY = "KEY_RETRY";
|
||||
// /**
|
||||
// * Call this Service with KEY_RETRY and KEY_RETRY_REMOTE_PATH to retry
|
||||
// * upload of file identified by KEY_RETRY_REMOTE_PATH.
|
||||
// */
|
||||
// private static final String KEY_RETRY_REMOTE_PATH = "KEY_RETRY_REMOTE_PATH";
|
||||
/**
|
||||
* Call this Service with KEY_RETRY and KEY_RETRY_UPLOAD to retry
|
||||
* upload of file identified by KEY_RETRY_UPLOAD.
|
||||
*/
|
||||
private static final String KEY_RETRY_UPLOAD = "KEY_RETRY_UPLOAD";
|
||||
/**
|
||||
* {@link Account} to which file is to be uploaded.
|
||||
*/
|
||||
|
@ -267,7 +272,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
* server.
|
||||
* @return 'True' if the ownCloud server with version supports chunked
|
||||
* uploads.
|
||||
*
|
||||
* <p/>
|
||||
* TODO - move to OCClient
|
||||
*/
|
||||
private static boolean chunkedUploadIsSupported(OwnCloudVersion version) {
|
||||
|
@ -313,7 +318,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
*/
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log_OC.v(TAG, "Destroying service" );
|
||||
Log_OC.v(TAG, "Destroying service");
|
||||
mBinder = null;
|
||||
mServiceHandler = null;
|
||||
mServiceLooper.quit();
|
||||
|
@ -344,7 +349,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
|
||||
/**
|
||||
* Entry point to add one or several files to the queue of uploads.
|
||||
*
|
||||
* <p/>
|
||||
* New uploads are added calling to startService(), resulting in a call to
|
||||
* this method. This ensures the service will keep on working although the
|
||||
* caller activity goes away.
|
||||
|
@ -353,8 +358,24 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log_OC.d(TAG, "Starting command with id " + startId);
|
||||
|
||||
if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
|
||||
|| !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
|
||||
boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
|
||||
AbstractList<String> requestedUploads = new Vector<String>();
|
||||
|
||||
if (!intent.hasExtra(KEY_ACCOUNT)) {
|
||||
Log_OC.e(TAG, "Not enough information provided in intent");
|
||||
return Service.START_NOT_STICKY;
|
||||
|
||||
} else {
|
||||
Account account = intent.getParcelableExtra(KEY_ACCOUNT);
|
||||
if (!AccountUtils.exists(account, getApplicationContext())) {
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
|
||||
boolean chunked = FileUploadService.chunkedUploadIsSupported(ocv);
|
||||
|
||||
if (!retry) {
|
||||
if (!intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) ||
|
||||
intent.hasExtra(KEY_FILE))) {
|
||||
Log_OC.e(TAG, "Not enough information provided in intent");
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
@ -363,22 +384,18 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
Log_OC.e(TAG, "Incorrect upload type provided");
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
Account account = intent.getParcelableExtra(KEY_ACCOUNT);
|
||||
if (!AccountUtils.exists(account, getApplicationContext())) {
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
||||
String[] localPaths = null, remotePaths = null, mimeTypes = null;
|
||||
OCFile[] files = null;
|
||||
if (uploadType == UPLOAD_SINGLE_FILE) {
|
||||
|
||||
if (intent.hasExtra(KEY_FILE)) {
|
||||
files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };
|
||||
files = new OCFile[]{intent.getParcelableExtra(KEY_FILE)};
|
||||
|
||||
} else {
|
||||
localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
|
||||
remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
|
||||
mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
|
||||
localPaths = new String[]{intent.getStringExtra(KEY_LOCAL_FILE)};
|
||||
remotePaths = new String[]{intent.getStringExtra(KEY_REMOTE_FILE)};
|
||||
mimeTypes = new String[]{intent.getStringExtra(KEY_MIME_TYPE)};
|
||||
}
|
||||
|
||||
} else { // mUploadType == UPLOAD_MULTIPLE_FILES
|
||||
|
@ -444,10 +461,6 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
}
|
||||
// at this point variable "OCFile[] files" is loaded correctly.
|
||||
|
||||
OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
|
||||
|
||||
boolean chunked = FileUploadService.chunkedUploadIsSupported(ocv);
|
||||
AbstractList<String> requestedUploads = new Vector<String>();
|
||||
String uploadKey = null;
|
||||
UploadFileOperation newUpload = null;
|
||||
try {
|
||||
|
@ -503,6 +516,39 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
return START_NOT_STICKY;
|
||||
|
||||
}
|
||||
} else {
|
||||
if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_RETRY_UPLOAD) ) {
|
||||
Log_OC.e(TAG, "Not enough information provided in intent: no KEY_RETRY_UPLOAD_KEY");
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
|
||||
|
||||
UploadFileOperation newUpload = new UploadFileOperation(
|
||||
account,
|
||||
upload.getOCFile(),
|
||||
chunked,
|
||||
upload.isForceOverwrite(),
|
||||
upload.getLocalAction(),
|
||||
getApplicationContext()
|
||||
);
|
||||
if (upload.isCreateRemoteFolder()) {
|
||||
newUpload.setRemoteFolderToBeCreated();
|
||||
}
|
||||
newUpload.addDatatransferProgressListener(this);
|
||||
newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
|
||||
|
||||
Pair<String, String> putResult = mPendingUploads.putIfAbsent(
|
||||
account, upload.getOCFile().getRemotePath(), newUpload
|
||||
);
|
||||
if (putResult != null) {
|
||||
String uploadKey = putResult.first;
|
||||
requestedUploads.add(uploadKey);
|
||||
|
||||
// Update upload in database
|
||||
upload.setUploadStatus(UploadStatus.UPLOAD_LATER);
|
||||
mUploadsStorageManager.updateUpload(upload);
|
||||
}
|
||||
}
|
||||
|
||||
if (requestedUploads.size() > 0) {
|
||||
Message msg = mServiceHandler.obtainMessage();
|
||||
|
@ -512,6 +558,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
}
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAccountsUpdated(Account[] accounts) {
|
||||
|
@ -640,16 +688,16 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
}
|
||||
}
|
||||
|
||||
// // TODO: Review: Method from FileUploadService with some changes because the merge with FileUploader
|
||||
// // TODO Complete operation to retry the upload
|
||||
// /**
|
||||
// * Puts upload in upload list and tell FileUploadService to upload items in list.
|
||||
// */
|
||||
// public void retry(Account account, OCUpload upload) {
|
||||
// String uploadKey = buildRemoteName(upload);
|
||||
// //mPendingUploads.put(uploadKey, upload);
|
||||
// FileUploadService.retry(getApplicationContext(), uploadKey);
|
||||
// }
|
||||
// TODO: Review: Method from FileUploadService with some changes because the merge with FileUploader
|
||||
// TODO Complete operation to retry the upload
|
||||
/**
|
||||
* Puts upload in upload list and tell FileUploadService to upload items in list.
|
||||
*/
|
||||
public void retry(Account account, OCUpload upload) {
|
||||
String uploadKey = buildRemoteName(account, upload.getOCFile());
|
||||
// mPendingUploads.put(uploadKey, upload);
|
||||
FileUploadService.retry(getApplicationContext(), account, upload);
|
||||
}
|
||||
|
||||
public void clearListeners() {
|
||||
mBoundListeners.clear();
|
||||
|
@ -824,7 +872,6 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
|
||||
RemoteOperationResult uploadResult = null, grantResult;
|
||||
|
||||
|
||||
try {
|
||||
/// prepare client object to send the request to the ownCloud server
|
||||
if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentUpload.getAccount())) {
|
||||
|
@ -1905,24 +1952,25 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
|||
return CanUploadFileNowStatus.NOW;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Call if all pending uploads are to be retried.
|
||||
// */
|
||||
/**
|
||||
* Call if all pending uploads are to be retried.
|
||||
*/
|
||||
// public static void retry(Context context) {
|
||||
// retry(context, null);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Call to retry upload identified by remotePath
|
||||
// */
|
||||
// private static void retry(Context context, String remotePath) {
|
||||
// Log_OC.d(TAG, "FileUploadService.retry()");
|
||||
// Intent i = new Intent(context, FileUploadService.class);
|
||||
// i.putExtra(FileUploadService.KEY_RETRY, true);
|
||||
// if(remotePath != null) {
|
||||
// i.putExtra(FileUploadService.KEY_RETRY_REMOTE_PATH, remotePath);
|
||||
// }
|
||||
// context.startService(i);
|
||||
// }
|
||||
/**
|
||||
* Call to retry upload identified by remotePath
|
||||
*/
|
||||
private static void retry(Context context, Account account, OCUpload upload) {
|
||||
Log_OC.d(TAG, "FileUploadService.retry()");
|
||||
Intent i = new Intent(context, FileUploadService.class);
|
||||
i.putExtra(FileUploadService.KEY_RETRY, true);
|
||||
if(upload!= null) {
|
||||
i.putExtra(FileUploadService.KEY_ACCOUNT, account);
|
||||
i.putExtra(FileUploadService.KEY_RETRY_UPLOAD, upload);
|
||||
}
|
||||
context.startService(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -213,12 +213,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
|||
}
|
||||
break;
|
||||
case UPLOAD_FAILED_RETRY:
|
||||
// if(upload.getLastResult() != UploadResult.UNKNOWN){
|
||||
// status = "Last failure: "
|
||||
// + upload.getLastResult().toString();
|
||||
// } else {
|
||||
status = "Upload will be retried shortly.";
|
||||
// }
|
||||
if (upload.getLastResult() == UploadResult.NETWORK_CONNECTION) {
|
||||
status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_connection_error);
|
||||
} else {
|
||||
status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_retry);;
|
||||
}
|
||||
String laterReason = FileUploadService.getUploadLaterReason(mParentActivity, upload);
|
||||
if(laterReason != null) {
|
||||
//Upload failed once but is delayed now, show reason.
|
||||
|
@ -266,7 +265,8 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
|||
rightButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// mParentActivity.getFileOperationsHelper().retryUpload(upload);
|
||||
Log_OC.d(TAG, "Retry unpload CLICK");
|
||||
mParentActivity.getFileOperationsHelper().retryUpload(upload);
|
||||
}
|
||||
});
|
||||
} else if (upload.userCanCancelUpload()) {
|
||||
|
|
Loading…
Reference in a new issue