Transferables interface needs to differentiate between 0 and null file size

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/entities/Transferable.java                    |  2 
src/main/java/eu/siacs/conversations/entities/TransferablePlaceholder.java         |  4 
src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java              |  6 
src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java                |  4 
src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java       | 11 
src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java |  4 
6 files changed, 16 insertions(+), 15 deletions(-)

Detailed changes

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;
         }
     }
 

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

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);
     }