bullet proofing some code

This commit is contained in:
iNPUTmice 2014-10-08 14:10:37 +02:00
parent 3d88ffc5cd
commit 10411944b1
2 changed files with 23 additions and 8 deletions

View File

@ -210,6 +210,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
list.add(Account.fromCursor(cursor)); list.add(Account.fromCursor(cursor));
} }
cursor.close();
return list; return list;
} }
@ -232,6 +233,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ Account.TABLENAME + " where not options & (1 <<1)", null); + Account.TABLENAME + " where not options & (1 <<1)", null);
cursor.moveToFirst(); cursor.moveToFirst();
int count = cursor.getInt(0); int count = cursor.getInt(0);
cursor.close();
return (count > 0); return (count > 0);
} }
@ -258,6 +260,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
roster.initContact(Contact.fromCursor(cursor)); roster.initContact(Contact.fromCursor(cursor));
} }
cursor.close();
} }
public void writeRoster(Roster roster) { public void writeRoster(Roster roster) {

View File

@ -908,10 +908,12 @@ public class XmppConnectionService extends Service {
public void archiveConversation(Conversation conversation) { public void archiveConversation(Conversation conversation) {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
Bookmark bookmark = conversation.getBookmark(); if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
if (bookmark != null && bookmark.autojoin()) { Bookmark bookmark = conversation.getBookmark();
bookmark.setAutojoin(false); if (bookmark != null && bookmark.autojoin()) {
pushBookmarks(bookmark.getAccount()); bookmark.setAutojoin(false);
pushBookmarks(bookmark.getAccount());
}
} }
leaveMuc(conversation); leaveMuc(conversation);
} else { } else {
@ -1639,7 +1641,8 @@ public class XmppConnectionService extends Service {
String id = conversation.getLatestMarkableMessageId(); String id = conversation.getLatestMarkableMessageId();
conversation.markRead(); conversation.markRead();
if (confirmMessages() && id != null && calledByUi) { if (confirmMessages() && id != null && calledByUi) {
Log.d(Config.LOGTAG,conversation.getAccount().getJid()+": sending read marker for "+conversation.getName()); Log.d(Config.LOGTAG, conversation.getAccount().getJid()
+ ": sending read marker for " + conversation.getName());
Account account = conversation.getAccount(); Account account = conversation.getAccount();
String to = conversation.getContactJid(); String to = conversation.getContactJid();
this.sendMessagePacket(conversation.getAccount(), this.sendMessagePacket(conversation.getAccount(),
@ -1722,16 +1725,25 @@ public class XmppConnectionService extends Service {
} }
public void sendMessagePacket(Account account, MessagePacket packet) { public void sendMessagePacket(Account account, MessagePacket packet) {
account.getXmppConnection().sendMessagePacket(packet); XmppConnection connection = account.getXmppConnection();
if (connection != null) {
connection.sendMessagePacket(packet);
}
} }
public void sendPresencePacket(Account account, PresencePacket packet) { public void sendPresencePacket(Account account, PresencePacket packet) {
account.getXmppConnection().sendPresencePacket(packet); XmppConnection connection = account.getXmppConnection();
if (connection != null) {
connection.sendPresencePacket(packet);
}
} }
public void sendIqPacket(Account account, IqPacket packet, public void sendIqPacket(Account account, IqPacket packet,
OnIqPacketReceived callback) { OnIqPacketReceived callback) {
account.getXmppConnection().sendIqPacket(packet, callback); XmppConnection connection = account.getXmppConnection();
if (connection != null) {
connection.sendIqPacket(packet, callback);
}
} }
public MessageGenerator getMessageGenerator() { public MessageGenerator getMessageGenerator() {