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.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;
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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();
}
}
}