Clear block list cache on settings changes

pull/199/head
M66B 4 years ago
parent 67fb582a3a
commit 3c633e568e

@ -212,6 +212,10 @@ public class ApplicationEx extends Application
case "schedule_day6":
ServiceSynchronize.reschedule(this);
break;
case "check_blocklist":
case "use_blocklist":
DnsBlockList.clearCache();
break;
case "watchdog":
ServiceSynchronize.scheduleWatchdog(this);
break;

@ -82,16 +82,21 @@ public class DnsBlockList {
private static final long CACHE_EXPIRY_AFTER = 3600 * 1000L; // milliseconds
private static final Map<String, CacheEntry> cache = new Hashtable<>();
static void clearCache() {
Log.i("isJunk clear cache");
synchronized (cache) {
cache.clear();
}
}
static void setEnabled(Context context, BlockList blocklist, boolean enabled) {
Log.i("isJunk " + blocklist.name + "=" + enabled);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (blocklist.enabled == null || blocklist.enabled == enabled)
prefs.edit().remove("blocklist." + blocklist.name).apply();
else
prefs.edit().putBoolean("blocklist." + blocklist.name, enabled).apply();
synchronized (cache) {
cache.clear();
}
clearCache();
}
static boolean isEnabled(Context context, BlockList blocklist) {
@ -101,15 +106,13 @@ public class DnsBlockList {
}
static void reset(Context context) {
Log.i("isJunk reset");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
for (BlockList blocklist : BLOCK_LISTS)
editor.remove("blocklist." + blocklist.name);
editor.apply();
synchronized (cache) {
cache.clear();
}
clearCache();
}
static List<BlockList> getLists() {

@ -143,9 +143,8 @@ public class WorkerCleanup extends Worker {
ServiceSynchronize.reschedule(context);
DnsBlockList.clearCache();
MessageClassifier.cleanup(context);
// Contact info cache
ContactInfo.clearCache(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

Loading…
Cancel
Save