Enable/disable via sync service

This commit is contained in:
M66B
2021-03-29 08:37:45 +02:00
parent 386475a4d9
commit 9ec584f08e
3 changed files with 22 additions and 7 deletions

View File

@@ -152,6 +152,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
static final int PI_ALARM = 1;
static final int PI_BACKOFF = 2;
static final int PI_KEEPALIVE = 3;
static final int PI_ENABLE = 4;
@Override
public void onCreate() {
@@ -792,6 +793,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (action != null)
try {
switch (action.split(":")[0]) {
case "enable":
onEnable(intent);
break;
case "eval":
onEval(intent);
break;
@@ -827,6 +832,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
return START_STICKY;
}
private void onEnable(Intent intent) {
boolean enabled = intent.getBooleanExtra("enabled", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("enabled", enabled).apply();
onEval(intent);
}
private void onEval(Intent intent) {
Bundle command = new Bundle();
command.putString("name", "eval");