gt: 					new OnPrimaryCandidateFound() {
context: package eu.siacs.conversations.xmpp.jingle;
  
  import android.util.Log;
  import android.util.Pair;
  
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map.Entry;
  import java.util.concurrent.ConcurrentHashMap;
  
  import eu.siacs.conversations.Config;
  import eu.siacs.conversations.crypto.axolotl.AxolotlService;
  import eu.siacs.conversations.crypto.axolotl.OnMessageCreatedCallback;
  import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
  import eu.siacs.conversations.entities.Account;
  import eu.siacs.conversations.entities.Conversation;
  import eu.siacs.conversations.entities.DownloadableFile;
  import eu.siacs.conversations.entities.Message;
  import eu.siacs.conversations.entities.Presence;
  import eu.siacs.conversations.entities.ServiceDiscoveryResult;
  import eu.siacs.conversations.entities.Transferable;
  import eu.siacs.conversations.entities.TransferablePlaceholder;
  import eu.siacs.conversations.persistance.FileBackend;
  import eu.siacs.conversations.services.AbstractConnectionManager;
  import eu.siacs.conversations.services.XmppConnectionService;
  import eu.siacs.conversations.xml.Element;
  import eu.siacs.conversations.xmpp.OnIqPacketReceived;
  import eu.siacs.conversations.xmpp.jid.Jid;
  import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
  import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
  import eu.siacs.conversations.xmpp.jingle.stanzas.Reason;
  import eu.siacs.conversations.xmpp.stanzas.IqPacket;
  
  public class JingleConnection implements Transferable {
  
  	private JingleConnectionManager mJingleConnectionManager;
  	private XmppConnectionService mXmppConnectionService;
  
  	protected static final int JINGLE_STATUS_INITIATED = 0;
  	protected static final int JINGLE_STATUS_ACCEPTED = 1;
  	protected static final int JINGLE_STATUS_FINISHED = 4;
  	protected static final int JINGLE_STATUS_TRANSMITTING = 5;
  	protected static final int JINGLE_STATUS_FAILED = 99;
  
  	private Content.Version ftVersion = Content.Version.FT_3;
  
  	private int ibbBlockSize = 8192;
  
  	private int mJingleStatus = -1;
  	private int mStatus = Transferable.STATUS_UNKNOWN;
  	private Message message;
  	private String sessionId;
  	private Account account;
  	private Jid initiator;
  	private Jid responder;
  	private List<JingleCandidate> candidates = new ArrayList<>();
  	private ConcurrentHashMap<String, JingleSocks5Transport> connections = new ConcurrentHashMap<>();
  
  	private String transportId;
  	private Element fileOffer;
  	private DownloadableFile file = null;
  
  	private String contentName;
  	private String contentCreator;
  
  	private int mProgress = 0;
  
  	private boolean receivedCandidate = false;
  	private boolean sentCandidate = false;
  
  	private boolean acceptedAutomatically = false;
  
  	private XmppAxolotlMessage mXmppAxolotlMessage;
  
  	private JingleTransport transport = null;
  
  	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();
  			}
  		}
  	};
  
  	final OnFileTransmissionStatusChanged onFileTransmissionSatusChanged = new OnFileTransmissionStatusChanged() {
  
  		@Override
  		public void onFileTransmitted(DownloadableFile file) {
  			if (responder.equals(account.getJid())) {
  				sendSuccess();
  				mXmppConnectionService.getFileBackend().updateFileParams(message);
  				mXmppConnectionService.databaseBackend.createMessage(message);
  				mXmppConnectionService.markMessage(message,Message.STATUS_RECEIVED);
  				if (acceptedAutomatically) {
  					message.markUnread();
  					if (message.getEncryption() == Message.ENCRYPTION_PGP) {
  						account.getPgpDecryptionService().decrypt(message, true);
  					} else {
  						JingleConnection.this.mXmppConnectionService.getNotificationService().push(message);
  					}
  				}
  			} else {
  				if (message.getEncryption() == Message.ENCRYPTION_PGP) {
  					account.getPgpDecryptionService().decrypt(message, false);
  				}
  				if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
  					file.delete();
  				}
  			}
  			Log.d(Config.LOGTAG,"successfully transmitted file:" + file.getAbsolutePath()+" ("+file.getSha1Sum()+")");
  			if (message.getEncryption() != Message.ENCRYPTION_PGP) {
  				mXmppConnectionService.getFileBackend().updateMediaScanner(file);
  			}
  		}
  
  		@Override
  		public void onFileTransferAborted() {
  			JingleConnection.this.sendCancel();
  			JingleConnection.this.fail();
  		}
  	};
  
  	public InputStream getFileInputStream() {
  		return this.mFileInputStream;
  	}
  
  	public OutputStream getFileOutputStream() {
  		return this.mFileOutputStream;
  	}
  
  	private OnProxyActivated onProxyActivated = new OnProxyActivated() {
  
  		@Override
  		public void success() {
  			if (initiator.equals(account.getJid())) {
  				Log.d(Config.LOGTAG, "we were initiating. sending file");
  				transport.send(file, onFileTransmissionSatusChanged);
  			} else {
  				transport.receive(file, onFileTransmissionSatusChanged);
  				Log.d(Config.LOGTAG, "we were responding. receiving file");
  			}
  		}
  
  		@Override
  		public void failed() {
  			Log.d(Config.LOGTAG, "proxy activation failed");
  		}
  	};
  
  	public JingleConnection(JingleConnectionManager mJingleConnectionManager) {
  		this.mJingleConnectionManager = mJingleConnectionManager;
  		this.mXmppConnectionService = mJingleConnectionManager
  				.getXmppConnectionService();
  	}
  
  	public String getSessionId() {
  		return this.sessionId;
  	}
  
  	public Account getAccount() {
  		return this.account;
  	}
  
  	public Jid getCounterPart() {
  		return this.message.getCounterpart();
  	}
  
  	public void deliverPacket(JinglePacket packet) {
  		boolean returnResult = true;
  		if (packet.isAction("session-terminate")) {
  			Reason reason = packet.getReason();
  			if (reason != null) {
  				if (reason.hasChild("cancel")) {
  					this.fail();
  				} else if (reason.hasChild("success")) {
  					this.receiveSuccess();
  				} else {
  					this.fail();
  				}
  			} else {
  				this.fail();
  			}
  		} else if (packet.isAction("session-accept")) {
  			returnResult = receiveAccept(packet);
  		} else if (packet.isAction("transport-info")) {
  			returnResult = receiveTransportInfo(packet);
  		} else if (packet.isAction("transport-replace")) {
  			if (packet.getJingleContent().hasIbbTransport()) {
  				returnResult = this.receiveFallbackToIbb(packet);
  			} else {
  				returnResult = false;
  				Log.d(Config.LOGTAG, "trying to fallback to something unknown"
  						+ packet.toString());
  			}
  		} else if (packet.isAction("transport-accept")) {
  			returnResult = this.receiveTransportAccept(packet);
  		} else {
  			Log.d(Config.LOGTAG, "packet arrived in connection. action was "
  					+ packet.getAction());
  			returnResult = false;
  		}
  		IqPacket response;
  		if (returnResult) {
  			response = packet.generateResponse(IqPacket.TYPE.RESULT);
  
  		} else {
  			response = packet.generateResponse(IqPacket.TYPE.ERROR);
  		}
  		mXmppConnectionService.sendIqPacket(account,response,null);
  	}
  
  	public void init(final Message message) {
  		if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
  			Conversation conversation = message.getConversation();
  			conversation.getAccount().getAxolotlService().prepareKeyTransportMessage(conversation, new OnMessageCreatedCallback() {
  				@Override
  				public void run(XmppAxolotlMessage xmppAxolotlMessage) {
  					if (xmppAxolotlMessage != null) {
  						init(message, xmppAxolotlMessage);
  					} else {
  						fail();
  					}
  				}
  			});
  		} else {
  			init(message, null);
  		}
  	}
  
  	private void init(Message message, XmppAxolotlMessage xmppAxolotlMessage) {
  		this.mXmppAxolotlMessage = xmppAxolotlMessage;
  		this.contentCreator = "initiator";
  		this.contentName = this.mJingleConnectionManager.nextRandomId();
  		this.message = message;
  		this.account = message.getConversation().getAccount();
  		upgradeNamespace();
  		this.message.setTransferable(this);
  		this.mStatus = Transferable.STATUS_UPLOADING;
  		this.initiator = this.account.getJid();
  		this.responder = this.message.getCounterpart();
  		this.sessionId = this.mJingleConnectionManager.nextRandomId();
  		this.transportId = this.mJingleConnectionManager.nextRandomId();
  		if (this.candidates.size() > 0) {
  			this.sendInitRequest();
  		} else {
  			this.mJingleConnectionManager.getPrimaryCandidate(account,
  