From 85e27ff7e1a8ecd916c973b786ec2db9de4a28b5 Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 6 Jul 2020 12:36:07 -0700 Subject: [PATCH] 3. fixed high CPU load after switch-off. prevent NPE. --- .../chronosx88/yggdrasil/YggdrasilTunService.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index 7ae8edb..96e95ad 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -88,12 +88,11 @@ class YggdrasilTunService : VpnService() { address = ygg.addressString var builder = Builder() - .addAddress(address, 7) + .addAddress(address!!, 7) .allowFamily(OsConstants.AF_INET) .allowBypass() .setMtu(MAX_PACKET_SIZE) if (dns.size > 0) { - builder.addDnsServer(address) for (d in dns) { builder.addDnsServer(d.address) } @@ -272,10 +271,12 @@ class YggdrasilTunService : VpnService() { val networks = cm.allNetworks for (network in networks) { val linkProperties = cm.getLinkProperties(network) - val routes = linkProperties.routes - for (route in routes) { - if (route.isDefaultRoute && route.gateway is Inet6Address) { - return true + if(linkProperties!=null) { + val routes = linkProperties.routes + for (route in routes) { + if (route.isDefaultRoute && route.gateway is Inet6Address) { + return true + } } } }