Added external enable/disable account

pull/160/head
M66B 6 years ago
parent 1053ba3ac1
commit 3cb8ffd0cd

@ -1505,6 +1505,13 @@ You can also automate turning synchronization on and off by sending these comman
Sending these commands will automatically turn scheduling off. Sending these commands will automatically turn scheduling off.
It is also possible to just enable/disable one account, for example the account with the name *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
```
You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html): You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html):
``` ```
@ -1514,6 +1521,14 @@ Action: eu.faircode.email.ENABLE
Target: Service Target: Service
``` ```
To enable/disable an account with the name *Gmail*:
```
Extras: account:Gmail
```
Account names are case sensitive.
Automation can be used for more advanced schedules, Automation can be used for more advanced schedules,
like for example multiple synchronization periods per day or different synchronization periods for different days. like for example multiple synchronization periods per day or different synchronization periods for different days.

@ -71,6 +71,9 @@ public interface DaoAccount {
@Query("SELECT * FROM account WHERE id = :id") @Query("SELECT * FROM account WHERE id = :id")
EntityAccount getAccount(long id); EntityAccount getAccount(long id);
@Query("SELECT * FROM account WHERE name = :name")
EntityAccount getAccount(String name);
@Query("SELECT * FROM account WHERE `primary`") @Query("SELECT * FROM account WHERE `primary`")
EntityAccount getPrimaryAccount(); EntityAccount getPrimaryAccount();

@ -20,6 +20,7 @@ package eu.faircode.email;
*/ */
import android.app.Service; import android.app.Service;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
@ -28,12 +29,17 @@ 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.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ServiceExternal extends Service { 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.ENABLE // adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail
// adb shell am startservice -a eu.faircode.email.DISABLE // adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail
private static ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
@Override @Override
@ -57,13 +63,17 @@ public class ServiceExternal extends Service {
if (!Helper.isPro(this)) if (!Helper.isPro(this))
return START_NOT_STICKY; return START_NOT_STICKY;
Boolean enabled = null; final Boolean enabled;
if (ACTION_ENABLE.equals(intent.getAction())) if (ACTION_ENABLE.equals(intent.getAction()))
enabled = true; enabled = true;
else if (ACTION_DISABLE.equals(intent.getAction())) else if (ACTION_DISABLE.equals(intent.getAction()))
enabled = false; enabled = false;
else
enabled = null;
if (enabled != null) { if (enabled != null) {
final String accountName = intent.getStringExtra("account");
if (accountName == null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("schedule", false).apply(); prefs.edit().putBoolean("schedule", false).apply();
@ -72,6 +82,20 @@ public class ServiceExternal extends Service {
prefs.edit().putBoolean("enabled", enabled).apply(); prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.reload(this, "external"); ServiceSynchronize.reload(this, "external");
} }
} 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.reload(context, "account enabled=" + enabled);
}
}
});
}
} }
return START_NOT_STICKY; return START_NOT_STICKY;

Loading…
Cancel
Save