aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-08-13 22:53:03 +0200
committerChristian Schneppe <christian@pix-art.de>2017-08-13 22:53:03 +0200
commitc449c5dcb84f0b4f2435103ceb4909ecac52e810 (patch)
treea4b110b5df8c4e6d951e2f95eb42910d96bf6e40 /src/main
parent04db5052ccee3cba54c52d64e3ec199d78b675ad (diff)
add more logging to http download connection and reset file params after setting expected size
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java4
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java72
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpUploadConnection.java7
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java2
4 files changed, 50 insertions, 35 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 6f516f45e..317605167 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -706,6 +706,10 @@ public class Message extends AbstractEntity {
return isGeoUri;
}
+ public synchronized void resetFileParams() {
+ this.fileParams = null;
+ }
+
public synchronized FileParams getFileParams() {
if (fileParams == null) {
fileParams = new FileParams();
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index dbbfec861..7326cbf4b 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -160,6 +160,30 @@ public class HttpDownloadConnection implements Transferable {
}
}
+ public void updateProgress(long i) {
+ this.mProgress = (int) i;
+ mHttpConnectionManager.updateConversationUi(false);
+ }
+
+ @Override
+ public int getStatus() {
+ return this.mStatus;
+ }
+
+ @Override
+ public long getFileSize() {
+ if (this.file != null) {
+ return this.file.getExpectedSize();
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public int getProgress() {
+ return this.mProgress;
+ }
+
private class FileSizeChecker implements Runnable {
private boolean interactive = false;
@@ -186,6 +210,7 @@ public class HttpDownloadConnection implements Transferable {
return;
}
file.setExpectedSize(size);
+ message.resetFileParams();
if (mHttpConnectionManager.hasStoragePermission()
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
&& mXmppConnectionService.isDataSaverDisabled()) {
@@ -283,12 +308,13 @@ public class HttpDownloadConnection implements Transferable {
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
}
connection.setRequestProperty("User-Agent", mXmppConnectionService.getIqGenerator().getIdentityName());
- final boolean tryResume = file.exists() && file.getKey() == null;
+ final boolean tryResume = file.exists() && file.getKey() == null && file.getSize() > 0;
long resumeSize = 0;
+ long expected = file.getExpectedSize();
if (tryResume) {
- Log.d(Config.LOGTAG, "http download trying resume");
resumeSize = file.getSize();
- connection.setRequestProperty("Range", "bytes="+resumeSize+"-");
+ Log.d(Config.LOGTAG, "http download trying resume after" + resumeSize + " of " + expected);
+ connection.setRequestProperty("Range", "bytes=" + resumeSize + "-");
}
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
connection.setReadTimeout(Config.CONNECT_TIMEOUT * 1000);
@@ -297,16 +323,24 @@ public class HttpDownloadConnection implements Transferable {
final String contentRange = connection.getHeaderField("Content-Range");
boolean serverResumed = tryResume && contentRange != null && contentRange.startsWith("bytes "+resumeSize+"-");
long transmitted = 0;
- long expected = file.getExpectedSize();
if (tryResume && serverResumed) {
Log.d(Config.LOGTAG, "server resumed");
transmitted = file.getSize();
- updateProgress((int) ((((double) transmitted) / expected) * 100));
+ updateProgress(Math.round(((double) transmitted / expected) * 100));
os = AbstractConnectionManager.createAppendedOutputStream(file);
if (os == null) {
throw new FileWriterException();
}
} else {
+ long reportedContentLengthOnGet;
+ try {
+ reportedContentLengthOnGet = Long.parseLong(connection.getHeaderField("Content-Length"));
+ } catch (NumberFormatException | NullPointerException e) {
+ reportedContentLengthOnGet = 0;
+ }
+ if (expected != reportedContentLengthOnGet) {
+ Log.d(Config.LOGTAG, "content-length reported on GET (" + reportedContentLengthOnGet + ") did not match Content-Length reported on HEAD (" + expected + ")");
+ }
file.getParentFile().mkdirs();
if (!file.exists() && !file.createNewFile()) {
throw new FileWriterException();
@@ -314,7 +348,7 @@ public class HttpDownloadConnection implements Transferable {
os = AbstractConnectionManager.createOutputStream(file, true);
}
int count;
- byte[] buffer = new byte[1024];
+ byte[] buffer = new byte[4096];
while ((count = is.read(buffer)) != -1) {
transmitted += count;
try {
@@ -322,7 +356,7 @@ public class HttpDownloadConnection implements Transferable {
} catch (IOException e) {
throw new FileWriterException();
}
- updateProgress((int) ((((double) transmitted) / expected) * 100));
+ updateProgress(Math.round(((double) transmitted / expected) * 100));
if (canceled) {
throw new CancellationException();
}
@@ -359,28 +393,4 @@ public class HttpDownloadConnection implements Transferable {
}
}
-
- public void updateProgress(int i) {
- this.mProgress = i;
- mHttpConnectionManager.updateConversationUi(false);
- }
-
- @Override
- public int getStatus() {
- return this.mStatus;
- }
-
- @Override
- public long getFileSize() {
- if (this.file != null) {
- return this.file.getExpectedSize();
- } else {
- return 0;
- }
- }
-
- @Override
- public int getProgress() {
- return this.mProgress;
- }
}
diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
index 48485eaf7..22fec6888 100644
--- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
@@ -117,10 +117,9 @@ public class HttpUploadConnection implements Transferable {
fail(e.getMessage());
return;
}
- if (pair != null) {
- this.file.setExpectedSize(pair.second);
- this.mFileInputStream = pair.first;
- }
+ this.file.setExpectedSize(pair.second);
+ message.resetFileParams();
+ this.mFileInputStream = pair.first;
Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
index 2f8d66306..3aaf002c7 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
@@ -464,6 +464,7 @@ public class JingleConnection implements Transferable {
}
this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file, message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
this.file.setExpectedSize(size);
+ message.resetFileParams();
Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
} else {
this.sendCancel();
@@ -508,6 +509,7 @@ public class JingleConnection implements Transferable {
cancel();
return;
}
+ message.resetFileParams();
this.mFileInputStream = pair.first;
content.setTransportId(this.transportId);
content.socks5transport().setChildren(getCandidatesAsElements());