mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 11:28:41 +01:00
Start service at boot only if synchronizing accounts
This commit is contained in:
@@ -44,6 +44,9 @@ public interface DaoAccount {
|
||||
@Query("SELECT * FROM account WHERE `primary`")
|
||||
EntityAccount getPrimaryAccount();
|
||||
|
||||
@Query("SELECT COUNT(*) FROM account WHERE synchronize")
|
||||
int getSynchronizingAccountCount();
|
||||
|
||||
@Query("SELECT * FROM account WHERE `primary`")
|
||||
LiveData<EntityAccount> livePrimaryAccount();
|
||||
|
||||
|
||||
@@ -22,12 +22,21 @@ package eu.faircode.email;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class ReceiverAutostart extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()))
|
||||
ServiceSynchronize.start(context);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int synchronizing = DB.getInstance(context).account().getSynchronizingAccountCount();
|
||||
Log.i(Helper.TAG, "Synchronizing accounts=" + synchronizing);
|
||||
if (synchronizing > 0)
|
||||
ServiceSynchronize.start(context);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user