|
|
|
@ -20,6 +20,7 @@ package eu.faircode.email;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import android.app.Service;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.os.IBinder;
|
|
|
|
@ -28,12 +29,17 @@ import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
|
public class ServiceExternal extends Service {
|
|
|
|
|
private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE";
|
|
|
|
|
private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE";
|
|
|
|
|
|
|
|
|
|
// adb shell am startservice -a eu.faircode.email.ENABLE
|
|
|
|
|
// adb shell am startservice -a eu.faircode.email.DISABLE
|
|
|
|
|
// adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail
|
|
|
|
|
// adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail
|
|
|
|
|
|
|
|
|
|
private static ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -57,20 +63,38 @@ public class ServiceExternal extends Service {
|
|
|
|
|
if (!Helper.isPro(this))
|
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
|
|
|
|
|
|
Boolean enabled = null;
|
|
|
|
|
final Boolean enabled;
|
|
|
|
|
if (ACTION_ENABLE.equals(intent.getAction()))
|
|
|
|
|
enabled = true;
|
|
|
|
|
else if (ACTION_DISABLE.equals(intent.getAction()))
|
|
|
|
|
enabled = false;
|
|
|
|
|
else
|
|
|
|
|
enabled = null;
|
|
|
|
|
|
|
|
|
|
if (enabled != null) {
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
prefs.edit().putBoolean("schedule", false).apply();
|
|
|
|
|
|
|
|
|
|
boolean previous = prefs.getBoolean("enabled", true);
|
|
|
|
|
if (!enabled.equals(previous)) {
|
|
|
|
|
prefs.edit().putBoolean("enabled", enabled).apply();
|
|
|
|
|
ServiceSynchronize.reload(this, "external");
|
|
|
|
|
final String accountName = intent.getStringExtra("account");
|
|
|
|
|
if (accountName == null) {
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
prefs.edit().putBoolean("schedule", false).apply();
|
|
|
|
|
|
|
|
|
|
boolean previous = prefs.getBoolean("enabled", true);
|
|
|
|
|
if (!enabled.equals(previous)) {
|
|
|
|
|
prefs.edit().putBoolean("enabled", enabled).apply();
|
|
|
|
|
ServiceSynchronize.reload(this, "external");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
EntityAccount account = db.account().getAccount(accountName);
|
|
|
|
|
if (account != null) {
|
|
|
|
|
db.account().setAccountSynchronize(account.id, enabled);
|
|
|
|
|
ServiceSynchronize.reload(context, "account enabled=" + enabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|