diff options
author | lookshe <github@lookshe.org> | 2016-03-08 10:49:47 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-03-08 10:49:47 +0100 |
commit | 2b86b686c52c3d82ad01a8ff81c5766d64050b62 (patch) | |
tree | ad7cfd62d79e06fea673bf601c9f0823842559ce /src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | |
parent | f767a068423c50dde60bf570d6a05683ed6d76d7 (diff) | |
parent | 1e75283250aee20b0fd2a73b7b3407801391f953 (diff) |
Merge tag '1.11.0' into trz/merge_1.11.0
Conflicts:
README.md
build.gradle
src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
src/main/java/eu/siacs/conversations/entities/Conversation.java
src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
src/main/java/eu/siacs/conversations/parser/MessageParser.java
src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
src/main/java/eu/siacs/conversations/ui/XmppActivity.java
src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
src/main/res/values-bg/strings.xml
src/main/res/values-de/strings.xml
src/main/res/values-es/strings.xml
src/main/res/values-fr/strings.xml
src/main/res/values-it/strings.xml
src/main/res/values-nl/strings.xml
src/main/res/values-pl/strings.xml
src/main/res/values-ro-rRO/strings.xml
src/main/res/values-sr/strings.xml
src/main/res/values-sv/strings.xml
src/main/res/values-tr-rTR/strings.xml
src/main/res/values-zh-rCN/strings.xml
src/main/res/values/strings.xml
Diffstat (limited to 'src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | 144 |
1 files changed, 76 insertions, 68 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index b47ff96c..cdc5d2e7 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -3,13 +3,17 @@ package eu.siacs.conversations.http; import android.content.Intent; import android.net.Uri; import android.os.PowerManager; +import android.util.Log; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.MalformedURLException; +import java.net.Proxy; import java.net.URL; import java.util.Arrays; import java.util.concurrent.CancellationException; @@ -70,75 +74,76 @@ public class HttpDownloadConnection implements Transferable { } public void init(Message message, boolean interactive) { - this.message = message; - this.message.setTransferable(this); - try { - if (message.hasFileOnRemoteHost()) { - mUrl = message.getFileParams().url; - } else { - mUrl = new URL(message.getBody()); - } - String[] parts = mUrl.getPath().toLowerCase().split("\\."); - String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null; - String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null; - if ("pgp".equals(lastPart) || "gpg".equals(lastPart)) { - this.message.setEncryption(Message.ENCRYPTION_PGP); - } else if (message.getEncryption() != Message.ENCRYPTION_OTR - && message.getEncryption() != Message.ENCRYPTION_AXOLOTL) { - this.message.setEncryption(Message.ENCRYPTION_NONE); - } - String extension; - if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains(lastPart)) { - extension = secondToLast; - } else { - extension = lastPart; - } - message.setRelativeFilePath(message.getUuid()+"."+extension); - this.file = FileBackend.getFile(message, false); - String reference = mUrl.getRef(); - if (reference != null && reference.length() == 96) { - this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference)); - } + this.message = message; + this.message.setTransferable(this); + try { + if (message.hasFileOnRemoteHost()) { + mUrl = message.getFileParams().url; + } else { + mUrl = new URL(message.getBody()); + } + String[] parts = mUrl.getPath().toLowerCase().split("\\."); + String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null; + String secondToLast = parts.length >= 2 ? parts[parts.length -2] : null; + if ("pgp".equals(lastPart) || "gpg".equals(lastPart)) { + this.message.setEncryption(Message.ENCRYPTION_PGP); + } else if (message.getEncryption() != Message.ENCRYPTION_OTR + && message.getEncryption() != Message.ENCRYPTION_AXOLOTL) { + this.message.setEncryption(Message.ENCRYPTION_NONE); + } + String extension; + if (VALID_CRYPTO_EXTENSIONS.contains(lastPart)) { + extension = secondToLast; + } else { + extension = lastPart; + } + message.setRelativeFilePath(message.getUuid()+"."+extension); + this.file = FileBackend.getFile(message, false); + String reference = mUrl.getRef(); + if (reference != null && reference.length() == 96) { + this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference)); + } - if ((this.message.getEncryption() == Message.ENCRYPTION_OTR - || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL) - && this.file.getKey() == null) { - this.message.setEncryption(Message.ENCRYPTION_NONE); - } - checkFileSize(interactive); - } catch (MalformedURLException e) { - this.cancel(); - } + if ((this.message.getEncryption() == Message.ENCRYPTION_OTR + || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL) + && this.file.getKey() == null) { + this.message.setEncryption(Message.ENCRYPTION_NONE); + } + checkFileSize(interactive); + } catch (MalformedURLException e) { + this.cancel(); + } } private void checkFileSize(boolean interactive) { new Thread(new FileSizeChecker(interactive)).start(); } + @Override public void cancel() { - this.canceled = true; - mHttpConnectionManager.finishConnection(this); - if (message.isFileOrImage()) { - message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); - } else { - message.setTransferable(null); - } - mXmppConnectionService.updateConversationUi(); + this.canceled = true; + mHttpConnectionManager.finishConnection(this); + if (message.isFileOrImage()) { + message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); + } else { + message.setTransferable(null); + } + mXmppConnectionService.updateConversationUi(); } private void finish() { - Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - intent.setData(Uri.fromFile(file)); - mXmppConnectionService.sendBroadcast(intent); - message.setTransferable(null); - mHttpConnectionManager.finishConnection(this); - if (message.getEncryption() == Message.ENCRYPTION_PGP) { - message.getConversation().getAccount().getPgpDecryptionService().add(message); - } - mXmppConnectionService.updateConversationUi(); - if (acceptedAutomatically) { - mXmppConnectionService.getNotificationService().push(message); - } + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(Uri.fromFile(file)); + mXmppConnectionService.sendBroadcast(intent); + message.setTransferable(null); + mHttpConnectionManager.finishConnection(this); + if (message.getEncryption() == Message.ENCRYPTION_PGP) { + message.getConversation().getAccount().getPgpDecryptionService().add(message); + } + mXmppConnectionService.updateConversationUi(); + if (acceptedAutomatically) { + mXmppConnectionService.getNotificationService().push(message); + } } private void changeStatus(int status) { @@ -152,7 +157,7 @@ public class HttpDownloadConnection implements Transferable { mXmppConnectionService.showErrorToastInUi(R.string.download_failed_server_not_found); } else if (e instanceof java.net.ConnectException) { mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_connect); - } else if (!(e instanceof CancellationException)) { + } else if (!(e instanceof CancellationException)) { mXmppConnectionService.showErrorToastInUi(R.string.download_failed_file_not_found); } } @@ -176,7 +181,7 @@ public class HttpDownloadConnection implements Transferable { HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message); return; } catch (IOException e) { - Logging.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage()); + Log.d(Config.LOGTAG, "io exception in http file size checker: " + e.getMessage()); if (interactive) { showToastForException(e); } @@ -184,7 +189,8 @@ public class HttpDownloadConnection implements Transferable { return; } file.setExpectedSize(size); - if (size != -1 + if (mHttpConnectionManager.hasStoragePermission() + && size != -1 && size <= ConversationsPlusPreferences.autoAcceptFileSize() && mXmppConnectionService.isDownloadAllowedInConnection()) { HttpDownloadConnection.this.acceptedAutomatically = true; @@ -221,13 +227,14 @@ public class HttpDownloadConnection implements Transferable { return -1; } } + } private class FileDownloader implements Runnable { private boolean interactive = false; - private OutputStream os; + private OutputStream os; public FileDownloader(boolean interactive) { this.interactive = interactive; @@ -243,10 +250,10 @@ public class HttpDownloadConnection implements Transferable { } catch (SSLHandshakeException e) { changeStatus(STATUS_OFFER); } catch (Exception e) { - if (interactive) { - showToastForException(e); - } - cancel(); + if (interactive) { + showToastForException(e); + } + cancel(); } } @@ -312,11 +319,12 @@ public class HttpDownloadConnection implements Transferable { MessageUtil.updateFileParams(message, mUrl); mXmppConnectionService.updateMessage(message); } + } public void updateProgress(int i) { - this.mProgress = i; - mXmppConnectionService.updateConversationUi(); + this.mProgress = i; + mXmppConnectionService.updateConversationUi(); } @Override |