diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index 132b27179..616146df1 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -164,7 +164,6 @@ public class Contact extends AbstractEntity implements Serializable { public void updatePresence(String resource, int status) { this.presences.updatePresence(resource, status); - Log.d("xmppService","updatingPresence for contact="+this.jid+" resource="+resource+" num="+presences.size()); } public void removePresence(String resource) { diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index 68fc56cde..ad4555c2e 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -207,6 +207,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { ContentValues values = contact.getContentValues(); if (!updatePresences) { 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 + "=?", args); @@ -231,7 +235,6 @@ public class DatabaseBackend extends SQLiteOpenHelper { if (cursor.getCount()>=1) { cursor.moveToFirst(); contact.setUuid(cursor.getString(0)); - //contact.setPresences(Presences.fromJsonString(cursor.getString(1))); updateContact(contact,false); } else { contact.setUuid(UUID.randomUUID().toString()); diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 7433946b2..307a9e2c5 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.persistance; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -10,6 +11,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.util.Log; import android.util.LruCache; import eu.siacs.conversations.entities.Conversation; @@ -25,7 +27,7 @@ public class FileBackend { public FileBackend(Context context) { this.context = context; - + int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); int cacheSize = maxMemory / 8; thumbnailCache = new LruCache(cacheSize) { @@ -45,7 +47,7 @@ public class FileBackend { String filename = message.getUuid() + ".webp"; return new JingleFile(path + "/" + filename); } - + private Bitmap resize(Bitmap originalBitmap, int size) { int w = originalBitmap.getWidth(); int h = originalBitmap.getHeight(); @@ -59,8 +61,8 @@ public class FileBackend { scalledW = size; scalledH = (int) (h / ((double) w / size)); } - Bitmap scalledBitmap = Bitmap.createScaledBitmap( - originalBitmap, scalledW, scalledH, true); + Bitmap scalledBitmap = Bitmap.createScaledBitmap(originalBitmap, + scalledW, scalledH, true); return scalledBitmap; } else { return originalBitmap; @@ -78,9 +80,10 @@ public class FileBackend { Bitmap originalBitmap = BitmapFactory.decodeStream(is); is.close(); 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) { - //Log.d("xmppService", "couldnt compress"); + // Log.d("xmppService", "couldnt compress"); } os.close(); return file; @@ -96,16 +99,17 @@ public class FileBackend { } public Bitmap getImageFromMessage(Message message) { - return BitmapFactory - .decodeFile(getJingleFile(message).getAbsolutePath()); + return BitmapFactory.decodeFile(getJingleFile(message) + .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()); - if (thumbnail==null) { + if (thumbnail == null) { Bitmap fullsize = BitmapFactory.decodeFile(getJingleFile(message) .getAbsolutePath()); - if (fullsize==null) { + if (fullsize == null) { throw new FileNotFoundException(); } thumbnail = resize(fullsize, size); @@ -113,4 +117,25 @@ public class FileBackend { } 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(); + } } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 69f0b8af5..b68dab641 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -290,7 +290,7 @@ public class XmppConnectionService extends Service { if ("subscribe".equals(type)) { account.getXmppConnection().addPendingSubscription(fromParts[0]); } else { - Log.d(LOGTAG,packet.getFrom()+ " could not be found"); + //Log.d(LOGTAG,packet.getFrom()+ " could not be found"); } return; } @@ -667,7 +667,6 @@ public class XmppConnectionService extends Service { @Override public void onBind(Account account) { - Log.d("xmppService","bount. cleaning presences"); databaseBackend.clearPresences(account); account.clearPresences(); // self presences if (account.getXmppConnection().hasFeatureRosterManagment()) { diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index a70484378..b221ec0cc 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -186,8 +186,7 @@ public class JingleConnection { this.transportId = this.mJingleConnectionManager.nextRandomId(); content.setCandidates(this.transportId,getCandidatesAsElements()); packet.setContent(content); - Log.d("xmppService",packet.toString()); - account.getXmppConnection().sendIqPacket(packet, this.responseListener); + this.sendJinglePacket(packet); this.status = STATUS_INITIATED; } } @@ -219,7 +218,7 @@ public class JingleConnection { public void failed() { content.setCandidates(transportId, getCandidatesAsElements()); packet.setContent(content); - account.getXmppConnection().sendIqPacket(packet,responseListener); + sendJinglePacket(packet); } @Override @@ -227,13 +226,13 @@ public class JingleConnection { mergeCandidate(candidate); content.setCandidates(transportId, getCandidatesAsElements()); packet.setContent(content); - account.getXmppConnection().sendIqPacket(packet,responseListener); + sendJinglePacket(packet); } }); } else { content.setCandidates(transportId, getCandidatesAsElements()); packet.setContent(content); - account.getXmppConnection().sendIqPacket(packet,responseListener); + sendJinglePacket(packet); } } }); @@ -250,8 +249,12 @@ public class JingleConnection { return packet; } + private void sendJinglePacket(JinglePacket packet) { + Log.d("xmppService",packet.toPrettyString()); + account.getXmppConnection().sendIqPacket(packet,responseListener); + } + private void accept(JinglePacket packet) { - Log.d("xmppService","session-accept: "+packet.toString()); Content content = packet.getJingleContent(); mergeCandidates(JingleCandidate.parse(content.getCanditates())); this.status = STATUS_ACCEPTED; @@ -286,66 +289,72 @@ public class JingleConnection { private void connect() { final SocksConnection connection = chooseConnection(); - this.status = STATUS_TRANSMITTING; - final OnFileTransmitted callback = new OnFileTransmitted() { - - @Override - public void onFileTransmitted(JingleFile file) { - if (responder.equals(account.getFullJid())) { - sendSuccess(); - mXmppConnectionService.markMessage(message, Message.STATUS_SEND); - } - 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() { + if (connection==null) { + Log.d("xmppService","could not find suitable candidate"); + this.disconnect(); + this.status = STATUS_FAILED; + this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED); + } else { + this.status = STATUS_TRANSMITTING; + final OnFileTransmitted callback = new OnFileTransmitted() { @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"); + public void onFileTransmitted(JingleFile file) { + if (responder.equals(account.getFullJid())) { + sendSuccess(); + mXmppConnectionService.markMessage(message, Message.STATUS_SEND); } + Log.d("xmppService","sucessfully transmitted file. sha1:"+file.getSha1Sum()); } - }); - } else { - if (initiator.equals(account.getFullJid())) { - Log.d("xmppService","we were initiating. sending file"); - connection.send(file,callback); + }; + 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 + 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 { - Log.d("xmppService","we were responding. receiving file"); - connection.receive(file,callback); + if (initiator.equals(account.getFullJid())) { + 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() { - Log.d("xmppService","choosing connection from "+this.connections.size()+" possibilties"); SocksConnection connection = null; Iterator> it = this.connections.entrySet().iterator(); while (it.hasNext()) { Entry pairs = it.next(); 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()))) { - Log.d("xmppService","is usable"); + //Log.d("xmppService","is usable"); if (connection==null) { connection = currentConnection; } else { if (connection.getCandidate().getPriority()