|
|
@ -29,6 +29,8 @@ import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
|
|
|
|
|
|
public class ServiceExternal extends Service {
|
|
|
|
public class ServiceExternal extends Service {
|
|
|
@ -36,7 +38,7 @@ public class ServiceExternal extends Service {
|
|
|
|
private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE";
|
|
|
|
private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE";
|
|
|
|
private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE";
|
|
|
|
private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE";
|
|
|
|
|
|
|
|
|
|
|
|
// adb shell am startservice -a eu.faircode.email.POLL
|
|
|
|
// adb shell am startservice -a eu.faircode.email.POLL --es account Gmail
|
|
|
|
// adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail
|
|
|
|
// adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail
|
|
|
|
// adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail
|
|
|
|
// adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail
|
|
|
|
|
|
|
|
|
|
|
@ -73,20 +75,11 @@ public class ServiceExternal extends Service {
|
|
|
|
if (!ActivityBilling.isPro(this))
|
|
|
|
if (!ActivityBilling.isPro(this))
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
|
|
|
|
|
|
|
|
String action = intent.getAction();
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
final String accountName = intent.getStringExtra("account");
|
|
|
|
if (ACTION_POLL.equals(action)) {
|
|
|
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
WorkerPoll.sync(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Boolean enabled;
|
|
|
|
final Boolean enabled;
|
|
|
|
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (ACTION_ENABLE.equals(action))
|
|
|
|
if (ACTION_ENABLE.equals(action))
|
|
|
|
enabled = true;
|
|
|
|
enabled = true;
|
|
|
|
else if (ACTION_DISABLE.equals(action))
|
|
|
|
else if (ACTION_DISABLE.equals(action))
|
|
|
@ -94,32 +87,35 @@ public class ServiceExternal extends Service {
|
|
|
|
else
|
|
|
|
else
|
|
|
|
enabled = null;
|
|
|
|
enabled = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (enabled != null) {
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
final String accountName = intent.getStringExtra("account");
|
|
|
|
@Override
|
|
|
|
if (accountName == null) {
|
|
|
|
public void run() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if (accountName == null) {
|
|
|
|
prefs.edit().putBoolean("schedule", false).apply();
|
|
|
|
if (enabled == null)
|
|
|
|
|
|
|
|
WorkerPoll.sync(context, null);
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
prefs.edit().putBoolean("enabled", enabled).apply();
|
|
|
|
|
|
|
|
ServiceSynchronize.eval(context, "external enabled=" + enabled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
boolean previous = prefs.getBoolean("enabled", true);
|
|
|
|
EntityAccount account = db.account().getAccount(accountName);
|
|
|
|
if (!enabled.equals(previous)) {
|
|
|
|
if (account == null) {
|
|
|
|
prefs.edit().putBoolean("enabled", enabled).apply();
|
|
|
|
EntityLog.log(context, "Account not found name=" + accountName);
|
|
|
|
ServiceSynchronize.eval(this, "external");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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.eval(context, "account enabled=" + enabled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (enabled == null)
|
|
|
|
|
|
|
|
WorkerPoll.sync(context, account.id);
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
db.account().setAccountSynchronize(account.id, enabled);
|
|
|
|
|
|
|
|
ServiceSynchronize.eval(context, "external account=" + accountName + " enabled=" + enabled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
return START_NOT_STICKY;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|