mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Implement retry of manual uploads
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
5227513daa
commit
7ac07ab08a
5 changed files with 45 additions and 71 deletions
|
@ -300,34 +300,6 @@ public class FileUploader extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retry a subset of all the stored failed uploads.
|
|
||||||
*
|
|
||||||
* @param context Caller {@link Context}
|
|
||||||
* @param account If not null, only failed uploads to this OC account will be retried; otherwise,
|
|
||||||
* uploads of all accounts will be retried.
|
|
||||||
* @param uploadResult If not null, only failed uploads with the result specified will be retried;
|
|
||||||
* otherwise, failed uploads due to any result will be retried.
|
|
||||||
*/
|
|
||||||
public void retryFailedUploads(Context context, Account account, UploadResult uploadResult) {
|
|
||||||
UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
|
|
||||||
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
|
||||||
Account currentAccount = null;
|
|
||||||
boolean resultMatch;
|
|
||||||
boolean accountMatch;
|
|
||||||
for ( OCUpload failedUpload: failedUploads) {
|
|
||||||
accountMatch = (account == null || account.name.equals(failedUpload.getAccountName()));
|
|
||||||
resultMatch = (uploadResult == null || uploadResult.equals(failedUpload.getLastResult()));
|
|
||||||
if (accountMatch && resultMatch) {
|
|
||||||
if (currentAccount == null ||
|
|
||||||
!currentAccount.name.equals(failedUpload.getAccountName())) {
|
|
||||||
currentAccount = failedUpload.getAccount(context);
|
|
||||||
}
|
|
||||||
retry(context, currentAccount, failedUpload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private implementation of retry.
|
* Private implementation of retry.
|
||||||
*
|
*
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class AutoUploadJob extends Job {
|
||||||
uploadBehaviour,
|
uploadBehaviour,
|
||||||
mimeType,
|
mimeType,
|
||||||
true, // create parent folder if not existent
|
true, // create parent folder if not existent
|
||||||
UploadFileOperation.CREATED_BY_USER,
|
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
|
||||||
requiresWifi,
|
requiresWifi,
|
||||||
requiresCharging
|
requiresCharging
|
||||||
);
|
);
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class FilesSyncJob extends Job {
|
||||||
bundle.putBoolean(AutoUploadJob.REQUIRES_CHARGING, needsCharging);
|
bundle.putBoolean(AutoUploadJob.REQUIRES_CHARGING, needsCharging);
|
||||||
|
|
||||||
new JobRequest.Builder(AutoUploadJob.TAG)
|
new JobRequest.Builder(AutoUploadJob.TAG)
|
||||||
.setExecutionWindow(30_000L, 80_000L)
|
.setExecutionWindow(10_000L, 10_000L)
|
||||||
.setRequiresCharging(needsCharging)
|
.setRequiresCharging(needsCharging)
|
||||||
.setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobRequest.NetworkType.UNMETERED :
|
.setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobRequest.NetworkType.UNMETERED :
|
||||||
JobRequest.NetworkType.CONNECTED)
|
JobRequest.NetworkType.CONNECTED)
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package com.owncloud.android.ui.activity;
|
package com.owncloud.android.ui.activity;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
@ -40,11 +39,9 @@ import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.owncloud.android.R;
|
import com.owncloud.android.R;
|
||||||
import com.owncloud.android.authentication.AccountUtils;
|
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||||
import com.owncloud.android.db.OCUpload;
|
import com.owncloud.android.db.OCUpload;
|
||||||
import com.owncloud.android.db.UploadResult;
|
|
||||||
import com.owncloud.android.files.services.FileUploader;
|
import com.owncloud.android.files.services.FileUploader;
|
||||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
|
@ -54,6 +51,7 @@ import com.owncloud.android.operations.CheckCurrentCredentialsOperation;
|
||||||
import com.owncloud.android.ui.fragment.UploadListFragment;
|
import com.owncloud.android.ui.fragment.UploadListFragment;
|
||||||
import com.owncloud.android.utils.AnalyticsUtils;
|
import com.owncloud.android.utils.AnalyticsUtils;
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
|
import com.owncloud.android.utils.FilesSyncHelper;
|
||||||
import com.owncloud.android.utils.MimeTypeUtil;
|
import com.owncloud.android.utils.MimeTypeUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -221,17 +219,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == FileActivity.REQUEST_CODE__UPDATE_CREDENTIALS && resultCode == RESULT_OK) {
|
if (requestCode == FileActivity.REQUEST_CODE__UPDATE_CREDENTIALS && resultCode == RESULT_OK) {
|
||||||
// Retry uploads of the updated account
|
FilesSyncHelper.restartJobsIfNeeded();
|
||||||
Account account = AccountUtils.getOwnCloudAccountByName(
|
|
||||||
this,
|
|
||||||
data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME)
|
|
||||||
);
|
|
||||||
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
|
|
||||||
requester.retryFailedUploads(
|
|
||||||
this,
|
|
||||||
account,
|
|
||||||
UploadResult.CREDENTIAL_ERROR
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,8 +240,7 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// already updated -> just retry!
|
// already updated -> just retry!
|
||||||
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
|
FilesSyncHelper.restartJobsIfNeeded();
|
||||||
requester.retryFailedUploads(this, account, UploadResult.CREDENTIAL_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -43,7 +43,9 @@ import com.owncloud.android.datamodel.SyncedFolderProvider;
|
||||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||||
import com.owncloud.android.db.OCUpload;
|
import com.owncloud.android.db.OCUpload;
|
||||||
import com.owncloud.android.db.UploadResult;
|
import com.owncloud.android.db.UploadResult;
|
||||||
|
import com.owncloud.android.files.services.FileUploader;
|
||||||
import com.owncloud.android.jobs.AutoUploadJob;
|
import com.owncloud.android.jobs.AutoUploadJob;
|
||||||
|
import com.owncloud.android.operations.UploadFileOperation;
|
||||||
|
|
||||||
import org.lukhnos.nnio.file.FileVisitResult;
|
import org.lukhnos.nnio.file.FileVisitResult;
|
||||||
import org.lukhnos.nnio.file.Files;
|
import org.lukhnos.nnio.file.Files;
|
||||||
|
@ -190,6 +192,8 @@ public class FilesSyncHelper {
|
||||||
final Context context = MainApp.getAppContext();
|
final Context context = MainApp.getAppContext();
|
||||||
boolean restartedInCurrentIteration = false;
|
boolean restartedInCurrentIteration = false;
|
||||||
|
|
||||||
|
FileUploader.UploadRequester uploadRequester = new FileUploader.UploadRequester();
|
||||||
|
|
||||||
for (JobRequest jobRequest : JobManager.instance().getAllJobRequestsForTag(AutoUploadJob.TAG)) {
|
for (JobRequest jobRequest : JobManager.instance().getAllJobRequestsForTag(AutoUploadJob.TAG)) {
|
||||||
restartedInCurrentIteration = false;
|
restartedInCurrentIteration = false;
|
||||||
// Handle case of charging
|
// Handle case of charging
|
||||||
|
@ -222,36 +226,47 @@ public class FilesSyncHelper {
|
||||||
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
||||||
|
|
||||||
boolean accountExists;
|
boolean accountExists;
|
||||||
|
boolean fileExists;
|
||||||
for (OCUpload failedUpload: failedUploads) {
|
for (OCUpload failedUpload: failedUploads) {
|
||||||
accountExists = false;
|
accountExists = false;
|
||||||
if (!failedUpload.getLastResult().equals(UploadResult.UPLOADED)) {
|
fileExists = new File(failedUpload.getLocalPath()).exists();
|
||||||
uploadsStorageManager.removeUpload(failedUpload);
|
|
||||||
|
|
||||||
// check if accounts still exists
|
// check if accounts still exists
|
||||||
for (Account account : AccountUtils.getAccounts(context)) {
|
for (Account account : AccountUtils.getAccounts(context)) {
|
||||||
if (account.name.equals(failedUpload.getAccountName())) {
|
if (account.name.equals(failedUpload.getAccountName())) {
|
||||||
accountExists = true;
|
accountExists = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!failedUpload.getLastResult().equals(UploadResult.UPLOADED)) {
|
||||||
|
if (failedUpload.getCreadtedBy() == UploadFileOperation.CREATED_AS_INSTANT_PICTURE) {
|
||||||
|
uploadsStorageManager.removeUpload(failedUpload);
|
||||||
|
|
||||||
|
if (accountExists && fileExists) {
|
||||||
|
PersistableBundleCompat bundle = new PersistableBundleCompat();
|
||||||
|
bundle.putString(AutoUploadJob.LOCAL_PATH, failedUpload.getLocalPath());
|
||||||
|
bundle.putString(AutoUploadJob.REMOTE_PATH, failedUpload.getRemotePath());
|
||||||
|
bundle.putString(AutoUploadJob.ACCOUNT, failedUpload.getAccountName());
|
||||||
|
bundle.putInt(AutoUploadJob.UPLOAD_BEHAVIOUR, failedUpload.getLocalAction());
|
||||||
|
|
||||||
|
new JobRequest.Builder(AutoUploadJob.TAG)
|
||||||
|
.setExecutionWindow(10_000L, 10_000L)
|
||||||
|
.setRequiresCharging(failedUpload.isWhileChargingOnly())
|
||||||
|
.setRequiredNetworkType(failedUpload.isUseWifiOnly() ? JobRequest.NetworkType.UNMETERED :
|
||||||
|
JobRequest.NetworkType.CONNECTED)
|
||||||
|
.setExtras(bundle)
|
||||||
|
.setRequirementsEnforced(true)
|
||||||
|
.setUpdateCurrent(false)
|
||||||
|
.build()
|
||||||
|
.schedule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (accountExists) {
|
if (accountExists && fileExists) {
|
||||||
PersistableBundleCompat bundle = new PersistableBundleCompat();
|
uploadRequester.retry(context, failedUpload);
|
||||||
bundle.putString(AutoUploadJob.LOCAL_PATH, failedUpload.getLocalPath());
|
} else {
|
||||||
bundle.putString(AutoUploadJob.REMOTE_PATH, failedUpload.getRemotePath());
|
uploadsStorageManager.removeUpload(failedUpload);
|
||||||
bundle.putString(AutoUploadJob.ACCOUNT, failedUpload.getAccountName());
|
|
||||||
bundle.putInt(AutoUploadJob.UPLOAD_BEHAVIOUR, failedUpload.getLocalAction());
|
|
||||||
|
|
||||||
new JobRequest.Builder(AutoUploadJob.TAG)
|
|
||||||
.setExecutionWindow(30_000L, 80_000L)
|
|
||||||
.setRequiresCharging(failedUpload.isWhileChargingOnly())
|
|
||||||
.setRequiredNetworkType(failedUpload.isUseWifiOnly() ? JobRequest.NetworkType.UNMETERED :
|
|
||||||
JobRequest.NetworkType.CONNECTED)
|
|
||||||
.setExtras(bundle)
|
|
||||||
.setRequirementsEnforced(true)
|
|
||||||
.setUpdateCurrent(false)
|
|
||||||
.build()
|
|
||||||
.schedule();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue