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(); int getStatus();
long getFileSize(); Long getFileSize();
int getProgress(); int getProgress();

View File

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

View File

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

View File

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

View File

@ -5,6 +5,8 @@ import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import androidx.core.content.ContextCompat;
import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.io.CipherInputStream; import org.bouncycastle.crypto.io.CipherInputStream;
import org.bouncycastle.crypto.io.CipherOutputStream; import org.bouncycastle.crypto.io.CipherOutputStream;
@ -118,7 +120,8 @@ public class AbstractConnectionManager {
} }
public long getAutoAcceptFileSize() { 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() { 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) { 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); return powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
} }

View File

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