Added disconnect.me intent

pull/184/head
M66B 4 years ago
parent 674d5a0180
commit 3c2ae7bae8

@ -3150,6 +3150,12 @@ Tracking images will be disabled only if the corresponding main 'disable' option
Tracking images will not be recognized when the domain is classified as '*Content*',
see [here](https://disconnect.me/trackerprotection#trackers-we-dont-block) for more information.
This command can be sent to FairEmail from an automation app to update the protection lists:
```
(adb shell) am startservice -a eu.faircode.email.DISCONNECT.ME
```
<br />
## Support

@ -322,6 +322,7 @@
<action android:name="${applicationId}.POLL" />
<action android:name="${applicationId}.ENABLE" />
<action android:name="${applicationId}.DISABLE" />
<action android:name="${applicationId}.DISCONNECT.ME" />
</intent-filter>
</service>

@ -20,8 +20,11 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.SharedPreferences;
import android.os.SystemClock;
import androidx.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -31,6 +34,7 @@ import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -122,6 +126,9 @@ public class DisconnectBlacklist {
connection.disconnect();
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putLong("disconnect_last", new Date().getTime()).apply();
init(file);
}
@ -157,9 +164,4 @@ public class DisconnectBlacklist {
private static File getFile(Context context) {
return new File(context.getFilesDir(), "disconnect-blacklist.json");
}
static Long getTime(Context context) {
File file = getFile(context);
return (file.exists() ? file.lastModified() : null);
}
}

@ -376,9 +376,10 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
swSecure.setChecked(prefs.getBoolean("secure", false));
swSafeBrowsing.setChecked(prefs.getBoolean("safe_browsing", false));
Long time = DisconnectBlacklist.getTime(getContext());
long time = prefs.getLong("disconnect_last", -1);
DateFormat DF = SimpleDateFormat.getDateTimeInstance();
tvDisconnectBlacklistTime.setText(time == null ? null : DF.format(time));
tvDisconnectBlacklistTime.setText(time < 0 ? null : DF.format(time));
tvDisconnectBlacklistTime.setVisibility(time < 0 ? View.GONE : View.VISIBLE);
swDisconnectLinks.setChecked(prefs.getBoolean("disconnect_links", true));
swDisconnectImages.setChecked(prefs.getBoolean("disconnect_images", false));

@ -29,6 +29,10 @@ import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
@ -37,10 +41,12 @@ public class ServiceExternal extends Service {
private static final String ACTION_POLL = BuildConfig.APPLICATION_ID + ".POLL";
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_DISCONNECT_ME = BuildConfig.APPLICATION_ID + ".DISCONNECT.ME";
// 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.DISABLE --es account Gmail
// adb shell am startservice -a eu.faircode.email.DISCONNECT
private static final ExecutorService executor =
Helper.getBackgroundExecutor(1, "external");
@ -72,52 +78,35 @@ public class ServiceExternal extends Service {
if (intent == null)
return START_NOT_STICKY;
if (!ActivityBilling.isPro(this))
final String action = intent.getAction();
boolean pro = ActivityBilling.isPro(this);
EntityLog.log(this, action + " pro=" + pro);
if (!pro)
return START_NOT_STICKY;
final Context context = getApplicationContext();
final String accountName = intent.getStringExtra("account");
final Boolean enabled;
String action = intent.getAction();
if (ACTION_ENABLE.equals(action))
enabled = true;
else if (ACTION_DISABLE.equals(action))
enabled = false;
else // poll
enabled = null;
executor.submit(new Runnable() {
@Override
public void run() {
DB db = DB.getInstance(context);
if (enabled == null) {
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
for (EntityAccount account : accounts)
if (accountName == null || accountName.equals(account.name)) {
List<EntityFolder> folders = db.folder().getSynchronizingFolders(account.id);
if (folders.size() > 0)
Collections.sort(folders, folders.get(0).getComparator(context));
for (EntityFolder folder : folders)
EntityOperation.sync(context, folder.id, false);
}
ServiceSynchronize.eval(context, "external poll account=" + accountName);
} else {
if (accountName == null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.eval(context, "external enabled=" + enabled);
} else {
EntityAccount account = db.account().getAccount(accountName);
if (account == null) {
EntityLog.log(context, "Account not found name=" + accountName);
return;
}
db.account().setAccountSynchronize(account.id, enabled);
ServiceSynchronize.eval(context, "external account=" + accountName + " enabled=" + enabled);
try {
switch (action) {
case ACTION_POLL:
poll(context, intent);
break;
case ACTION_ENABLE:
case ACTION_DISABLE:
set(context, intent);
break;
case ACTION_DISCONNECT_ME:
disconnect(context, intent);
break;
default:
throw new IllegalArgumentException(action);
}
} catch (Throwable ex) {
Log.e(ex);
EntityLog.log(context, Log.formatThrowable(ex));
}
}
});
@ -149,4 +138,53 @@ public class ServiceExternal extends Service {
return builder;
}
private static void poll(Context context, Intent intent) {
String accountName = intent.getStringExtra("account");
DB db = DB.getInstance(context);
List<EntityAccount> accounts;
if (accountName == null)
accounts = db.account().getSynchronizingAccounts();
else {
EntityAccount account = db.account().getAccount(accountName);
if (account == null)
throw new IllegalArgumentException("Account not found name=" + accountName);
accounts = new ArrayList<>();
accounts.add(account);
}
for (EntityAccount account : accounts) {
List<EntityFolder> folders = db.folder().getSynchronizingFolders(account.id);
if (folders.size() > 0)
Collections.sort(folders, folders.get(0).getComparator(context));
for (EntityFolder folder : folders)
EntityOperation.sync(context, folder.id, false);
}
ServiceSynchronize.eval(context, "external poll account=" + accountName);
}
private static void set(Context context, Intent intent) {
String accountName = intent.getStringExtra("account");
boolean enabled = ACTION_ENABLE.equals(intent.getAction());
DB db = DB.getInstance(context);
if (accountName == null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.eval(context, "external enabled=" + enabled);
} else {
EntityAccount account = db.account().getAccount(accountName);
if (account == null)
throw new IllegalArgumentException("Account not found name=" + accountName);
db.account().setAccountSynchronize(account.id, enabled);
ServiceSynchronize.eval(context, "external account=" + accountName + " enabled=" + enabled);
}
}
private static void disconnect(Context context, Intent intent) throws IOException, JSONException {
DisconnectBlacklist.download(context);
}
}

Loading…
Cancel
Save