From 7793d9b3923d412fa09e83d3fde9bea27b0874e2 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 20 Oct 2018 21:39:59 +0200 Subject: make 'cancelled' work for jingle ft --- .../services/AbstractConnectionManager.java | 6 ++++- .../pixart/messenger/ui/ConversationFragment.java | 6 ++--- .../messenger/xmpp/jingle/JingleConnection.java | 28 ++++++++++++---------- .../xmpp/jingle/JingleConnectionManager.java | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java index e29d91618..7cf2b7a93 100644 --- a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java +++ b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java @@ -3,6 +3,7 @@ package de.pixart.messenger.services; import android.content.Context; import android.os.PowerManager; import android.os.SystemClock; +import android.util.Log; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -21,6 +22,7 @@ import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.DownloadableFile; import de.pixart.messenger.utils.Compatibility; @@ -73,6 +75,7 @@ public class AbstractConnectionManager { return os; } } catch (FileNotFoundException e) { + Log.d(Config.LOGTAG, "unable to create output stream", e); return null; } try { @@ -89,7 +92,8 @@ public class AbstractConnectionManager { return new CipherOutputStream(os, cipher); } } catch (Exception e) { - throw new AssertionError(e); + Log.d(Config.LOGTAG, "unable to create cipher output stream", e); + return null; } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 48eb19909..91cc911c3 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1363,7 +1363,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke || m.isGeoUri() || m.isXmppUri() || m.treatAsDownloadable() - || (t != null && t instanceof HttpDownloadConnection)) { + || t instanceof HttpDownloadConnection) { copyUrl.setVisible(true); } if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) { @@ -1384,7 +1384,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m))); } } - if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) { + if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage())) { showErrorMessage.setVisible(true); } } @@ -1961,7 +1961,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (transferable != null) { transferable.cancel(); } else if (message.getStatus() != Message.STATUS_RECEIVED) { - activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); + activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, Message.ERROR_MESSAGE_CANCELLED); } } 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 77540bc9c..2f3ec09ea 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java @@ -84,6 +84,7 @@ public class JingleConnection implements Transferable { private boolean sentCandidate = false; private boolean acceptedAutomatically = false; + private boolean cancelled = false; private XmppAxolotlMessage mXmppAxolotlMessage; @@ -92,13 +93,9 @@ public class JingleConnection implements Transferable { private OutputStream mFileOutputStream; private InputStream mFileInputStream; - private OnIqPacketReceived responseListener = new OnIqPacketReceived() { - - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() != IqPacket.TYPE.RESULT) { - fail(IqParser.extractErrorMessage(packet)); - } + private OnIqPacketReceived responseListener = (account, packet) -> { + if (packet.getType() != IqPacket.TYPE.RESULT) { + fail(IqParser.extractErrorMessage(packet)); } }; private byte[] expectedHash = new byte[0]; @@ -512,7 +509,7 @@ public class JingleConnection implements Transferable { try { this.mFileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { - cancel(); + abort(); return; } content.setTransportId(this.transportId); @@ -889,7 +886,7 @@ public class JingleConnection implements Transferable { this.mJingleStatus = JINGLE_STATUS_FINISHED; this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED); this.disconnectSocks5Connections(); - if (this.transport != null && this.transport instanceof JingleInbandTransport) { + if (this.transport instanceof JingleInbandTransport) { this.transport.disconnect(); } this.message.setTransferable(null); @@ -900,8 +897,13 @@ public class JingleConnection implements Transferable { } public void cancel() { + this.cancelled = true; + abort(); + } + + public void abort() { this.disconnectSocks5Connections(); - if (this.transport != null && this.transport instanceof JingleInbandTransport) { + if (this.transport instanceof JingleInbandTransport) { this.transport.disconnect(); } this.sendCancel(); @@ -913,7 +915,7 @@ public class JingleConnection implements Transferable { } this.mJingleConnectionManager.updateConversationUi(true); } else { - this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED); + this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : null); this.message.setTransferable(null); } } @@ -925,7 +927,7 @@ public class JingleConnection implements Transferable { private void fail(String errorMessage) { this.mJingleStatus = JINGLE_STATUS_FAILED; this.disconnectSocks5Connections(); - if (this.transport != null && this.transport instanceof JingleInbandTransport) { + if (this.transport instanceof JingleInbandTransport) { this.transport.disconnect(); } FileBackend.close(mFileInputStream); @@ -940,7 +942,7 @@ public class JingleConnection implements Transferable { } else { this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED, - errorMessage); + cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage); this.message.setTransferable(null); } } diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java index de0ce1ea0..bef7a000d 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnectionManager.java @@ -167,7 +167,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { public void cancelInTransmission() { for (JingleConnection connection : this.connections) { if (connection.getJingleStatus() == JingleConnection.JINGLE_STATUS_TRANSMITTING) { - connection.cancel(); + connection.abort(); } } } -- cgit v1.2.3