Added automation support

This commit is contained in:
M66B
2019-02-14 13:28:14 +00:00
parent 572607a76b
commit 582ce275db
6 changed files with 115 additions and 19 deletions

View File

@@ -0,0 +1,46 @@
package eu.faircode.email;
import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.annotation.Nullable;
public class ServiceExternal extends IntentService {
private final static String ACTION_ENABLE = "eu.faircode.email.ENABLE";
private final static String ACTION_DISABLE = "eu.faircode.email.DISABLE";
// adb shell am startservice -a eu.faircode.email.ENABLE
// adb shell am startservice -a eu.faircode.email.DISABLE
public ServiceExternal() {
super(ServiceExternal.class.getName());
}
public ServiceExternal(String name) {
super(name);
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
if (intent == null)
return;
Boolean enabled = null;
if (ACTION_ENABLE.equals(intent.getAction()))
enabled = true;
else if (ACTION_DISABLE.equals(intent.getAction()))
enabled = false;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean previous = prefs.getBoolean("enabled", true);
if (enabled != null) {
prefs.edit().putBoolean("schedule", false).apply();
if (!enabled.equals(previous)) {
prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.reload(this, "external");
}
}
}
}