use of com.owncloud.android.datamodel.OCUpload 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;
}
use of com.owncloud.android.datamodel.OCUpload 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);
}
}
}
use of com.owncloud.android.datamodel.OCUpload in project android by owncloud.
the class FileUploader method onStartCommand.
/**
* 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.
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Timber.d("Starting command with id %s", startId);
int createdBy = intent.getIntExtra(KEY_CREATED_BY, UploadFileOperation.CREATED_BY_USER);
boolean isCameraUploadFile = createdBy == CREATED_AS_CAMERA_UPLOAD_PICTURE || createdBy == CREATED_AS_CAMERA_UPLOAD_VIDEO;
boolean isAvailableOfflineFile = intent.getBooleanExtra(KEY_IS_AVAILABLE_OFFLINE_FILE, false);
boolean isRequestedFromWifiBackEvent = intent.getBooleanExtra(KEY_REQUESTED_FROM_WIFI_BACK_EVENT, false);
if ((isCameraUploadFile || isAvailableOfflineFile || isRequestedFromWifiBackEvent) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Timber.d("Starting FileUploader service in foreground");
if (isCameraUploadFile) {
mNotificationBuilder.setContentTitle(getString(R.string.uploader_upload_camera_upload_files));
} else if (isAvailableOfflineFile) {
mNotificationBuilder.setContentTitle(getString(R.string.uploader_upload_available_offline_files));
} else if (isRequestedFromWifiBackEvent) {
mNotificationBuilder.setContentTitle(getString(R.string.uploader_upload_requested_from_wifi_files));
}
/*
* After calling startForegroundService method from {@link TransferRequester} for camera uploads or
* available offline, we have to call this within five seconds after the service is created to avoid
* an error
*/
startForeground(141, mNotificationBuilder.build());
}
boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
AbstractList<String> requestedUploads = new Vector<>();
if (!intent.hasExtra(KEY_ACCOUNT)) {
Timber.e("Not enough information provided in intent");
return Service.START_NOT_STICKY;
}
Account account = intent.getParcelableExtra(KEY_ACCOUNT);
Timber.d("Account to upload the file to: %s", account);
if (account == null || !AccountUtils.exists(account.name, getApplicationContext())) {
return Service.START_NOT_STICKY;
}
if (!retry) {
if (!(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
Timber.e("Not enough information provided in intent");
return Service.START_NOT_STICKY;
}
String[] localPaths = null, remotePaths = null, mimeTypes = null;
OCFile[] files = null;
if (intent.hasExtra(KEY_FILE)) {
Parcelable[] files_temp = intent.getParcelableArrayExtra(KEY_FILE);
files = new OCFile[files_temp.length];
System.arraycopy(files_temp, 0, files, 0, files_temp.length);
} else {
localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
}
boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
if (intent.hasExtra(KEY_FILE) && files == null) {
Timber.e("Incorrect array for OCFiles provided in upload intent");
return Service.START_NOT_STICKY;
} else if (!intent.hasExtra(KEY_FILE)) {
if (localPaths == null) {
Timber.e("Incorrect array for local paths provided in upload intent");
return Service.START_NOT_STICKY;
}
if (remotePaths == null) {
Timber.e("Incorrect array for remote paths provided in upload intent");
return Service.START_NOT_STICKY;
}
if (localPaths.length != remotePaths.length) {
Timber.e("Different number of remote paths and local paths!");
return Service.START_NOT_STICKY;
}
files = new OCFile[localPaths.length];
for (int i = 0; i < localPaths.length; i++) {
files[i] = UploadFileOperation.obtainNewOCFileToUpload(remotePaths[i], localPaths[i], ((mimeTypes != null) ? mimeTypes[i] : null), getApplicationContext());
if (files[i] == null) {
Timber.e("obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i] + " and localPaths[i]:" + localPaths[i]);
return Service.START_NOT_STICKY;
}
}
}
// at this point variable "OCFile[] files" is loaded correctly.
String uploadKey;
UploadFileOperation newUploadFileOperation;
try {
FileDataStorageManager storageManager = new FileDataStorageManager(getApplicationContext(), account, getContentResolver());
OCCapability capabilitiesForAccount = storageManager.getCapability(account.name);
boolean isChunkingAllowed = capabilitiesForAccount != null && capabilitiesForAccount.isChunkingAllowed();
Timber.d("Chunking is allowed: %s", isChunkingAllowed);
for (OCFile ocFile : files) {
OCUpload ocUpload = new OCUpload(ocFile, account);
ocUpload.setFileSize(ocFile.getFileLength());
ocUpload.setForceOverwrite(forceOverwrite);
ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
ocUpload.setCreatedBy(createdBy);
ocUpload.setLocalAction(localAction);
/*ocUpload.setUseWifiOnly(isUseWifiOnly);
ocUpload.setWhileChargingOnly(isWhileChargingOnly);*/
ocUpload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
if (new File(ocFile.getStoragePath()).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE && isChunkingAllowed) {
ocUpload.setTransferId(SecurityUtils.stringToMD5Hash(ocFile.getRemotePath()) + System.currentTimeMillis());
newUploadFileOperation = new ChunkedUploadFileOperation(account, ocFile, ocUpload, forceOverwrite, localAction, this);
} else {
newUploadFileOperation = new UploadFileOperation(account, ocFile, ocUpload, forceOverwrite, localAction, this);
}
newUploadFileOperation.setCreatedBy(createdBy);
if (isCreateRemoteFolder) {
newUploadFileOperation.setRemoteFolderToBeCreated();
}
newUploadFileOperation.addDatatransferProgressListener(this);
newUploadFileOperation.addDatatransferProgressListener((FileUploaderBinder) mBinder);
newUploadFileOperation.addRenameUploadListener(this);
Pair<String, String> putResult = mPendingUploads.putIfAbsent(account.name, ocFile.getRemotePath(), newUploadFileOperation);
if (putResult != null) {
uploadKey = putResult.first;
requestedUploads.add(uploadKey);
// Save upload in database
long id = mUploadsStorageManager.storeUpload(ocUpload);
newUploadFileOperation.setOCUploadId(id);
}
}
} catch (IllegalArgumentException e) {
Timber.e(e, "Not enough information provided in intent: %s", e.getMessage());
return START_NOT_STICKY;
} catch (IllegalStateException e) {
Timber.e(e, "Bad information provided in intent: %s", e.getMessage());
return START_NOT_STICKY;
} catch (Exception e) {
Timber.e(e, "Unexpected exception while processing upload intent");
return START_NOT_STICKY;
}
// *** TODO REWRITE: block inserted to request A retry; too many code copied, no control exception ***/
} else {
if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_RETRY_UPLOAD)) {
Timber.e("Not enough information provided in intent: no KEY_RETRY_UPLOAD_KEY");
return START_NOT_STICKY;
}
OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
UploadFileOperation newUploadFileOperation;
if (upload.getFileSize() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE) {
upload.setTransferId(SecurityUtils.stringToMD5Hash(upload.getRemotePath()) + System.currentTimeMillis());
newUploadFileOperation = new ChunkedUploadFileOperation(account, null, upload, upload.isForceOverwrite(), upload.getLocalAction(), this);
} else {
newUploadFileOperation = new UploadFileOperation(account, null, upload, upload.isForceOverwrite(), upload.getLocalAction(), this);
}
newUploadFileOperation.addDatatransferProgressListener(this);
newUploadFileOperation.addDatatransferProgressListener((FileUploaderBinder) mBinder);
newUploadFileOperation.addRenameUploadListener(this);
Pair<String, String> putResult = mPendingUploads.putIfAbsent(account.name, upload.getRemotePath(), newUploadFileOperation);
if (putResult != null) {
String uploadKey = putResult.first;
requestedUploads.add(uploadKey);
// Update upload in database
upload.setUploadStatus(UploadStatus.UPLOAD_IN_PROGRESS);
mUploadsStorageManager.updateUpload(upload);
}
}
if (requestedUploads.size() > 0) {
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = requestedUploads;
mServiceHandler.sendMessage(msg);
sendBroadcastUploadsAdded();
}
return Service.START_NOT_STICKY;
}
use of com.owncloud.android.datamodel.OCUpload 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;
}
use of com.owncloud.android.datamodel.OCUpload in project android by owncloud.
the class UploadListFragment method onChildClick.
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
boolean handled = false;
OCUpload OCUpload = (OCUpload) mAdapter.getChild(groupPosition, childPosition);
if (OCUpload != null) {
// notify the click to container Activity
handled = mContainerActivity.onUploadItemClick(OCUpload);
} else {
Timber.w("Null object in ListAdapter!!");
}
return handled;
}
Aggregations