Loading app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java +9 −0 Original line number Diff line number Diff line Loading @@ -12,7 +12,9 @@ package foundation.e.drive.operations; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.FILE_NOT_FOUND; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.FORBIDDEN; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.INVALID_OVERWRITE; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.WRONG_CONNECTION; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; Loading Loading @@ -93,6 +95,9 @@ public class DownloadFileOperation extends RemoteOperation { mustRestart = false; } } else if (isNetworkDisconnected(downloadResult)) { mustRestart = false; resultCode = downloadResult.getCode(); } else { Timber.d("Download failed: %s, %s", downloadResult.getCode(), downloadResult.getLogMessage()); resultCode = RemoteOperationResult.ResultCode.UNKNOWN_ERROR; Loading @@ -116,6 +121,10 @@ public class DownloadFileOperation extends RemoteOperation { return new RemoteOperationResult(resultCode); } private boolean isNetworkDisconnected(@NonNull final RemoteOperationResult result) { RemoteOperationResult.ResultCode resultCode = result.getCode(); return resultCode == NO_NETWORK_CONNECTION || resultCode == WRONG_CONNECTION; } private RemoteOperationResult.ResultCode onDownloadSuccess(String tmpTargetFolderPath) { final String tmpFilePath = tmpTargetFolderPath + remoteFile.getRemotePath(); Loading app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +17 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import foundation.e.drive.database.DbHelper; import foundation.e.drive.models.SyncedFileState; Loading @@ -43,8 +45,10 @@ import timber.log.Timber; * High level Operation which upload a local file to a remote cloud storage */ public class UploadFileOperation extends RemoteOperation { private final static String TAG = UploadFileOperation.class.getSimpleName(); public final static int FILE_SIZE_FLOOR_FOR_CHUNKED = 3072000; //3MB private static final Set<ResultCode> handledFailureCodes = getHandledFailureCodes(); private final Context context; private final SyncedFileState syncedState; private final Account account; // TODO Remove as soon as nextcloud library move all Operation to NextcloudClient instead of OwncloudClient Loading Loading @@ -109,14 +113,24 @@ public class UploadFileOperation extends RemoteOperation { * @return */ private ResultCode onUploadFailure(final ResultCode uploadResult, final String fileName) { if (uploadResult != ResultCode.CONFLICT && uploadResult != ResultCode.QUOTA_EXCEEDED) { if (!handledFailureCodes.contains(uploadResult)) { Timber.d("Upload for %s failed : %s", fileName, uploadResult); return ResultCode.UNKNOWN_ERROR; } return uploadResult; } @NonNull private static Set<ResultCode> getHandledFailureCodes() { final Set<ResultCode> handledResultCodes = new HashSet<>(); handledResultCodes.add(ResultCode.CONFLICT); handledResultCodes.add(ResultCode.QUOTA_EXCEEDED); handledResultCodes.add(ResultCode.WRONG_CONNECTION); handledResultCodes.add(ResultCode.NO_NETWORK_CONNECTION); return handledResultCodes; } /** * Check condition required to upload the file: * - the local file exist Loading app/src/main/java/foundation/e/drive/services/SynchronizationService.java +23 −4 Original line number Diff line number Diff line Loading @@ -224,7 +224,12 @@ public class SynchronizationService extends Service implements OnRemoteOperation } } private void startWorker(Integer threadIndex){ private void startWorker(int threadIndex) { if (!isNetworkAvailable()) { syncRequestQueue.clear(); return; } if (!canStart(threadIndex) || isPaused()) return; final SyncRequest request = this.syncRequestQueue.poll(); //return null if empty Loading Loading @@ -267,16 +272,21 @@ public class SynchronizationService extends Service implements OnRemoteOperation * @return false if nogo */ private boolean canStart(int threadIndex) { final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); final SyncWrapper syncWrapper = startedSync.get(threadIndex); return (syncWrapper == null || !syncWrapper.isRunning()); } return (syncWrapper == null || !syncWrapper.isRunning()) && CommonUtils.haveNetworkConnection(getApplicationContext(), meteredNetworkAllowed); private boolean isNetworkAvailable() { final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); return CommonUtils.haveNetworkConnection(getApplicationContext(), meteredNetworkAllowed); } @Override public void onRemoteOperationFinish(@NonNull RemoteOperation callerOperation, @NonNull RemoteOperationResult result) { Timber.i("onRemoteOperationFinish()"); boolean isNetworkDisconnected = false; if (callerOperation instanceof RemoveFileOperation && result.isSuccess()) { DbHelper .manageSyncedFileStateDB( Loading Loading @@ -326,6 +336,11 @@ public class SynchronizationService extends Service implements OnRemoteOperation //Case specific to DownloadFileOperation Timber.d("%s : Sync_conflict: File is already up to date", operationClassName); break; case NO_NETWORK_CONNECTION: case WRONG_CONNECTION: isNetworkDisconnected = true; Timber.d("%s : network issue: %s", operationClassName, result.getCode()); break; } } Loading @@ -339,6 +354,10 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; } } if (isNetworkDisconnected) { syncRequestQueue.clear(); } } private void updateFailureCounter(SyncRequest request, boolean success) { Loading Loading
app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java +9 −0 Original line number Diff line number Diff line Loading @@ -12,7 +12,9 @@ package foundation.e.drive.operations; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.FILE_NOT_FOUND; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.FORBIDDEN; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.INVALID_OVERWRITE; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.WRONG_CONNECTION; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; Loading Loading @@ -93,6 +95,9 @@ public class DownloadFileOperation extends RemoteOperation { mustRestart = false; } } else if (isNetworkDisconnected(downloadResult)) { mustRestart = false; resultCode = downloadResult.getCode(); } else { Timber.d("Download failed: %s, %s", downloadResult.getCode(), downloadResult.getLogMessage()); resultCode = RemoteOperationResult.ResultCode.UNKNOWN_ERROR; Loading @@ -116,6 +121,10 @@ public class DownloadFileOperation extends RemoteOperation { return new RemoteOperationResult(resultCode); } private boolean isNetworkDisconnected(@NonNull final RemoteOperationResult result) { RemoteOperationResult.ResultCode resultCode = result.getCode(); return resultCode == NO_NETWORK_CONNECTION || resultCode == WRONG_CONNECTION; } private RemoteOperationResult.ResultCode onDownloadSuccess(String tmpTargetFolderPath) { final String tmpFilePath = tmpTargetFolderPath + remoteFile.getRemotePath(); Loading
app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +17 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import foundation.e.drive.database.DbHelper; import foundation.e.drive.models.SyncedFileState; Loading @@ -43,8 +45,10 @@ import timber.log.Timber; * High level Operation which upload a local file to a remote cloud storage */ public class UploadFileOperation extends RemoteOperation { private final static String TAG = UploadFileOperation.class.getSimpleName(); public final static int FILE_SIZE_FLOOR_FOR_CHUNKED = 3072000; //3MB private static final Set<ResultCode> handledFailureCodes = getHandledFailureCodes(); private final Context context; private final SyncedFileState syncedState; private final Account account; // TODO Remove as soon as nextcloud library move all Operation to NextcloudClient instead of OwncloudClient Loading Loading @@ -109,14 +113,24 @@ public class UploadFileOperation extends RemoteOperation { * @return */ private ResultCode onUploadFailure(final ResultCode uploadResult, final String fileName) { if (uploadResult != ResultCode.CONFLICT && uploadResult != ResultCode.QUOTA_EXCEEDED) { if (!handledFailureCodes.contains(uploadResult)) { Timber.d("Upload for %s failed : %s", fileName, uploadResult); return ResultCode.UNKNOWN_ERROR; } return uploadResult; } @NonNull private static Set<ResultCode> getHandledFailureCodes() { final Set<ResultCode> handledResultCodes = new HashSet<>(); handledResultCodes.add(ResultCode.CONFLICT); handledResultCodes.add(ResultCode.QUOTA_EXCEEDED); handledResultCodes.add(ResultCode.WRONG_CONNECTION); handledResultCodes.add(ResultCode.NO_NETWORK_CONNECTION); return handledResultCodes; } /** * Check condition required to upload the file: * - the local file exist Loading
app/src/main/java/foundation/e/drive/services/SynchronizationService.java +23 −4 Original line number Diff line number Diff line Loading @@ -224,7 +224,12 @@ public class SynchronizationService extends Service implements OnRemoteOperation } } private void startWorker(Integer threadIndex){ private void startWorker(int threadIndex) { if (!isNetworkAvailable()) { syncRequestQueue.clear(); return; } if (!canStart(threadIndex) || isPaused()) return; final SyncRequest request = this.syncRequestQueue.poll(); //return null if empty Loading Loading @@ -267,16 +272,21 @@ public class SynchronizationService extends Service implements OnRemoteOperation * @return false if nogo */ private boolean canStart(int threadIndex) { final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); final SyncWrapper syncWrapper = startedSync.get(threadIndex); return (syncWrapper == null || !syncWrapper.isRunning()); } return (syncWrapper == null || !syncWrapper.isRunning()) && CommonUtils.haveNetworkConnection(getApplicationContext(), meteredNetworkAllowed); private boolean isNetworkAvailable() { final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); return CommonUtils.haveNetworkConnection(getApplicationContext(), meteredNetworkAllowed); } @Override public void onRemoteOperationFinish(@NonNull RemoteOperation callerOperation, @NonNull RemoteOperationResult result) { Timber.i("onRemoteOperationFinish()"); boolean isNetworkDisconnected = false; if (callerOperation instanceof RemoveFileOperation && result.isSuccess()) { DbHelper .manageSyncedFileStateDB( Loading Loading @@ -326,6 +336,11 @@ public class SynchronizationService extends Service implements OnRemoteOperation //Case specific to DownloadFileOperation Timber.d("%s : Sync_conflict: File is already up to date", operationClassName); break; case NO_NETWORK_CONNECTION: case WRONG_CONNECTION: isNetworkDisconnected = true; Timber.d("%s : network issue: %s", operationClassName, result.getCode()); break; } } Loading @@ -339,6 +354,10 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; } } if (isNetworkDisconnected) { syncRequestQueue.clear(); } } private void updateFailureCounter(SyncRequest request, boolean success) { Loading