From 0443a77d669bdcca4b3651544e7162b57f61af45 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 20 Sep 2016 20:02:25 +0200 Subject: add timeouts to HTTPUrlConnections and allow cancelation of all sending files --- src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java | 4 ++++ src/main/java/de/pixart/messenger/http/HttpUploadConnection.java | 4 +++- src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java index 44f66735e..9a6676154 100644 --- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java @@ -220,6 +220,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(); @@ -288,6 +290,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/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java index 1e30a902a..0d1448509 100644 --- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java @@ -177,10 +177,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/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 3f79e01d7..11da4f130 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -585,9 +585,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) { -- cgit v1.2.3