You've already forked android-client
mirror of
https://github.com/netbirdio/android-client.git
synced 2026-05-22 17:10:49 -07:00
Add check on current looper when adding dns to VPNService.builder
This commit is contained in:
@@ -104,25 +104,33 @@ class IFace implements TunAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
// ConnectivityManager must to run on the main thread instead of a Go routine
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
DNSWatch dnsWatch = new DNSWatch(vpnService);
|
||||
// ConnectivityManager must to run on the main thread instead of a Go routine
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
addDnsServer(builder, dns);
|
||||
|
||||
if (!dnsWatch.isPrivateDnsActive()) {
|
||||
builder.addDnsServer(dns);
|
||||
} else {
|
||||
Log.d(LOGTAG, "ignore DNS because private dns is active");
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
try {
|
||||
latch.await(); // Will block the current thread until countDown() is called
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} else {
|
||||
addDnsServer(builder, dns);
|
||||
}
|
||||
}
|
||||
|
||||
latch.countDown();
|
||||
});
|
||||
private void addDnsServer(VpnService.Builder builder, String dns) {
|
||||
DNSWatch dnsWatch = new DNSWatch(vpnService);
|
||||
|
||||
try {
|
||||
latch.await(); // Will block the current thread until countDown() is called
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
if (!dnsWatch.isPrivateDnsActive()) {
|
||||
builder.addDnsServer(dns);
|
||||
} else {
|
||||
Log.d(LOGTAG, "ignore DNS because private dns is active");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user