mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
Merge pull request #6870 from nextcloud/testUploadConditions
Fix not waiting for non-metered wifi
This commit is contained in:
commit
3b2eb969c4
3 changed files with 46 additions and 2 deletions
|
@ -215,6 +215,7 @@ public class UploadIT extends AbstractOnServerIT {
|
||||||
|
|
||||||
uploadOCUpload(ocUpload);
|
uploadOCUpload(ocUpload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUploadOnChargingOnlyButNotCharging() {
|
public void testUploadOnChargingOnlyButNotCharging() {
|
||||||
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
||||||
|
@ -241,6 +242,7 @@ public class UploadIT extends AbstractOnServerIT {
|
||||||
|
|
||||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||||
assertFalse(result.toString(), result.isSuccess());
|
assertFalse(result.toString(), result.isSuccess());
|
||||||
|
assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_CHARGING, result.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -326,6 +328,7 @@ public class UploadIT extends AbstractOnServerIT {
|
||||||
|
|
||||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||||
assertFalse(result.toString(), result.isSuccess());
|
assertFalse(result.toString(), result.isSuccess());
|
||||||
|
assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -364,6 +367,47 @@ public class UploadIT extends AbstractOnServerIT {
|
||||||
.execute(client, getStorageManager());
|
.execute(client, getStorageManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUploadOnWifiOnlyButMeteredWifi() {
|
||||||
|
ConnectivityService connectivityServiceMock = new ConnectivityService() {
|
||||||
|
@Override
|
||||||
|
public boolean isInternetWalled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connectivity getConnectivity() {
|
||||||
|
return new Connectivity(true, true, true, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
|
||||||
|
FOLDER + "noWifi.txt",
|
||||||
|
account.name);
|
||||||
|
ocUpload.setUseWifiOnly(true);
|
||||||
|
|
||||||
|
UploadFileOperation newUpload = new UploadFileOperation(
|
||||||
|
uploadsStorageManager,
|
||||||
|
connectivityServiceMock,
|
||||||
|
powerManagementServiceMock,
|
||||||
|
user,
|
||||||
|
null,
|
||||||
|
ocUpload,
|
||||||
|
FileUploader.NameCollisionPolicy.DEFAULT,
|
||||||
|
FileUploader.LOCAL_BEHAVIOUR_COPY,
|
||||||
|
targetContext,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
newUpload.setRemoteFolderToBeCreated();
|
||||||
|
newUpload.addRenameUploadListener(() -> {
|
||||||
|
// dummy
|
||||||
|
});
|
||||||
|
|
||||||
|
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||||
|
assertFalse(result.toString(), result.isSuccess());
|
||||||
|
assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyStoragePath(OCFile file) {
|
private void verifyStoragePath(OCFile file) {
|
||||||
assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(),
|
assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(),
|
||||||
file.getStoragePath());
|
file.getStoragePath());
|
||||||
|
|
|
@ -686,7 +686,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||||
|
|
||||||
// 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()) {
|
if (mOnWifiOnly && (!connectivity.isWifi() || connectivity.isMetered())) {
|
||||||
Log_OC.d(TAG, "Upload delayed until WiFi is available: " + getRemotePath());
|
Log_OC.d(TAG, "Upload delayed until WiFi is available: " + getRemotePath());
|
||||||
remoteOperationResult = new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI);
|
remoteOperationResult = new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@
|
||||||
<string name="uploads_view_upload_status_conflict">Conflict</string>
|
<string name="uploads_view_upload_status_conflict">Conflict</string>
|
||||||
<string name="uploads_view_upload_status_service_interrupted">App terminated</string>
|
<string name="uploads_view_upload_status_service_interrupted">App terminated</string>
|
||||||
<string name="uploads_view_upload_status_unknown_fail">Unknown error</string>
|
<string name="uploads_view_upload_status_unknown_fail">Unknown error</string>
|
||||||
<string name="uploads_view_upload_status_waiting_for_wifi">Waiting for Wi-Fi</string>
|
<string name="uploads_view_upload_status_waiting_for_wifi">Waiting for non-metered Wi-Fi</string>
|
||||||
<string name="uploads_view_upload_status_waiting_exit_power_save_mode">Waiting to exit power save mode</string>
|
<string name="uploads_view_upload_status_waiting_exit_power_save_mode">Waiting to exit power save mode</string>
|
||||||
<string name="uploads_view_upload_status_fetching_server_version">Fetching server version…</string>
|
<string name="uploads_view_upload_status_fetching_server_version">Fetching server version…</string>
|
||||||
<string name="uploads_view_later_waiting_to_upload">Waiting to upload</string>
|
<string name="uploads_view_later_waiting_to_upload">Waiting to upload</string>
|
||||||
|
|
Loading…
Reference in a new issue