make 'cancelled' work for jingle ft

This commit is contained in:
Daniel Gultsch 2018-10-08 10:31:41 +02:00
parent bdb8d98eb1
commit 57fe153ef1
4 changed files with 23 additions and 18 deletions

View File

@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -73,6 +74,7 @@ public class AbstractConnectionManager {
return os; return os;
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.d(Config.LOGTAG,"unable to create output stream", e);
return null; return null;
} }
try { try {
@ -82,6 +84,7 @@ public class AbstractConnectionManager {
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
return new CipherOutputStream(os, cipher); return new CipherOutputStream(os, cipher);
} catch (Exception e) { } catch (Exception e) {
Log.d(Config.LOGTAG,"unable to create cipher output stream", e);
return null; return null;
} }
} }

View File

@ -1141,7 +1141,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (m.hasFileOnRemoteHost() if (m.hasFileOnRemoteHost()
|| m.isGeoUri() || m.isGeoUri()
|| m.treatAsDownloadable() || m.treatAsDownloadable()
|| (t != null && t instanceof HttpDownloadConnection)) { || t instanceof HttpDownloadConnection) {
copyUrl.setVisible(true); copyUrl.setVisible(true);
} }
if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) { 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))); 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); showErrorMessage.setVisible(true);
} }
} }
@ -1705,7 +1705,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (transferable != null) { if (transferable != null) {
transferable.cancel(); transferable.cancel();
} else if (message.getStatus() != Message.STATUS_RECEIVED) { } 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);
} }
} }

View File

@ -81,6 +81,7 @@ public class JingleConnection implements Transferable {
private boolean sentCandidate = false; private boolean sentCandidate = false;
private boolean acceptedAutomatically = false; private boolean acceptedAutomatically = false;
private boolean cancelled = false;
private XmppAxolotlMessage mXmppAxolotlMessage; private XmppAxolotlMessage mXmppAxolotlMessage;
@ -89,13 +90,9 @@ public class JingleConnection implements Transferable {
private OutputStream mFileOutputStream; private OutputStream mFileOutputStream;
private InputStream mFileInputStream; private InputStream mFileInputStream;
private OnIqPacketReceived responseListener = new OnIqPacketReceived() { private OnIqPacketReceived responseListener = (account, packet) -> {
if (packet.getType() != IqPacket.TYPE.RESULT) {
@Override fail(IqParser.extractErrorMessage(packet));
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.RESULT) {
fail(IqParser.extractErrorMessage(packet));
}
} }
}; };
private byte[] expectedHash = new byte[0]; private byte[] expectedHash = new byte[0];
@ -485,7 +482,7 @@ public class JingleConnection implements Transferable {
try { try {
this.mFileInputStream = new FileInputStream(file); this.mFileInputStream = new FileInputStream(file);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
cancel(); abort();
return; return;
} }
content.setTransportId(this.transportId); content.setTransportId(this.transportId);
@ -863,7 +860,7 @@ public class JingleConnection implements Transferable {
this.mJingleStatus = JINGLE_STATUS_FINISHED; this.mJingleStatus = JINGLE_STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED); this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED);
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport != null && this.transport instanceof JingleInbandTransport) { if (this.transport instanceof JingleInbandTransport) {
this.transport.disconnect(); this.transport.disconnect();
} }
this.message.setTransferable(null); 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"); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": received session-terminate/success while responding");
} }
} }
@Override
public void cancel() { public void cancel() {
this.cancelled = true;
abort();
}
public void abort() {
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport != null && this.transport instanceof JingleInbandTransport) { if (this.transport instanceof JingleInbandTransport) {
this.transport.disconnect(); this.transport.disconnect();
} }
this.sendCancel(); this.sendCancel();
@ -887,7 +889,7 @@ public class JingleConnection implements Transferable {
} }
this.mJingleConnectionManager.updateConversationUi(true); this.mJingleConnectionManager.updateConversationUi(true);
} else { } 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); this.message.setTransferable(null);
} }
} }
@ -899,7 +901,7 @@ public class JingleConnection implements Transferable {
private void fail(String errorMessage) { private void fail(String errorMessage) {
this.mJingleStatus = JINGLE_STATUS_FAILED; this.mJingleStatus = JINGLE_STATUS_FAILED;
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport != null && this.transport instanceof JingleInbandTransport) { if (this.transport instanceof JingleInbandTransport) {
this.transport.disconnect(); this.transport.disconnect();
} }
FileBackend.close(mFileInputStream); FileBackend.close(mFileInputStream);
@ -914,7 +916,7 @@ public class JingleConnection implements Transferable {
} else { } else {
this.mXmppConnectionService.markMessage(this.message, this.mXmppConnectionService.markMessage(this.message,
Message.STATUS_SEND_FAILED, Message.STATUS_SEND_FAILED,
errorMessage); cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
this.message.setTransferable(null); this.message.setTransferable(null);
} }
} }

View File

@ -167,7 +167,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
public void cancelInTransmission() { public void cancelInTransmission() {
for (JingleConnection connection : this.connections) { for (JingleConnection connection : this.connections) {
if (connection.getJingleStatus() == JingleConnection.JINGLE_STATUS_TRANSMITTING) { if (connection.getJingleStatus() == JingleConnection.JINGLE_STATUS_TRANSMITTING) {
connection.cancel(); connection.abort();
} }
} }
} }