Moved exists/reply to sync service

This commit is contained in:
M66B 2021-05-10 14:52:39 +02:00
parent df62478c64
commit 902213e935
3 changed files with 40 additions and 49 deletions

View File

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

View File

@ -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

View File

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