From 57fe153ef1268b70254398a6e94b999a14190291 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 8 Oct 2018 10:31:41 +0200 Subject: [PATCH] make 'cancelled' work for jingle ft --- .../services/AbstractConnectionManager.java | 3 ++ .../ui/ConversationFragment.java | 6 ++-- .../xmpp/jingle/JingleConnection.java | 30 ++++++++++--------- .../xmpp/jingle/JingleConnectionManager.java | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java index 92a0ba039..48c8a91dc 100644 --- a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java @@ -6,6 +6,7 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.PowerManager; import android.os.SystemClock; +import android.util.Log; import android.util.Pair; import java.io.FileInputStream; @@ -73,6 +74,7 @@ public class AbstractConnectionManager { return os; } } catch (FileNotFoundException e) { + Log.d(Config.LOGTAG,"unable to create output stream", e); return null; } try { @@ -82,6 +84,7 @@ public class AbstractConnectionManager { cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); return new CipherOutputStream(os, cipher); } catch (Exception e) { + Log.d(Config.LOGTAG,"unable to create cipher output stream", e); return null; } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index f1f8a44e8..b37e57b45 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1141,7 +1141,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (m.hasFileOnRemoteHost() || m.isGeoUri() || m.treatAsDownloadable() - || (t != null && t instanceof HttpDownloadConnection)) { + || t instanceof HttpDownloadConnection) { copyUrl.setVisible(true); } if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) { @@ -1161,7 +1161,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); } } @@ -1705,7 +1705,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/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 96d558dc2..c96be3134 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -81,6 +81,7 @@ public class JingleConnection implements Transferable { private boolean sentCandidate = false; private boolean acceptedAutomatically = false; + private boolean cancelled = false; private XmppAxolotlMessage mXmppAxolotlMessage; @@ -89,13 +90,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]; @@ -485,7 +482,7 @@ public class JingleConnection implements Transferable { try { this.mFileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { - cancel(); + abort(); return; } content.setTransportId(this.transportId); @@ -863,7 +860,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); @@ -872,10 +869,15 @@ public class JingleConnection implements Transferable { Log.d(Config.LOGTAG,account.getJid().asBareJid()+": received session-terminate/success while responding"); } } - + @Override 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(); @@ -887,7 +889,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); } } @@ -899,7 +901,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); @@ -914,7 +916,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/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 23c0f12fe..237fd1229 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/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(); } } }