cleaned up debug log a little bit

This commit is contained in:
Daniel Gultsch 2014-04-19 01:14:30 +02:00
parent 7ccbf0008a
commit 5c0873c7ca
7 changed files with 118 additions and 91 deletions

View file

@ -164,7 +164,6 @@ public class Contact extends AbstractEntity implements Serializable {
public void updatePresence(String resource, int status) { public void updatePresence(String resource, int status) {
this.presences.updatePresence(resource, status); this.presences.updatePresence(resource, status);
Log.d("xmppService","updatingPresence for contact="+this.jid+" resource="+resource+" num="+presences.size());
} }
public void removePresence(String resource) { public void removePresence(String resource) {

View file

@ -207,6 +207,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
ContentValues values = contact.getContentValues(); ContentValues values = contact.getContentValues();
if (!updatePresences) { if (!updatePresences) {
values.remove(Contact.PRESENCES); values.remove(Contact.PRESENCES);
} else {
values.remove(Contact.DISPLAYNAME);
values.remove(Contact.PHOTOURI);
values.remove(Contact.SYSTEMACCOUNT);
} }
db.update(Contact.TABLENAME, contact.getContentValues(), Contact.UUID db.update(Contact.TABLENAME, contact.getContentValues(), Contact.UUID
+ "=?", args); + "=?", args);
@ -231,7 +235,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (cursor.getCount()>=1) { if (cursor.getCount()>=1) {
cursor.moveToFirst(); cursor.moveToFirst();
contact.setUuid(cursor.getString(0)); contact.setUuid(cursor.getString(0));
//contact.setPresences(Presences.fromJsonString(cursor.getString(1)));
updateContact(contact,false); updateContact(contact,false);
} else { } else {
contact.setUuid(UUID.randomUUID().toString()); contact.setUuid(UUID.randomUUID().toString());

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.persistance; package eu.siacs.conversations.persistance;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -10,6 +11,7 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import android.util.LruCache; import android.util.LruCache;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -25,7 +27,7 @@ public class FileBackend {
public FileBackend(Context context) { public FileBackend(Context context) {
this.context = context; this.context = context;
int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
int cacheSize = maxMemory / 8; int cacheSize = maxMemory / 8;
thumbnailCache = new LruCache<String, Bitmap>(cacheSize) { thumbnailCache = new LruCache<String, Bitmap>(cacheSize) {
@ -45,7 +47,7 @@ public class FileBackend {
String filename = message.getUuid() + ".webp"; String filename = message.getUuid() + ".webp";
return new JingleFile(path + "/" + filename); return new JingleFile(path + "/" + filename);
} }
private Bitmap resize(Bitmap originalBitmap, int size) { private Bitmap resize(Bitmap originalBitmap, int size) {
int w = originalBitmap.getWidth(); int w = originalBitmap.getWidth();
int h = originalBitmap.getHeight(); int h = originalBitmap.getHeight();
@ -59,8 +61,8 @@ public class FileBackend {
scalledW = size; scalledW = size;
scalledH = (int) (h / ((double) w / size)); scalledH = (int) (h / ((double) w / size));
} }
Bitmap scalledBitmap = Bitmap.createScaledBitmap( Bitmap scalledBitmap = Bitmap.createScaledBitmap(originalBitmap,
originalBitmap, scalledW, scalledH, true); scalledW, scalledH, true);
return scalledBitmap; return scalledBitmap;
} else { } else {
return originalBitmap; return originalBitmap;
@ -78,9 +80,10 @@ public class FileBackend {
Bitmap originalBitmap = BitmapFactory.decodeStream(is); Bitmap originalBitmap = BitmapFactory.decodeStream(is);
is.close(); is.close();
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE); Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
boolean success = scalledBitmap.compress(Bitmap.CompressFormat.WEBP,75,os); boolean success = scalledBitmap.compress(
Bitmap.CompressFormat.WEBP, 75, os);
if (!success) { if (!success) {
//Log.d("xmppService", "couldnt compress"); // Log.d("xmppService", "couldnt compress");
} }
os.close(); os.close();
return file; return file;
@ -96,16 +99,17 @@ public class FileBackend {
} }
public Bitmap getImageFromMessage(Message message) { public Bitmap getImageFromMessage(Message message) {
return BitmapFactory return BitmapFactory.decodeFile(getJingleFile(message)
.decodeFile(getJingleFile(message).getAbsolutePath()); .getAbsolutePath());
} }
public Bitmap getThumbnailFromMessage(Message message, int size) throws FileNotFoundException { 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) { if (fullsize == null) {
throw new FileNotFoundException(); throw new FileNotFoundException();
} }
thumbnail = resize(fullsize, size); thumbnail = resize(fullsize, size);
@ -113,4 +117,25 @@ public class FileBackend {
} }
return thumbnail; return thumbnail;
} }
public void removeFiles(Conversation conversation) {
String prefix = context.getFilesDir().getAbsolutePath();
String path = prefix + "/" + conversation.getAccount().getJid() + "/"
+ conversation.getContactJid();
File file = new File(path);
try {
this.deleteFile(file);
} catch (IOException e) {
Log.d("xmppService",
"error deleting file: " + file.getAbsolutePath());
}
}
private void deleteFile(File f) throws IOException {
if (f.isDirectory()) {
for (File c : f.listFiles())
deleteFile(c);
}
f.delete();
}
} }

View file

@ -290,7 +290,7 @@ public class XmppConnectionService extends Service {
if ("subscribe".equals(type)) { if ("subscribe".equals(type)) {
account.getXmppConnection().addPendingSubscription(fromParts[0]); account.getXmppConnection().addPendingSubscription(fromParts[0]);
} else { } else {
Log.d(LOGTAG,packet.getFrom()+ " could not be found"); //Log.d(LOGTAG,packet.getFrom()+ " could not be found");
} }
return; return;
} }
@ -667,7 +667,6 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onBind(Account account) { public void onBind(Account account) {
Log.d("xmppService","bount. cleaning presences");
databaseBackend.clearPresences(account); databaseBackend.clearPresences(account);
account.clearPresences(); // self presences account.clearPresences(); // self presences
if (account.getXmppConnection().hasFeatureRosterManagment()) { if (account.getXmppConnection().hasFeatureRosterManagment()) {

View file

@ -186,8 +186,7 @@ public class JingleConnection {
this.transportId = this.mJingleConnectionManager.nextRandomId(); this.transportId = this.mJingleConnectionManager.nextRandomId();
content.setCandidates(this.transportId,getCandidatesAsElements()); content.setCandidates(this.transportId,getCandidatesAsElements());
packet.setContent(content); packet.setContent(content);
Log.d("xmppService",packet.toString()); this.sendJinglePacket(packet);
account.getXmppConnection().sendIqPacket(packet, this.responseListener);
this.status = STATUS_INITIATED; this.status = STATUS_INITIATED;
} }
} }
@ -219,7 +218,7 @@ public class JingleConnection {
public void failed() { public void failed() {
content.setCandidates(transportId, getCandidatesAsElements()); content.setCandidates(transportId, getCandidatesAsElements());
packet.setContent(content); packet.setContent(content);
account.getXmppConnection().sendIqPacket(packet,responseListener); sendJinglePacket(packet);
} }
@Override @Override
@ -227,13 +226,13 @@ public class JingleConnection {
mergeCandidate(candidate); mergeCandidate(candidate);
content.setCandidates(transportId, getCandidatesAsElements()); content.setCandidates(transportId, getCandidatesAsElements());
packet.setContent(content); packet.setContent(content);
account.getXmppConnection().sendIqPacket(packet,responseListener); sendJinglePacket(packet);
} }
}); });
} else { } else {
content.setCandidates(transportId, getCandidatesAsElements()); content.setCandidates(transportId, getCandidatesAsElements());
packet.setContent(content); packet.setContent(content);
account.getXmppConnection().sendIqPacket(packet,responseListener); sendJinglePacket(packet);
} }
} }
}); });
@ -250,8 +249,12 @@ public class JingleConnection {
return packet; return packet;
} }
private void sendJinglePacket(JinglePacket packet) {
Log.d("xmppService",packet.toPrettyString());
account.getXmppConnection().sendIqPacket(packet,responseListener);
}
private void accept(JinglePacket packet) { private void accept(JinglePacket packet) {
Log.d("xmppService","session-accept: "+packet.toString());
Content content = packet.getJingleContent(); Content content = packet.getJingleContent();
mergeCandidates(JingleCandidate.parse(content.getCanditates())); mergeCandidates(JingleCandidate.parse(content.getCanditates()));
this.status = STATUS_ACCEPTED; this.status = STATUS_ACCEPTED;
@ -286,66 +289,72 @@ public class JingleConnection {
private void connect() { private void connect() {
final SocksConnection connection = chooseConnection(); final SocksConnection connection = chooseConnection();
this.status = STATUS_TRANSMITTING; if (connection==null) {
final OnFileTransmitted callback = new OnFileTransmitted() { Log.d("xmppService","could not find suitable candidate");
this.disconnect();
@Override this.status = STATUS_FAILED;
public void onFileTransmitted(JingleFile file) { this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED);
if (responder.equals(account.getFullJid())) { } else {
sendSuccess(); this.status = STATUS_TRANSMITTING;
mXmppConnectionService.markMessage(message, Message.STATUS_SEND); final OnFileTransmitted callback = new OnFileTransmitted() {
}
Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum());
}
};
if (connection.isProxy()&&(connection.getCandidate().isOurs())) {
Log.d("xmppService","candidate "+connection.getCandidate().getCid()+" was our proxy and needs activation");
IqPacket activation = new IqPacket(IqPacket.TYPE_SET);
activation.setTo(connection.getCandidate().getJid());
activation.query("http://jabber.org/protocol/bytestreams").setAttribute("sid", this.getSessionId());
activation.query().addChild("activate").setContent(this.getCounterPart());
this.account.getXmppConnection().sendIqPacket(activation, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onFileTransmitted(JingleFile file) {
Log.d("xmppService","activation result: "+packet.toString()); if (responder.equals(account.getFullJid())) {
if (initiator.equals(account.getFullJid())) { sendSuccess();
Log.d("xmppService","we were initiating. sending file"); mXmppConnectionService.markMessage(message, Message.STATUS_SEND);
connection.send(file,callback);
} else {
connection.receive(file,callback);
Log.d("xmppService","we were responding. receiving file");
} }
Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum());
} }
}); };
} else { if (connection.isProxy()&&(connection.getCandidate().isOurs())) {
if (initiator.equals(account.getFullJid())) { Log.d("xmppService","candidate "+connection.getCandidate().getCid()+" was our proxy and needs activation");
Log.d("xmppService","we were initiating. sending file"); IqPacket activation = new IqPacket(IqPacket.TYPE_SET);
connection.send(file,callback); activation.setTo(connection.getCandidate().getJid());
activation.query("http://jabber.org/protocol/bytestreams").setAttribute("sid", this.getSessionId());
activation.query().addChild("activate").setContent(this.getCounterPart());
this.account.getXmppConnection().sendIqPacket(activation, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Log.d("xmppService","activation result: "+packet.toString());
if (initiator.equals(account.getFullJid())) {
Log.d("xmppService","we were initiating. sending file");
connection.send(file,callback);
} else {
connection.receive(file,callback);
Log.d("xmppService","we were responding. receiving file");
}
}
});
} else { } else {
Log.d("xmppService","we were responding. receiving file"); if (initiator.equals(account.getFullJid())) {
connection.receive(file,callback); Log.d("xmppService","we were initiating. sending file");
connection.send(file,callback);
} else {
Log.d("xmppService","we were responding. receiving file");
connection.receive(file,callback);
}
} }
} }
} }
private SocksConnection chooseConnection() { private SocksConnection chooseConnection() {
Log.d("xmppService","choosing connection from "+this.connections.size()+" possibilties");
SocksConnection connection = null; SocksConnection connection = null;
Iterator<Entry<String, SocksConnection>> it = this.connections.entrySet().iterator(); Iterator<Entry<String, SocksConnection>> it = this.connections.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Entry<String, SocksConnection> pairs = it.next(); Entry<String, SocksConnection> pairs = it.next();
SocksConnection currentConnection = pairs.getValue(); SocksConnection currentConnection = pairs.getValue();
Log.d("xmppService","comparing candidate: "+currentConnection.getCandidate().toString()); //Log.d("xmppService","comparing candidate: "+currentConnection.getCandidate().toString());
if (currentConnection.isEstablished()&&(currentConnection.getCandidate().isUsedByCounterpart()||(!currentConnection.getCandidate().isOurs()))) { if (currentConnection.isEstablished()&&(currentConnection.getCandidate().isUsedByCounterpart()||(!currentConnection.getCandidate().isOurs()))) {
Log.d("xmppService","is usable"); //Log.d("xmppService","is usable");
if (connection==null) { if (connection==null) {
connection = currentConnection; connection = currentConnection;
} else { } else {
if (connection.getCandidate().getPriority()<currentConnection.getCandidate().getPriority()) { if (connection.getCandidate().getPriority()<currentConnection.getCandidate().getPriority()) {
connection = currentConnection; connection = currentConnection;
} else if (connection.getCandidate().getPriority()==currentConnection.getCandidate().getPriority()) { } else if (connection.getCandidate().getPriority()==currentConnection.getCandidate().getPriority()) {
Log.d("xmppService","found two candidates with same priority"); //Log.d("xmppService","found two candidates with same priority");
if (initiator.equals(account.getFullJid())) { if (initiator.equals(account.getFullJid())) {
if (currentConnection.getCandidate().isOurs()) { if (currentConnection.getCandidate().isOurs()) {
connection = currentConnection; connection = currentConnection;
@ -359,11 +368,6 @@ public class JingleConnection {
} }
} }
it.remove(); it.remove();
}
if (connection!=null) {
Log.d("xmppService","chose candidate: "+connection.getCandidate().getHost());
} else {
Log.d("xmppService","couldn't find candidate");
} }
return connection; return connection;
} }
@ -373,8 +377,7 @@ public class JingleConnection {
Reason reason = new Reason(); Reason reason = new Reason();
reason.addChild("success"); reason.addChild("success");
packet.setReason(reason); packet.setReason(reason);
Log.d("xmppService","sending success. "+packet.toString()); this.sendJinglePacket(packet);
this.account.getXmppConnection().sendIqPacket(packet, responseListener);
this.disconnect(); this.disconnect();
this.status = STATUS_FINISHED; this.status = STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_RECIEVED); this.mXmppConnectionService.markMessage(this.message, Message.STATUS_RECIEVED);
@ -391,28 +394,7 @@ public class JingleConnection {
this.status = STATUS_CANCELED; this.status = STATUS_CANCELED;
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_REJECTED); this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_REJECTED);
} }
/*private void openOurCandidates() {
for(JingleCandidate candidate : this.candidates) {
if (candidate.isOurs()) {
final SocksConnection socksConnection = new SocksConnection(this,candidate);
connections.put(candidate.getCid(), socksConnection);
socksConnection.connect(new OnSocksConnection() {
@Override
public void failed() {
Log.d("xmppService","connection to our candidate failed");
}
@Override
public void established() {
Log.d("xmppService","connection to our candidate was successful");
}
});
}
}
}*/
private void connectNextCandidate() { private void connectNextCandidate() {
for(JingleCandidate candidate : this.candidates) { for(JingleCandidate candidate : this.candidates) {
if ((!connections.containsKey(candidate.getCid())&&(!candidate.isOurs()))) { if ((!connections.containsKey(candidate.getCid())&&(!candidate.isOurs()))) {
@ -430,11 +412,13 @@ public class JingleConnection {
@Override @Override
public void failed() { public void failed() {
Log.d("xmppService", "connection failed with "+candidate.getHost()+":"+candidate.getPort());
connectNextCandidate(); connectNextCandidate();
} }
@Override @Override
public void established() { public void established() {
Log.d("xmppService", "established connection with "+candidate.getHost()+":"+candidate.getPort());
sendCandidateUsed(candidate.getCid()); sendCandidateUsed(candidate.getCid());
if ((receivedCandidate)&&(status == STATUS_ACCEPTED)) { if ((receivedCandidate)&&(status == STATUS_ACCEPTED)) {
connect(); connect();
@ -461,7 +445,7 @@ public class JingleConnection {
content.setUsedCandidate(this.transportId, cid); content.setUsedCandidate(this.transportId, cid);
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.sendJinglePacket(packet);
this.sentCandidate = true; this.sentCandidate = true;
} }
@ -474,7 +458,7 @@ public class JingleConnection {
content.setCandidateError(this.transportId); content.setCandidateError(this.transportId);
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.sendJinglePacket(packet);
this.sentCandidate = true; this.sentCandidate = true;
} }

View file

@ -69,7 +69,6 @@ public class SocksConnection {
inputStream.read(result); inputStream.read(result);
int status = result[1]; int status = result[1];
if (status == 0) { if (status == 0) {
Log.d("xmppService", "established connection with "+candidate.getHost()+":"+candidate.getPort()+ "/" + destination);
isEstablished = true; isEstablished = true;
callback.established(); callback.established();
} else { } else {

View file

@ -92,4 +92,22 @@ public class JinglePacket extends IqPacket {
public boolean isAction(String action) { public boolean isAction(String action) {
return action.equalsIgnoreCase(this.getAction()); return action.equalsIgnoreCase(this.getAction());
} }
public String toPrettyString() {
StringBuilder output = new StringBuilder();
output.append("["+getAction()+ " to:"+getTo()+" ");
if (this.content!=null) {
if (this.content.getUsedCandidate()!=null) {
output.append("used-candidate="+this.content.getUsedCandidate());
} else if (this.content.hasCandidateError()) {
output.append("candidate-error");
} else {
for(Element c : this.content.getCanditates()) {
output.append("["+c.getAttribute("host")+":"+c.getAttribute("port")+"]");
}
}
}
output.append("]");
return output.toString();
}
} }