Browse Source

Start service at boot only if synchronizing accounts

main
M66B 6 years ago
parent
commit
3fee5e24ec
2 changed files with 14 additions and 2 deletions
  1. +3
    -0
      app/src/main/java/eu/faircode/email/DaoAccount.java
  2. +11
    -2
      app/src/main/java/eu/faircode/email/ReceiverAutostart.java

+ 3
- 0
app/src/main/java/eu/faircode/email/DaoAccount.java View File

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


+ 11
- 2
app/src/main/java/eu/faircode/email/ReceiverAutostart.java View File

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

Loading…
Cancel
Save