When retrying failing uploads, delay connectivity check until last possible moment

This avoids network calls if the uploads can't be done for other reason (such as missing files)

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-06-28 11:25:06 +02:00 committed by tobiasKaminsky
parent a62373efb4
commit c8aa577589
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 5 additions and 4 deletions

View file

@ -675,7 +675,7 @@ public class FileUploader extends Service
/**
* Convert current account to user. This is a temporary workaround until
* service is migrated to new user model.
*
*
* @return Optional {@link User}
*/
private Optional<User> getCurrentUser() {
@ -1075,7 +1075,7 @@ public class FileUploader extends Service
}
final Connectivity connectivity = connectivityService.getConnectivity();
final boolean gotNetwork = connectivity.isConnected() && !connectivityService.isInternetWalled();
final boolean gotNetwork = connectivity.isConnected();
final boolean gotWifi = connectivity.isWifi();
final BatteryStatus batteryStatus = powerManagementService.getBattery();
final boolean charging = batteryStatus.isCharging() || batteryStatus.isFull();
@ -1094,7 +1094,8 @@ public class FileUploader extends Service
failedUpload.setLastResult(UploadResult.FILE_NOT_FOUND);
uploadsStorageManager.updateUpload(failedUpload);
}
} else if (!isPowerSaving && gotNetwork && canUploadBeRetried(failedUpload, gotWifi, charging)) {
} else if (!isPowerSaving && gotNetwork &&
canUploadBeRetried(failedUpload, gotWifi, charging) && !connectivityService.isInternetWalled()) {
// 2B. for existing local files, try restarting it if possible
retryUpload(context, uploadUser.get(), failedUpload);
}

View file

@ -236,7 +236,7 @@ public final class FilesSyncHelper {
}
new Thread(() -> {
if (connectivityService.getConnectivity().isConnected() && !connectivityService.isInternetWalled()) {
if (connectivityService.getConnectivity().isConnected()) {
FileUploader.retryFailedUploads(
context,
uploadsStorageManager,