Transferables interface needs to differentiate between 0 and null file size

This commit is contained in:
Daniel Gultsch 2021-05-17 15:51:21 +02:00
parent b025265f91
commit 87f99d3570
6 changed files with 16 additions and 15 deletions

View file

@ -22,7 +22,7 @@ public interface Transferable {
int getStatus();
long getFileSize();
Long getFileSize();
int getProgress();

View file

@ -18,8 +18,8 @@ public class TransferablePlaceholder implements Transferable {
}
@Override
public long getFileSize() {
return 0;
public Long getFileSize() {
return null;
}
@Override

View file

@ -107,6 +107,7 @@ public class HttpDownloadConnection implements Transferable {
}
//TODO add auth tag size to knownFileSize
final Long knownFileSize = message.getFileParams().size;
Log.d(Config.LOGTAG,"knownFileSize: "+knownFileSize+", body="+message.getBody());
if (knownFileSize != null && interactive) {
this.file.setExpectedSize(knownFileSize);
download(true);
@ -130,6 +131,7 @@ public class HttpDownloadConnection implements Transferable {
}
private void download(final boolean interactive) {
Log.d(Config.LOGTAG,"download()",new Exception());
EXECUTOR.execute(new FileDownloader(interactive));
}
@ -234,11 +236,11 @@ public class HttpDownloadConnection implements Transferable {
}
@Override
public long getFileSize() {
public Long getFileSize() {
if (this.file != null) {
return this.file.getExpectedSize();
} else {
return 0;
return null;
}
}

View file

@ -69,8 +69,8 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
}
@Override
public long getFileSize() {
return file == null ? 0 : file.getExpectedSize();
public Long getFileSize() {
return file == null ? null : file.getExpectedSize();
}
@Override

View file

@ -5,6 +5,8 @@ import android.os.PowerManager;
import android.os.SystemClock;
import android.util.Log;
import androidx.core.content.ContextCompat;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.io.CipherInputStream;
import org.bouncycastle.crypto.io.CipherOutputStream;
@ -118,7 +120,8 @@ public class AbstractConnectionManager {
}
public long getAutoAcceptFileSize() {
return this.mXmppConnectionService.getLongPreference("auto_accept_file_size", R.integer.auto_accept_filesize);
final long autoAcceptFileSize = this.mXmppConnectionService.getLongPreference("auto_accept_file_size", R.integer.auto_accept_filesize);
return autoAcceptFileSize <= 0 ? -1 : autoAcceptFileSize;
}
public boolean hasStoragePermission() {
@ -134,12 +137,8 @@ public class AbstractConnectionManager {
}
}
public PowerManager.WakeLock createWakeLock(final Thread thread) {
return createWakeLock("conversations:" + thread.getName());
}
public PowerManager.WakeLock createWakeLock(final String name) {
final PowerManager powerManager = (PowerManager) mXmppConnectionService.getSystemService(Context.POWER_SERVICE);
final PowerManager powerManager = ContextCompat.getSystemService(mXmppConnectionService, PowerManager.class);
return powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
}

View file

@ -1239,11 +1239,11 @@ public class JingleFileTransferConnection extends AbstractJingleConnection imple
}
@Override
public long getFileSize() {
public Long getFileSize() {
if (this.file != null) {
return this.file.getExpectedSize();
} else {
return 0;
return null;
}
}