Skip to content

Commit

Permalink
enh/connectionChecks: Report main reason + don't do unnecessary checks
Browse files Browse the repository at this point in the history
Previously checkConditions() would always report the last detected condition (in the method) that prevented the upload rather than the first. Besides doing unnecessary work, this meant that situations where say the auto-upload condition is set to "charging only" but network connectivity isn't working, would be reported as "Upload failed" due to a "Connection error" which is irrelevant. Also means we stop doing silling things like checking for network connectivity when the upload is already excluded due to the device not currently charging.

Signed-off-by: Josh Richards <[email protected]>
  • Loading branch information
joshtrichards committed Dec 12, 2023
1 parent e524f1a commit dcff63d
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,25 +711,29 @@ private RemoteOperationResult checkConditions(File originalFile) {
if (mOnWifiOnly && (!connectivity.isWifi() || connectivity.isMetered())) {
Log_OC.d(TAG, "Upload delayed until WiFi is available: " + getRemotePath());
remoteOperationResult = new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI);
return remoteOperationResult;
}

// check if charging conditions are met and delays the upload otherwise
final BatteryStatus battery = powerManagementService.getBattery();
if (mWhileChargingOnly && !battery.isCharging()) {
Log_OC.d(TAG, "Upload delayed until the device is charging: " + getRemotePath());
remoteOperationResult = new RemoteOperationResult(ResultCode.DELAYED_FOR_CHARGING);
return remoteOperationResult;
}

// check that device is not in power save mode
if (!mIgnoringPowerSaveMode && powerManagementService.isPowerSavingEnabled()) {
Log_OC.d(TAG, "Upload delayed because device is in power save mode: " + getRemotePath());
remoteOperationResult = new RemoteOperationResult(ResultCode.DELAYED_IN_POWER_SAVE_MODE);
return remoteOperationResult;
}

// check if the file continues existing before schedule the operation
if (!originalFile.exists()) {
Log_OC.d(TAG, mOriginalStoragePath + " not exists anymore");
remoteOperationResult = new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND);
return remoteOperationResult;
}

// check that internet is not behind walled garden
Expand Down

0 comments on commit dcff63d

Please sign in to comment.