background daemon doesn't start automatically if there are no enabled accounts. fixed #443 fixed #442

This commit is contained in:
iNPUTmice 2014-09-19 17:21:33 +02:00
parent 3da0d5adce
commit 2a185c8fc9
2 changed files with 13 additions and 2 deletions

View file

@ -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);
}
@ -222,6 +222,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
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() {
SQLiteDatabase db = super.getWritableDatabase();

View file

@ -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);
}
}
}