From b53fb25058e726cdabc281b314287c3f83297e22 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 24 Sep 2019 19:45:46 +0200 Subject: [PATCH] Added intent poll --- FAQ.md | 7 +++++- app/src/main/AndroidManifest.xml | 1 + .../eu/faircode/email/ServiceExternal.java | 25 ++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/FAQ.md b/FAQ.md index f74dbb72c8..5a8efb6c1a 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1571,12 +1571,17 @@ You can also automate turning synchronization on and off by sending these comman 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 ``` +If you just want to automate checking for new messages, you can do this: + +``` +(adb shell) adb shell am startservice -a eu.faircode.email.POLL +``` + You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html): ``` diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 11b052ab47..80ddb98b46 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -225,6 +225,7 @@ android:foregroundServiceType="dataSync"> + diff --git a/app/src/main/java/eu/faircode/email/ServiceExternal.java b/app/src/main/java/eu/faircode/email/ServiceExternal.java index 552335259f..1024b32c9e 100644 --- a/app/src/main/java/eu/faircode/email/ServiceExternal.java +++ b/app/src/main/java/eu/faircode/email/ServiceExternal.java @@ -33,9 +33,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ServiceExternal extends Service { + private static final String ACTION_POLL = BuildConfig.APPLICATION_ID + ".POLL"; private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE"; 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.ENABLE --es account Gmail // adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail @@ -44,14 +46,22 @@ public class ServiceExternal extends Service { @Override public void onCreate() { + Log.i("Service external create"); super.onCreate(); startForeground(Helper.NOTIFICATION_EXTERNAL, getNotification().build()); } + @Override + public void onDestroy() { + Log.i("Service external destroy"); + stopForeground(true); + super.onDestroy(); + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { try { - Log.i("Received intent=" + intent); + EntityLog.log(this, "Service external intent=" + intent); Log.logExtras(intent); super.onStartCommand(intent, flags, startId); @@ -63,10 +73,17 @@ public class ServiceExternal extends Service { if (!ActivityBilling.isPro(this)) return START_NOT_STICKY; + String action = intent.getAction(); + + if (ACTION_POLL.equals(action)) { + ServiceSynchronize.process(this, true); + return START_NOT_STICKY; + } + final Boolean enabled; - if (ACTION_ENABLE.equals(intent.getAction())) + if (ACTION_ENABLE.equals(action)) enabled = true; - else if (ACTION_DISABLE.equals(intent.getAction())) + else if (ACTION_DISABLE.equals(action)) enabled = false; else enabled = null; @@ -100,7 +117,7 @@ public class ServiceExternal extends Service { return START_NOT_STICKY; } finally { - stopForeground(true); + stopSelf(startId); } }