Search in sources :

Example 1 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.

the class SynchronizeFolderOperation method isBlockedForAutomatedSync.

/**
 * Checks the last upload of a file and determines if automated synchronization needs to wait for
 * user action or not.
 *
 * @param file ownCloud file to check.
 * @return 'True' if the received file should not be automatically synced due to a previous
 * upload error that requires an user action.
 */
private boolean isBlockedForAutomatedSync(OCFile file) {
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver());
    OCUpload failedUpload = uploadsStorageManager.getLastUploadFor(file, mAccount.name);
    if (failedUpload != null) {
        switch(failedUpload.getLastResult()) {
            case CREDENTIAL_ERROR:
            case FOLDER_ERROR:
            case FILE_NOT_FOUND:
            case FILE_ERROR:
            case PRIVILEGES_ERROR:
            case CONFLICT_ERROR:
                return true;
        }
    }
    return false;
}
Also used : OCUpload(com.owncloud.android.datamodel.OCUpload) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager)

Example 2 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.

the class TransferRequester method retryFailedUploads.

/**
 * 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.
 * @param requestedFromWifiBackEvent true if the retry was requested because wifi connection was back,
 *                                   false otherwise
 */
public void retryFailedUploads(Context context, Account account, UploadResult uploadResult, boolean requestedFromWifiBackEvent) {
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver());
    OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
    Account currentAccount = null;
    boolean resultMatch, 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, requestedFromWifiBackEvent);
        }
    }
}
Also used : Account(android.accounts.Account) OCUpload(com.owncloud.android.datamodel.OCUpload) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager)

Example 3 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.

the class RetryUploadJobService method onStartJob.

@Override
public boolean onStartJob(JobParameters jobParameters) {
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(getContentResolver());
    String fileRemotePath = jobParameters.getExtras().getString(Extras.EXTRA_REMOTE_PATH);
    String accountName = jobParameters.getExtras().getString(Extras.EXTRA_ACCOUNT_NAME);
    Timber.d("Retrying upload of %1s in %2s", fileRemotePath, accountName);
    // Get upload to be retried
    OCUpload ocUpload = uploadsStorageManager.getLastUploadFor(new OCFile(fileRemotePath), accountName);
    if (ocUpload != null) {
        // Retry the upload
        TransferRequester requester = new TransferRequester();
        requester.retry(this, ocUpload, true);
    } else {
        // easy if the user deletes the upload in uploads view before recovering network
        Timber.w("No upload found in database for %1s in %2s", fileRemotePath, accountName);
    }
    // done here, real job was delegated to another castle
    jobFinished(jobParameters, false);
    // TODO or false? what is the real effect, Google!?!?!?!?
    return true;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.datamodel.OCUpload) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager)

Example 4 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.

the class UploadListFragment method onClick.

@Override
public void onClick(OptionsInUploadList option) {
    UploadsStorageManager storageManager;
    switch(option) {
        case RETRY_FAILED:
            TransferRequester requester = new TransferRequester();
            requester.retryFailedUploads(requireContext(), null, null, false);
            break;
        case CLEAR_FAILED:
            storageManager = new UploadsStorageManager(requireActivity().getContentResolver());
            storageManager.clearFailedButNotDelayedForWifiUploads();
            break;
        case CLEAR_SUCCESSFUL:
            storageManager = new UploadsStorageManager(requireActivity().getContentResolver());
            storageManager.clearSuccessfulUploads();
            break;
    }
    updateUploads();
}
Also used : TransferRequester(com.owncloud.android.files.services.TransferRequester) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager)

Example 5 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by nextcloud.

the class AbstractIT method uploadOCUpload.

public void uploadOCUpload(OCUpload ocUpload) {
    ConnectivityService connectivityServiceMock = new ConnectivityService() {

        @Override
        public boolean isInternetWalled() {
            return false;
        }

        @Override
        public Connectivity getConnectivity() {
            return Connectivity.CONNECTED_WIFI;
        }
    };
    PowerManagementService powerManagementServiceMock = new PowerManagementService() {

        @NonNull
        @Override
        public BatteryStatus getBattery() {
            return new BatteryStatus();
        }

        @Override
        public boolean isPowerSavingEnabled() {
            return false;
        }

        @Override
        public boolean isPowerSavingExclusionAvailable() {
            return false;
        }
    };
    UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(accountManager, targetContext.getContentResolver());
    UploadFileOperation newUpload = new UploadFileOperation(uploadsStorageManager, connectivityServiceMock, powerManagementServiceMock, user, null, ocUpload, NameCollisionPolicy.DEFAULT, FileUploader.LOCAL_BEHAVIOUR_COPY, targetContext, false, false, getStorageManager());
    newUpload.addRenameUploadListener(() -> {
    // dummy
    });
    newUpload.setRemoteFolderToBeCreated();
    RemoteOperationResult result = newUpload.execute(client);
    assertTrue(result.getLogMessage(), result.isSuccess());
}
Also used : UserAccountManager(com.nextcloud.client.account.UserAccountManager) ConnectivityService(com.nextcloud.client.network.ConnectivityService) PowerManagementService(com.nextcloud.client.device.PowerManagementService) BatteryStatus(com.nextcloud.client.device.BatteryStatus) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager) UploadFileOperation(com.owncloud.android.operations.UploadFileOperation)

Aggregations

UploadsStorageManager (com.owncloud.android.datamodel.UploadsStorageManager)12 OCUpload (com.owncloud.android.datamodel.OCUpload)4 Account (android.accounts.Account)3 OCFile (com.owncloud.android.datamodel.OCFile)3 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 UserAccountManager (com.nextcloud.client.account.UserAccountManager)2 BatteryStatus (com.nextcloud.client.device.BatteryStatus)2 PowerManagementService (com.nextcloud.client.device.PowerManagementService)2 ConnectivityService (com.nextcloud.client.network.ConnectivityService)2 FileUploader (com.owncloud.android.files.services.FileUploader)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)2 File (java.io.File)2 HandlerThread (android.os.HandlerThread)1 NonNull (android.support.annotation.NonNull)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)1 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1