From 87f99d35708d09a52c1c99b2d114e4c1c07007ef Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 17 May 2021 15:51:21 +0200 Subject: [PATCH] Transferables interface needs to differentiate between 0 and null file size --- .../eu/siacs/conversations/entities/Transferable.java | 2 +- .../entities/TransferablePlaceholder.java | 4 ++-- .../conversations/http/HttpDownloadConnection.java | 6 ++++-- .../conversations/http/HttpUploadConnection.java | 4 ++-- .../services/AbstractConnectionManager.java | 11 +++++------ .../xmpp/jingle/JingleFileTransferConnection.java | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Transferable.java b/src/main/java/eu/siacs/conversations/entities/Transferable.java index 6a31a368a..5c833f603 100644 --- a/src/main/java/eu/siacs/conversations/entities/Transferable.java +++ b/src/main/java/eu/siacs/conversations/entities/Transferable.java @@ -22,7 +22,7 @@ public interface Transferable { int getStatus(); - long getFileSize(); + Long getFileSize(); int getProgress(); diff --git a/src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java b/src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java index c8a60d7d9..fd72a28a0 100644 --- a/src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java +++ b/src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java @@ -18,8 +18,8 @@ public class TransferablePlaceholder implements Transferable { } @Override - public long getFileSize() { - return 0; + public Long getFileSize() { + return null; } @Override diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index fca5cc705..349886115 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -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; } } diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index 6611aab2b..f1bae9956 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -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 diff --git a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java index 40e381816..94c6b79b9 100644 --- a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java @@ -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); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java index 8997a5043..40edf0b2c 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java @@ -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; } }