Skip to content

Commit

Permalink
Merge pull request #2679 from owncloud/AttemptToFixUpload
Browse files Browse the repository at this point in the history
[Camera Uploads] Sync/Upload for older file, which waits for WiFi too
  • Loading branch information
davigonz authored Nov 21, 2019
2 parents 66e8e25 + 6b516b3 commit 9d123cc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 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 @@ -45,8 +45,6 @@
import java.util.Date;
import java.util.Locale;

import androidx.annotation.RequiresApi;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class CameraUploadsSyncJobService extends JobService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
* fatal error occured.
* <p>
* Every file passed to this service is uploaded. No filtering is performed.
* However, Intent keys (e.g., KEY_WIFI_ONLY) are obeyed.
*/
public class FileUploader extends Service
implements OnDatatransferProgressListener, OnAccountsUpdateListener,
Expand Down Expand Up @@ -292,7 +291,6 @@ public int onStartCommand(Intent intent, int flags, int startId) {

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 @@ -884,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 9d123cc

Please sign in to comment.