Allow extern poll of individual accounts

pull/169/head
M66B 5 years ago
parent bd9416bd25
commit 616526ff16

@ -1711,29 +1711,32 @@ so there is little room for performance improvements.
<a name="faq78"></a> <a name="faq78"></a>
**(78) How do I use schedules?** **(78) How do I use schedules?**
In the settingss you can enable scheduling and set the time to turn synchronizing automatically on and off. In the receive settings you can enable scheduling and set the time period for when messages should be received.
An end time equal to or earlier than the start time is considered to be 24 hours later. Note that an end time equal to or earlier than the start time is considered to be 24 hours later.
Turning FairEmail on or off, for example by using [a quick settings tile](#user-content-faq30), will not turn scheduling off. For more complex schemes you could set one or more accounts to manual synchronization
This means that the next schedule event will still turn FairEmail on or off. and send this command to FairEmail to check for new messages:
You can also automate turning synchronization on and off by sending these commands to FairEmail:
``` ```
(adb shell) am startservice -a eu.faircode.email.ENABLE (adb shell) am startservice -a eu.faircode.email.POLL
(adb shell) am startservice -a eu.faircode.email.DISABLE
``` ```
Sending these commands will turn scheduling off. For a specific account:
If you want to automate checking for new messages, you can send this command to FairEmail: ```
(adb shell) am startservice -a eu.faircode.email.POLL --es account Gmail
```
You can also automate turning receiving messages on and off by sending these commands to FairEmail:
``` ```
(adb shell) adb shell am startservice -a eu.faircode.email.POLL (adb shell) am startservice -a eu.faircode.email.ENABLE
(adb shell) am startservice -a eu.faircode.email.DISABLE
``` ```
It is also possible to enable/disable an account, for example the account with the name *Gmail*: To enable/disable a specific account:
``` ```
(adb shell) am startservice -a eu.faircode.email.ENABLE --es account Gmail (adb shell) am startservice -a eu.faircode.email.ENABLE --es account Gmail
(adb shell) am startservice -a eu.faircode.email.DISABLE --es account Gmail (adb shell) am startservice -a eu.faircode.email.DISABLE --es account Gmail

@ -779,7 +779,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
WorkerPoll.sync(context); WorkerPoll.sync(context, null);
return null; return null;
} }

@ -29,6 +29,8 @@ import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
public class ServiceExternal extends Service { public class ServiceExternal extends Service {
@ -36,7 +38,7 @@ public class ServiceExternal extends Service {
private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE"; private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE";
private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE"; private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE";
// adb shell am startservice -a eu.faircode.email.POLL // adb shell am startservice -a eu.faircode.email.POLL --es account Gmail
// adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail // adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail
// adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail // adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail
@ -73,20 +75,11 @@ public class ServiceExternal extends Service {
if (!ActivityBilling.isPro(this)) if (!ActivityBilling.isPro(this))
return START_NOT_STICKY; return START_NOT_STICKY;
String action = intent.getAction(); final Context context = getApplicationContext();
final String accountName = intent.getStringExtra("account");
if (ACTION_POLL.equals(action)) {
final Context context = getApplicationContext();
executor.submit(new Runnable() {
@Override
public void run() {
WorkerPoll.sync(context);
}
});
return START_NOT_STICKY;
}
final Boolean enabled; final Boolean enabled;
String action = intent.getAction();
if (ACTION_ENABLE.equals(action)) if (ACTION_ENABLE.equals(action))
enabled = true; enabled = true;
else if (ACTION_DISABLE.equals(action)) else if (ACTION_DISABLE.equals(action))
@ -94,32 +87,35 @@ public class ServiceExternal extends Service {
else else
enabled = null; enabled = null;
if (enabled != null) { executor.submit(new Runnable() {
final String accountName = intent.getStringExtra("account"); @Override
if (accountName == null) { public void run() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (accountName == null) {
prefs.edit().putBoolean("schedule", false).apply(); if (enabled == null)
WorkerPoll.sync(context, null);
else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.eval(context, "external enabled=" + enabled);
}
} else {
DB db = DB.getInstance(context);
boolean previous = prefs.getBoolean("enabled", true); EntityAccount account = db.account().getAccount(accountName);
if (!enabled.equals(previous)) { if (account == null) {
prefs.edit().putBoolean("enabled", enabled).apply(); EntityLog.log(context, "Account not found name=" + accountName);
ServiceSynchronize.eval(this, "external"); return;
}
} else {
final Context context = getApplicationContext();
executor.submit(new Runnable() {
@Override
public void run() {
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(accountName);
if (account != null) {
db.account().setAccountSynchronize(account.id, enabled);
ServiceSynchronize.eval(context, "account enabled=" + enabled);
}
} }
});
if (enabled == null)
WorkerPoll.sync(context, account.id);
else {
db.account().setAccountSynchronize(account.id, enabled);
ServiceSynchronize.eval(context, "external account=" + accountName + " enabled=" + enabled);
}
}
} }
} });
return START_NOT_STICKY; return START_NOT_STICKY;
} finally { } finally {

@ -101,7 +101,7 @@ public class ServiceTileUnseen extends TileService {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
WorkerPoll.sync(context); WorkerPoll.sync(context, null);
} }
}).start(); }).start();
} }

@ -45,7 +45,7 @@ public class WorkerPoll extends Worker {
public Result doWork() { public Result doWork() {
Log.i("Running " + getName()); Log.i("Running " + getName());
sync(getApplicationContext()); sync(getApplicationContext(), null);
return Result.success(); return Result.success();
} }
@ -76,19 +76,20 @@ public class WorkerPoll extends Worker {
} }
} }
static void sync(Context context) { static void sync(Context context, Long aid) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
List<EntityAccount> accounts = db.account().getSynchronizingAccounts(); List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
for (EntityAccount account : accounts) { for (EntityAccount account : accounts)
List<EntityFolder> folders = db.folder().getSynchronizingFolders(account.id); if (aid == null || account.id.equals(aid)) {
if (folders.size() > 0) List<EntityFolder> folders = db.folder().getSynchronizingFolders(account.id);
Collections.sort(folders, folders.get(0).getComparator(context)); if (folders.size() > 0)
for (EntityFolder folder : folders) Collections.sort(folders, folders.get(0).getComparator(context));
EntityOperation.sync(context, folder.id, false); for (EntityFolder folder : folders)
} EntityOperation.sync(context, folder.id, false);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

Loading…
Cancel
Save