mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 10:18:59 +03:00
Merge pull request #7892 from tomaszduda23/master
Reduce number of calls to /index.php/204 if there is nothing to do.
This commit is contained in:
commit
2d087215de
3 changed files with 43 additions and 5 deletions
|
@ -1062,6 +1062,12 @@ public class FileUploader extends Service
|
|||
@Nullable final UploadResult uploadResult
|
||||
) {
|
||||
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
||||
if(failedUploads.length == 0)
|
||||
{
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
Account currentAccount = null;
|
||||
boolean resultMatch;
|
||||
boolean accountMatch;
|
||||
|
|
|
@ -690,11 +690,6 @@ public class UploadFileOperation extends SyncOperation {
|
|||
private RemoteOperationResult checkConditions(File originalFile) {
|
||||
RemoteOperationResult remoteOperationResult = null;
|
||||
|
||||
// check that internet is not behind walled garden
|
||||
if (!connectivityService.getConnectivity().isConnected() || connectivityService.isInternetWalled()) {
|
||||
remoteOperationResult = new RemoteOperationResult(ResultCode.NO_NETWORK_CONNECTION);
|
||||
}
|
||||
|
||||
// check that connectivity conditions are met and delays the upload otherwise
|
||||
Connectivity connectivity = connectivityService.getConnectivity();
|
||||
if (mOnWifiOnly && (!connectivity.isWifi() || connectivity.isMetered())) {
|
||||
|
@ -721,6 +716,11 @@ public class UploadFileOperation extends SyncOperation {
|
|||
remoteOperationResult = new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// check that internet is not behind walled garden
|
||||
if (!connectivityService.getConnectivity().isConnected() || connectivityService.isInternetWalled()) {
|
||||
remoteOperationResult = new RemoteOperationResult(ResultCode.NO_NETWORK_CONNECTION);
|
||||
}
|
||||
|
||||
return remoteOperationResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import android.provider.MediaStore;
|
|||
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.BatteryStatus;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
|
@ -185,10 +186,20 @@ public final class FilesSyncHelper {
|
|||
|
||||
boolean accountExists;
|
||||
|
||||
boolean whileChargingOnly = true;
|
||||
boolean useWifiOnly = true;
|
||||
|
||||
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
||||
|
||||
for (OCUpload failedUpload : failedUploads) {
|
||||
accountExists = false;
|
||||
if(!failedUpload.isWhileChargingOnly()){
|
||||
whileChargingOnly = false;
|
||||
}
|
||||
if(!failedUpload.isUseWifiOnly())
|
||||
{
|
||||
useWifiOnly = false;
|
||||
}
|
||||
|
||||
// check if accounts still exists
|
||||
for (Account account : accountManager.getAccounts()) {
|
||||
|
@ -203,6 +214,27 @@ public final class FilesSyncHelper {
|
|||
}
|
||||
}
|
||||
|
||||
failedUploads = uploadsStorageManager.getFailedUploads();
|
||||
if(failedUploads.length == 0)
|
||||
{
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
if(whileChargingOnly){
|
||||
final BatteryStatus batteryStatus = powerManagementService.getBattery();
|
||||
final boolean charging = batteryStatus.isCharging() || batteryStatus.isFull();
|
||||
if(!charging){
|
||||
//all uploads requires charging
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (useWifiOnly && !connectivityService.getConnectivity().isWifi()){
|
||||
//all uploads requires wifi
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
if (connectivityService.getConnectivity().isConnected() && !connectivityService.isInternetWalled()) {
|
||||
FileUploader.retryFailedUploads(
|
||||
|
|
Loading…
Reference in a new issue