Skip to content

Commit

Permalink
Add new case in FileUploader to retry uploads delayed for wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
davigonz committed Nov 13, 2019
1 parent 221d246 commit 159ebc4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ private void wifiConnected(Context context) {
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected JobParameters doInBackground(JobParameters... jobParams) {
mCameraUploadsBehaviorAfterUpload = jobParams[0].getExtras().
getInt(Extras.EXTRA_CAMERA_UPLOADS_BEHAVIOR_AFTER_UPLOAD);

syncFiles(mCameraUploadsSyncJobService.getApplicationContext());
syncFiles();

return jobParams[0];
}
Expand All @@ -113,7 +113,7 @@ protected void onPostExecute(JobParameters jobParameters) {
/**
* Get local images and videos and start handling them
*/
private void syncFiles(Context context) {
private void syncFiles() {

//Get local images and videos
String localCameraPath = mCameraUploadsSourcePath;
Expand All @@ -134,10 +134,6 @@ private void syncFiles(Context context) {
}

Log_OC.d(TAG, "All files synced, finishing job");

// After scan of new files, we try to sync such files with waiting for Wifi as well
TransferRequester requester = new TransferRequester();
requester.retryFailedUploads(context, null, null, false);
}

private File[] orderFilesByCreationTimestamp(File[] localFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
KEY_REQUESTED_FROM_WIFI_BACK_EVENT, false
);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

if ((isCameraUploadFile || isAvailableOfflineFile || isRequestedFromWifiBackEvent) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log_OC.d(TAG, "Starting FileUploader service in foreground");
mNotificationBuilder
.setChannelId(UPLOAD_NOTIFICATION_CHANNEL_ID)
Expand Down Expand Up @@ -882,32 +882,42 @@ public void uploadFile(String uploadKey) {
);
}

if (!uploadResult.isSuccess() && uploadResult.getException() != null) {

// if failed due to lack of connectivity, schedule an automatic retry
if (!uploadResult.isSuccess()) {
TransferRequester requester = new TransferRequester();
if (requester.shouldScheduleRetry(this, uploadResult.getException())) {
int jobId = mPendingUploads.buildKey(
mCurrentAccount.name,
mCurrentUpload.getRemotePath()
).hashCode();
int jobId = mPendingUploads.buildKey(
mCurrentAccount.name,
mCurrentUpload.getRemotePath()
).hashCode();

if (uploadResult.getException() != null) {
// if failed due to lack of connectivity, schedule an automatic retry
if (requester.shouldScheduleRetry(this, uploadResult.getException())) {
requester.scheduleUpload(
this,
jobId,
mCurrentAccount.name,
mCurrentUpload.getRemotePath()
);
uploadResult = new RemoteOperationResult(
ResultCode.NO_NETWORK_CONNECTION);
} else {
Log_OC.v(
TAG,
String.format(
"Exception in upload, network is OK, no retry scheduled for %1s in %2s",
mCurrentUpload.getRemotePath(),
mCurrentAccount.name
)
);
}
} else if (uploadResult.getCode() == ResultCode.DELAYED_FOR_WIFI) {
// if failed due to the upload is delayed for wifi, schedule automatic retry as well
requester.scheduleUpload(
this,
jobId,
mCurrentAccount.name,
mCurrentUpload.getRemotePath()
);
uploadResult = new RemoteOperationResult(
ResultCode.NO_NETWORK_CONNECTION);
} else {
Log_OC.v(
TAG,
String.format(
"Exception in upload, network is OK, no retry scheduled for %1s in %2s",
mCurrentUpload.getRemotePath(),
mCurrentAccount.name
)
);
}
} else {
Log_OC.v(
Expand Down

0 comments on commit 159ebc4

Please sign in to comment.