Clear block list cache on settings changes

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

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

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

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

Loading…
Cancel
Save