Restart services on exact alarm changes

pull/200/head
M66B 3 years ago
parent 683dd0ebe8
commit f902b584f4

@ -19,19 +19,18 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.app.AlarmManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class ReceiverAutoStart extends BroadcastReceiver {
// https://developer.android.com/reference/android/app/AlarmManager#ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED
private final String ACTION_EXACT =
"android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED";
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_EXACT.equals(action) ||
if (AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED.equals(action) ||
Intent.ACTION_BOOT_COMPLETED.equals(action) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
EntityLog.log(context, "Received " + intent);
@ -39,12 +38,13 @@ public class ReceiverAutoStart extends BroadcastReceiver {
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action))
ApplicationEx.upgrade(context);
if (ACTION_EXACT.equals(action))
ServiceSynchronize.reload(context, null, false, action);
else {
ServiceSynchronize.boot(context);
ServiceSend.boot(context);
if (AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED.equals(action)) {
ServiceSynchronize.stop(context);
ServiceSend.stop(context);
}
ServiceSynchronize.boot(context);
ServiceSend.boot(context);
}
}
}

@ -800,6 +800,10 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
}
}
static void stop(Context context) {
context.stopService(new Intent(context, ServiceSend.class));
}
static void schedule(Context context, long delay) {
Intent intent = new Intent(context, ServiceSend.class);
PendingIntent pi = PendingIntentCompat.getForegroundService(

@ -2710,8 +2710,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
.setAction("watchdog"));
}
static void restart(Context context) {
static void stop(Context context) {
context.stopService(new Intent(context, ServiceSynchronize.class));
}
static void restart(Context context) {
stop(context);
eval(context, "restart");
}

Loading…
Cancel
Save