tried to avoid some more race conditions in jingle
This commit is contained in:
parent
8cc72b5a56
commit
1e5f916b2a
|
@ -100,11 +100,14 @@ public class FileBackend {
|
||||||
.decodeFile(getJingleFile(message).getAbsolutePath());
|
.decodeFile(getJingleFile(message).getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getThumbnailFromMessage(Message message, int size) {
|
public Bitmap getThumbnailFromMessage(Message message, int size) throws FileNotFoundException {
|
||||||
Bitmap thumbnail = thumbnailCache.get(message.getUuid());
|
Bitmap thumbnail = thumbnailCache.get(message.getUuid());
|
||||||
if (thumbnail==null) {
|
if (thumbnail==null) {
|
||||||
Bitmap fullsize = BitmapFactory.decodeFile(getJingleFile(message)
|
Bitmap fullsize = BitmapFactory.decodeFile(getJingleFile(message)
|
||||||
.getAbsolutePath());
|
.getAbsolutePath());
|
||||||
|
if (fullsize==null) {
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
}
|
||||||
thumbnail = resize(fullsize, size);
|
thumbnail = resize(fullsize, size);
|
||||||
this.thumbnailCache.put(message.getUuid(), thumbnail);
|
this.thumbnailCache.put(message.getUuid(), thumbnail);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
@ -277,9 +278,16 @@ public class ConversationFragment extends Fragment {
|
||||||
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
viewHolder.messageBody.setTextColor(0xff33B5E5);
|
||||||
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
|
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC);
|
||||||
} else {
|
} else {
|
||||||
viewHolder.image.setImageBitmap(activity.xmppConnectionService.getFileBackend().getThumbnailFromMessage(item,(int) (metrics.density * 288)));
|
try {
|
||||||
|
Bitmap thumbnail = activity.xmppConnectionService.getFileBackend().getThumbnailFromMessage(item,(int) (metrics.density * 288));
|
||||||
|
viewHolder.image.setImageBitmap(thumbnail);
|
||||||
viewHolder.messageBody.setVisibility(View.GONE);
|
viewHolder.messageBody.setVisibility(View.GONE);
|
||||||
viewHolder.image.setVisibility(View.VISIBLE);
|
viewHolder.image.setVisibility(View.VISIBLE);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
viewHolder.image.setVisibility(View.GONE);
|
||||||
|
viewHolder.messageBody.setText("error loading image file");
|
||||||
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
viewHolder.image.setVisibility(View.GONE);
|
viewHolder.image.setVisibility(View.GONE);
|
||||||
|
|
|
@ -45,7 +45,8 @@ public class JingleConnection {
|
||||||
private Element fileOffer;
|
private Element fileOffer;
|
||||||
private JingleFile file = null;
|
private JingleFile file = null;
|
||||||
|
|
||||||
private boolean receivedCandidateError = false;
|
private boolean receivedCandidate = false;
|
||||||
|
private boolean sentCandidate = false;
|
||||||
|
|
||||||
private OnIqPacketReceived responseListener = new OnIqPacketReceived() {
|
private OnIqPacketReceived responseListener = new OnIqPacketReceived() {
|
||||||
|
|
||||||
|
@ -110,13 +111,28 @@ public class JingleConnection {
|
||||||
this.mJingleConnectionManager.getPrimaryCandidate(account, new OnPrimaryCandidateFound() {
|
this.mJingleConnectionManager.getPrimaryCandidate(account, new OnPrimaryCandidateFound() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryCandidateFound(boolean success, JingleCandidate candidate) {
|
public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
|
||||||
if (success) {
|
if (success) {
|
||||||
mergeCandidate(candidate);
|
final SocksConnection socksConnection = new SocksConnection(JingleConnection.this, candidate);
|
||||||
}
|
connections.put(candidate.getCid(), socksConnection);
|
||||||
openOurCandidates();
|
socksConnection.connect(new OnSocksConnection() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed() {
|
||||||
sendInitRequest();
|
sendInitRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void established() {
|
||||||
|
mergeCandidate(candidate);
|
||||||
|
sendInitRequest();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mergeCandidate(candidate);
|
||||||
|
} else {
|
||||||
|
sendInitRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +164,7 @@ public class JingleConnection {
|
||||||
if (this.mXmppConnectionService.convChangedListener!=null) {
|
if (this.mXmppConnectionService.convChangedListener!=null) {
|
||||||
this.mXmppConnectionService.convChangedListener.onConversationListChanged();
|
this.mXmppConnectionService.convChangedListener.onConversationListChanged();
|
||||||
}
|
}
|
||||||
if (this.file.getExpectedSize()>=this.mJingleConnectionManager.getAutoAcceptFileSize()) {
|
if (this.file.getExpectedSize()<=this.mJingleConnectionManager.getAutoAcceptFileSize()) {
|
||||||
Log.d("xmppService","auto accepting file from "+packet.getFrom());
|
Log.d("xmppService","auto accepting file from "+packet.getFrom());
|
||||||
this.sendAccept();
|
this.sendAccept();
|
||||||
} else {
|
} else {
|
||||||
|
@ -185,31 +201,40 @@ public class JingleConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendAccept() {
|
private void sendAccept() {
|
||||||
|
status = STATUS_ACCEPTED;
|
||||||
|
connectNextCandidate();
|
||||||
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryCandidateFound(boolean success, JingleCandidate candidate) {
|
public void onPrimaryCandidateFound(boolean success,final JingleCandidate candidate) {
|
||||||
Content content = new Content();
|
final JinglePacket packet = bootstrapPacket("session-accept");
|
||||||
|
final Content content = new Content();
|
||||||
content.setFileOffer(fileOffer);
|
content.setFileOffer(fileOffer);
|
||||||
if (success) {
|
if ((success)&&(!equalCandidateExists(candidate))) {
|
||||||
if (!equalCandidateExists(candidate)) {
|
final SocksConnection socksConnection = new SocksConnection(JingleConnection.this, candidate);
|
||||||
mergeCandidate(candidate);
|
connections.put(candidate.getCid(), socksConnection);
|
||||||
}
|
socksConnection.connect(new OnSocksConnection() {
|
||||||
}
|
|
||||||
openOurCandidates();
|
|
||||||
content.setCandidates(transportId, getCandidatesAsElements());
|
|
||||||
JinglePacket packet = bootstrapPacket("session-accept");
|
|
||||||
packet.setContent(content);
|
|
||||||
account.getXmppConnection().sendIqPacket(packet, new OnIqPacketReceived() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void failed() {
|
||||||
if (packet.getType() != IqPacket.TYPE_ERROR) {
|
content.setCandidates(transportId, getCandidatesAsElements());
|
||||||
status = STATUS_ACCEPTED;
|
packet.setContent(content);
|
||||||
connectNextCandidate();
|
account.getXmppConnection().sendIqPacket(packet,responseListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void established() {
|
||||||
|
mergeCandidate(candidate);
|
||||||
|
content.setCandidates(transportId, getCandidatesAsElements());
|
||||||
|
packet.setContent(content);
|
||||||
|
account.getXmppConnection().sendIqPacket(packet,responseListener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
content.setCandidates(transportId, getCandidatesAsElements());
|
||||||
|
packet.setContent(content);
|
||||||
|
account.getXmppConnection().sendIqPacket(packet,responseListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -219,7 +244,7 @@ public class JingleConnection {
|
||||||
JinglePacket packet = new JinglePacket();
|
JinglePacket packet = new JinglePacket();
|
||||||
packet.setAction(action);
|
packet.setAction(action);
|
||||||
packet.setFrom(account.getFullJid());
|
packet.setFrom(account.getFullJid());
|
||||||
packet.setTo(this.message.getCounterpart()); //fixme, not right in all cases;
|
packet.setTo(this.message.getCounterpart());
|
||||||
packet.setSessionId(this.sessionId);
|
packet.setSessionId(this.sessionId);
|
||||||
packet.setInitiator(this.initiator);
|
packet.setInitiator(this.initiator);
|
||||||
return packet;
|
return packet;
|
||||||
|
@ -243,14 +268,15 @@ public class JingleConnection {
|
||||||
Log.d("xmppService","candidate used by counterpart:"+cid);
|
Log.d("xmppService","candidate used by counterpart:"+cid);
|
||||||
JingleCandidate candidate = getCandidate(cid);
|
JingleCandidate candidate = getCandidate(cid);
|
||||||
candidate.flagAsUsedByCounterpart();
|
candidate.flagAsUsedByCounterpart();
|
||||||
if (status == STATUS_ACCEPTED) {
|
this.receivedCandidate = true;
|
||||||
|
if ((status == STATUS_ACCEPTED)&&(this.sentCandidate)) {
|
||||||
this.connect();
|
this.connect();
|
||||||
} else {
|
} else {
|
||||||
Log.d("xmppService","ignoring because file is already in transmission");
|
Log.d("xmppService","ignoring because file is already in transmission or we havent sent our candidate yet");
|
||||||
}
|
}
|
||||||
} else if (content.hasCandidateError()) {
|
} else if (content.hasCandidateError()) {
|
||||||
Log.d("xmppService","received candidate error");
|
Log.d("xmppService","received candidate error");
|
||||||
this.receivedCandidateError = true;
|
this.receivedCandidate = true;
|
||||||
if (status == STATUS_ACCEPTED) {
|
if (status == STATUS_ACCEPTED) {
|
||||||
this.connect();
|
this.connect();
|
||||||
}
|
}
|
||||||
|
@ -334,7 +360,11 @@ public class JingleConnection {
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
if (connection!=null) {
|
||||||
Log.d("xmppService","chose candidate: "+connection.getCandidate().getHost());
|
Log.d("xmppService","chose candidate: "+connection.getCandidate().getHost());
|
||||||
|
} else {
|
||||||
|
Log.d("xmppService","couldn't find candidate");
|
||||||
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +392,7 @@ public class JingleConnection {
|
||||||
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_REJECTED);
|
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_REJECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openOurCandidates() {
|
/*private void openOurCandidates() {
|
||||||
for(JingleCandidate candidate : this.candidates) {
|
for(JingleCandidate candidate : this.candidates) {
|
||||||
if (candidate.isOurs()) {
|
if (candidate.isOurs()) {
|
||||||
final SocksConnection socksConnection = new SocksConnection(this,candidate);
|
final SocksConnection socksConnection = new SocksConnection(this,candidate);
|
||||||
|
@ -381,7 +411,7 @@ public class JingleConnection {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void connectNextCandidate() {
|
private void connectNextCandidate() {
|
||||||
for(JingleCandidate candidate : this.candidates) {
|
for(JingleCandidate candidate : this.candidates) {
|
||||||
|
@ -406,8 +436,7 @@ public class JingleConnection {
|
||||||
@Override
|
@Override
|
||||||
public void established() {
|
public void established() {
|
||||||
sendCandidateUsed(candidate.getCid());
|
sendCandidateUsed(candidate.getCid());
|
||||||
if ((receivedCandidateError)&&(status == STATUS_ACCEPTED)) {
|
if ((receivedCandidate)&&(status == STATUS_ACCEPTED)) {
|
||||||
Log.d("xmppService","received candidate error before. trying to connect");
|
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,6 +462,7 @@ public class JingleConnection {
|
||||||
packet.setContent(content);
|
packet.setContent(content);
|
||||||
Log.d("xmppService","send using candidate: "+cid);
|
Log.d("xmppService","send using candidate: "+cid);
|
||||||
this.account.getXmppConnection().sendIqPacket(packet,responseListener);
|
this.account.getXmppConnection().sendIqPacket(packet,responseListener);
|
||||||
|
this.sentCandidate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCandidateError() {
|
private void sendCandidateError() {
|
||||||
|
@ -445,6 +475,7 @@ public class JingleConnection {
|
||||||
packet.setContent(content);
|
packet.setContent(content);
|
||||||
Log.d("xmppService","send candidate error");
|
Log.d("xmppService","send candidate error");
|
||||||
this.account.getXmppConnection().sendIqPacket(packet,responseListener);
|
this.account.getXmppConnection().sendIqPacket(packet,responseListener);
|
||||||
|
this.sentCandidate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInitiator() {
|
public String getInitiator() {
|
||||||
|
|
Loading…
Reference in a new issue