diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index 1dd30be..57b6c11 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -140,7 +140,7 @@ public static T parseJson(Class beanClass, JsonReader reader) throws Json return gson.fromJson(reader, beanClass); } - public static void initHostsResolver() { + public static void initRuleResolver() { if (Daedalus.getPrefs().getBoolean("settings_local_rules_resolution", false)) { ArrayList pendingLoad = new ArrayList<>(); ArrayList usingRules = configurations.getUsingRules(); @@ -161,6 +161,8 @@ public static void initHostsResolver() { RuleResolver.startLoadDnsmasq(arr); break; } + } else { + RuleResolver.clear(); } } else { RuleResolver.clear(); @@ -171,7 +173,7 @@ public static void initHostsResolver() { public static void setRulesChanged() { if (DaedalusVpnService.isActivated() && getPrefs().getBoolean("settings_allow_dynamic_rule_reload", false)) { - initHostsResolver(); + initRuleResolver(); } } diff --git a/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java b/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java index 766d527..ffd68a1 100644 --- a/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java +++ b/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java @@ -111,7 +111,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { this.notification = builder; } - Daedalus.initHostsResolver(); + Daedalus.initRuleResolver(); DNSServerHelper.buildPortCache(); if (this.mThread == null) { diff --git a/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java b/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java index 78057b2..484ca27 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java +++ b/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java @@ -33,8 +33,8 @@ public class RuleResolver implements Runnable { private static int mode = MODE_HOSTS; private static String[] hostsFiles; private static String[] dnsmasqFiles; - private static HashMap rulesA; - private static HashMap rulesAAAA; + private static HashMap rulesA = new HashMap<>(); + private static HashMap rulesAAAA = new HashMap<>(); private static boolean shutdown = false; public RuleResolver() { @@ -61,18 +61,20 @@ public static void startLoadDnsmasq(String[] loadPath) { } public static void clear() { - rulesA = null; - rulesAAAA = null; + rulesA = new HashMap<>(); + rulesAAAA = new HashMap<>(); } public static String resolve(String hostname, Record.TYPE type) { - HashMap rules = null; + HashMap rules; if (type == Record.TYPE.A) { rules = rulesA; } else if (type == Record.TYPE.AAAA) { rules = rulesAAAA; + } else { + return null; } - if (rules == null) { + if (rules.size() == 0) { return null; } if (rules.containsKey(hostname)) {