|
|
@ -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() {
|
|
|
|