clear dns cache on network switch
This commit is contained in:
parent
9a7fc3d9b8
commit
ff756647a9
|
@ -657,6 +657,7 @@ public class XmppConnectionService extends Service {
|
||||||
if (Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) {
|
if (Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) {
|
||||||
resetAllAttemptCounts(true, false);
|
resetAllAttemptCounts(true, false);
|
||||||
}
|
}
|
||||||
|
Resolver.clearCache();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_SHUTDOWN:
|
case Intent.ACTION_SHUTDOWN:
|
||||||
|
|
|
@ -16,10 +16,12 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.measite.minidns.AbstractDNSClient;
|
import de.measite.minidns.AbstractDNSClient;
|
||||||
|
import de.measite.minidns.DNSCache;
|
||||||
import de.measite.minidns.DNSClient;
|
import de.measite.minidns.DNSClient;
|
||||||
import de.measite.minidns.DNSName;
|
import de.measite.minidns.DNSName;
|
||||||
import de.measite.minidns.Question;
|
import de.measite.minidns.Question;
|
||||||
import de.measite.minidns.Record;
|
import de.measite.minidns.Record;
|
||||||
|
import de.measite.minidns.cache.LRUCache;
|
||||||
import de.measite.minidns.dnssec.DNSSECResultNotAuthenticException;
|
import de.measite.minidns.dnssec.DNSSECResultNotAuthenticException;
|
||||||
import de.measite.minidns.dnsserverlookup.AndroidUsingExec;
|
import de.measite.minidns.dnsserverlookup.AndroidUsingExec;
|
||||||
import de.measite.minidns.hla.DnssecResolverApi;
|
import de.measite.minidns.hla.DnssecResolverApi;
|
||||||
|
@ -68,9 +70,7 @@ public class Resolver {
|
||||||
final Field useHardcodedDnsServers = DNSClient.class.getDeclaredField("useHardcodedDnsServers");
|
final Field useHardcodedDnsServers = DNSClient.class.getDeclaredField("useHardcodedDnsServers");
|
||||||
useHardcodedDnsServers.setAccessible(true);
|
useHardcodedDnsServers.setAccessible(true);
|
||||||
useHardcodedDnsServers.setBoolean(dnsClient, false);
|
useHardcodedDnsServers.setBoolean(dnsClient, false);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
Log.e(Config.LOGTAG, "Unable to disable hardcoded DNS servers", e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
Log.e(Config.LOGTAG, "Unable to disable hardcoded DNS servers", e);
|
Log.e(Config.LOGTAG, "Unable to disable hardcoded DNS servers", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,15 @@ public class Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void clearCache() {
|
||||||
|
final AbstractDNSClient client = ResolverApi.INSTANCE.getClient();
|
||||||
|
final DNSCache dnsCache = client.getCache();
|
||||||
|
if (dnsCache instanceof LRUCache) {
|
||||||
|
Log.d(Config.LOGTAG,"clearing DNS cache");
|
||||||
|
((LRUCache) dnsCache).clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean useDirectTls(final int port) {
|
public static boolean useDirectTls(final int port) {
|
||||||
return port == 443 || port == 5223;
|
return port == 443 || port == 5223;
|
||||||
|
@ -105,7 +114,7 @@ public class Resolver {
|
||||||
}
|
}
|
||||||
final List<Result> results = new ArrayList<>();
|
final List<Result> results = new ArrayList<>();
|
||||||
final List<Result> fallbackResults = new ArrayList<>();
|
final List<Result> fallbackResults = new ArrayList<>();
|
||||||
Thread[] threads = new Thread[3];
|
final Thread[] threads = new Thread[3];
|
||||||
threads[0] = new Thread(() -> {
|
threads[0] = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
final List<Result> list = resolveSrv(domain, true);
|
final List<Result> list = resolveSrv(domain, true);
|
||||||
|
@ -132,7 +141,7 @@ public class Resolver {
|
||||||
fallbackResults.addAll(list);
|
fallbackResults.addAll(list);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (Thread thread : threads) {
|
for (final Thread thread : threads) {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue