mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
Reduce number of calls to /index.php/204 if there is nothing to do.
https://github.com/nextcloud/android/issues/2263 Signed-off-by: Tomasz <tomaszduda23@gmail.com>
This commit is contained in:
parent
b160958a95
commit
cc69e660f0
3 changed files with 43 additions and 5 deletions
|
@ -1062,6 +1062,12 @@ public class FileUploader extends Service
|
||||||
@Nullable final UploadResult uploadResult
|
@Nullable final UploadResult uploadResult
|
||||||
) {
|
) {
|
||||||
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
||||||
|
if(failedUploads.length == 0)
|
||||||
|
{
|
||||||
|
//nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Account currentAccount = null;
|
Account currentAccount = null;
|
||||||
boolean resultMatch;
|
boolean resultMatch;
|
||||||
boolean accountMatch;
|
boolean accountMatch;
|
||||||
|
|
|
@ -690,11 +690,6 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
private RemoteOperationResult checkConditions(File originalFile) {
|
private RemoteOperationResult checkConditions(File originalFile) {
|
||||||
RemoteOperationResult remoteOperationResult = null;
|
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
|
// check that connectivity conditions are met and delays the upload otherwise
|
||||||
Connectivity connectivity = connectivityService.getConnectivity();
|
Connectivity connectivity = connectivityService.getConnectivity();
|
||||||
if (mOnWifiOnly && (!connectivity.isWifi() || connectivity.isMetered())) {
|
if (mOnWifiOnly && (!connectivity.isWifi() || connectivity.isMetered())) {
|
||||||
|
@ -721,6 +716,11 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
remoteOperationResult = new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND);
|
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;
|
return remoteOperationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import android.provider.MediaStore;
|
||||||
|
|
||||||
import com.nextcloud.client.account.UserAccountManager;
|
import com.nextcloud.client.account.UserAccountManager;
|
||||||
import com.nextcloud.client.core.Clock;
|
import com.nextcloud.client.core.Clock;
|
||||||
|
import com.nextcloud.client.device.BatteryStatus;
|
||||||
import com.nextcloud.client.device.PowerManagementService;
|
import com.nextcloud.client.device.PowerManagementService;
|
||||||
import com.nextcloud.client.jobs.BackgroundJobManager;
|
import com.nextcloud.client.jobs.BackgroundJobManager;
|
||||||
import com.nextcloud.client.network.ConnectivityService;
|
import com.nextcloud.client.network.ConnectivityService;
|
||||||
|
@ -185,10 +186,20 @@ public final class FilesSyncHelper {
|
||||||
|
|
||||||
boolean accountExists;
|
boolean accountExists;
|
||||||
|
|
||||||
|
boolean whileChargingOnly = true;
|
||||||
|
boolean useWifiOnly = true;
|
||||||
|
|
||||||
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
|
||||||
|
|
||||||
for (OCUpload failedUpload : failedUploads) {
|
for (OCUpload failedUpload : failedUploads) {
|
||||||
accountExists = false;
|
accountExists = false;
|
||||||
|
if(!failedUpload.isWhileChargingOnly()){
|
||||||
|
whileChargingOnly = false;
|
||||||
|
}
|
||||||
|
if(!failedUpload.isUseWifiOnly())
|
||||||
|
{
|
||||||
|
useWifiOnly = false;
|
||||||
|
}
|
||||||
|
|
||||||
// check if accounts still exists
|
// check if accounts still exists
|
||||||
for (Account account : accountManager.getAccounts()) {
|
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(() -> {
|
new Thread(() -> {
|
||||||
if (connectivityService.getConnectivity().isConnected() && !connectivityService.isInternetWalled()) {
|
if (connectivityService.getConnectivity().isConnected() && !connectivityService.isInternetWalled()) {
|
||||||
FileUploader.retryFailedUploads(
|
FileUploader.retryFailedUploads(
|
||||||
|
|
Loading…
Reference in a new issue