From 2a185c8fc97ad82525ae18efe67026019d04442d Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 19 Sep 2014 17:21:33 +0200 Subject: background daemon doesn't start automatically if there are no enabled accounts. fixed #443 fixed #442 --- src/eu/siacs/conversations/persistance/DatabaseBackend.java | 10 +++++++++- src/eu/siacs/conversations/services/EventReceiver.java | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index cda2f356..51fd79e5 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -32,7 +32,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { + ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT + ", " + Contact.JID + ") ON CONFLICT REPLACE);"; - public DatabaseBackend(Context context) { + private DatabaseBackend(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @@ -221,6 +221,14 @@ public class DatabaseBackend extends SQLiteOpenHelper { String[] args = { account.getUuid() }; db.delete(Account.TABLENAME, Account.UUID + "=?", args); } + + public boolean hasEnabledAccounts() { + SQLiteDatabase db = this.getReadableDatabase(); + Cursor cursor= db.rawQuery("select count("+Account.UUID+") from "+Account.TABLENAME+" where not options & (1 <<1)", null); + cursor.moveToFirst(); + int count = cursor.getInt(0); + return (count>0); + } @Override public SQLiteDatabase getWritableDatabase() { diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index c0bf67f3..e2445b2a 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.services; +import eu.siacs.conversations.persistance.DatabaseBackend; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -14,7 +15,9 @@ public class EventReceiver extends BroadcastReceiver { } else { mIntentForService.setAction("other"); } - context.startService(mIntentForService); + if (intent.getAction().equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { + context.startService(mIntentForService); + } } } -- cgit v1.2.3