From 902213e93527cb68cde655109fd7b09130234023 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 10 May 2021 14:52:39 +0200 Subject: [PATCH] Moved exists/reply to sync service --- app/src/main/java/eu/faircode/email/Core.java | 4 +- .../java/eu/faircode/email/ServiceSend.java | 47 ------------------- .../eu/faircode/email/ServiceSynchronize.java | 38 +++++++++++++++ 3 files changed, 40 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 3fa6fa862d..e0a81c2bc0 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1766,10 +1766,10 @@ class Core { else if (imessages == null || imessages.length == 0) { long next = new Date().getTime() + EXISTS_RETRY_DELAY; - Intent intent = new Intent(context, ServiceSend.class); + Intent intent = new Intent(context, ServiceSynchronize.class); intent.setAction("exists:" + message.id); PendingIntent piExists = PendingIntentCompat.getForegroundService( - context, ServiceSend.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT); + context, ServiceSynchronize.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piExists); diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 9798d6200b..f84debdbcc 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -78,7 +78,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar private static final int CONNECTIVITY_DELAY = 5000; // milliseconds static final int PI_SEND = 1; - static final int PI_EXISTS = 2; @Override public void onCreate() { @@ -198,20 +197,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar Log.i("Send intent=" + intent); Log.logExtras(intent); - if (intent == null) - return START_STICKY; - - String action = intent.getAction(); - if (action == null) - return START_STICKY; - - String[] parts = action.split(":"); - switch (parts[0]) { - case "exists": - onExists(intent); - break; - } - return START_STICKY; } @@ -763,38 +748,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar ServiceSynchronize.eval(this, "sent"); } - private void onExists(Intent intent) { - String action = intent.getAction(); - long id = Long.parseLong(action.split(":")[1]); - - executor.submit(new Runnable() { - @Override - public void run() { - try { - DB db = DB.getInstance(ServiceSend.this); - - try { - db.beginTransaction(); - - // Message could have been deleted in the meantime - EntityMessage message = db.message().getMessage(id); - if (message == null) - return; - - EntityOperation.queue(ServiceSend.this, message, EntityOperation.EXISTS, true); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - } catch (Throwable ex) { - Log.e(ex); - } - } - }); - } - static void boot(final Context context) { executor.submit(new Runnable() { @Override diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index e42549680f..a2a15133b9 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -159,6 +159,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences static final int PI_POLL = 5; static final int PI_WATCHDOG = 6; static final int PI_UNSNOOZE = 7; + static final int PI_EXISTS = 8; @Override public void onCreate() { @@ -823,6 +824,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences onUnsnooze(intent); break; + case "exists": + onExists(intent); + break; + case "state": onState(intent); break; @@ -985,6 +990,39 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences }); } + private void onExists(Intent intent) { + String action = intent.getAction(); + long id = Long.parseLong(action.split(":")[1]); + + executor.submit(new Runnable() { + @Override + public void run() { + try { + DB db = DB.getInstance(ServiceSynchronize.this); + + try { + db.beginTransaction(); + + // Message could have been deleted in the meantime + EntityMessage message = db.message().getMessage(id); + if (message == null) + return; + + EntityOperation.queue(ServiceSynchronize.this, message, EntityOperation.EXISTS, true); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + eval(ServiceSynchronize.this, "exists/delayed"); + } catch (Throwable ex) { + Log.e(ex); + } + } + }); + } + private void onState(Intent intent) { foreground = intent.getBooleanExtra("foreground", false); }