aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-09-20 20:02:25 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-09-20 20:02:25 +0200
commit61f58b3dbde32eedd08f893977311405d5f465c6 (patch)
tree4f95b38357a068caa38908cf89a5b5f24f421a02 /src/main
parentde7c0c5121ac4436b9172d35bfe44a45865c25be (diff)
add timeouts to HTTPUrlConnections and allow cancelation of all sending files
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java4
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java7
3 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
index 741ea98d..a9bffe3e 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
@@ -212,6 +212,8 @@ public class HttpDownloadConnection implements Transferable {
if (connection instanceof HttpsURLConnection) {
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
}
+ connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
+ connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
connection.connect();
String contentLength = connection.getHeaderField("Content-Length");
connection.disconnect();
@@ -279,6 +281,8 @@ public class HttpDownloadConnection implements Transferable {
long size = file.getSize();
connection.setRequestProperty("Range", "bytes="+size+"-");
}
+ connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
+ connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
connection.connect();
is = new BufferedInputStream(connection.getInputStream());
boolean serverResumed = "bytes".equals(connection.getHeaderField("Accept-Ranges"));
diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
index 1bb70690..1bd6a8e4 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
@@ -171,10 +171,12 @@ public class HttpUploadConnection implements Transferable {
connection.setRequestProperty("Content-Type", mime == null ? "application/octet-stream" : mime);
connection.setRequestProperty("User-Agent",mXmppConnectionService.getIqGenerator().getIdentityName());
connection.setDoOutput(true);
+ connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
+ connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
connection.connect();
os = connection.getOutputStream();
transmitted = 0;
- int count = -1;
+ int count;
byte[] buffer = new byte[4096];
while (((count = mFileInputStream.read(buffer)) != -1) && !canceled) {
transmitted += count;
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index c6f6b8cd..3490a712 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -573,9 +573,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
downloadFile.setVisible(true);
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
}
- if ((t != null && !(t instanceof TransferablePlaceholder))
- || (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
- || m.getStatus() == Message.STATUS_OFFERED))) {
+ boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING
+ || m.getStatus() == Message.STATUS_UNSEND
+ || m.getStatus() == Message.STATUS_OFFERED;
+ if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
cancelTransmission.setVisible(true);
}
if (treatAsFile) {