diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index 6209ae0..9507f18 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -143,24 +143,16 @@ class MainActivity : AppCompatActivity() { ipLayout.visibility = View.VISIBLE findViewById(R.id.ip).text = address } - /* + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager connectivityManager?.let { it.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + startVpn() } override fun onLost(network: Network?) { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + stopVpn() } }) } @@ -171,22 +163,14 @@ class MainActivity : AppCompatActivity() { Log.i(TAG, "Network state has been changed") if ("android.net.conn.CONNECTIVITY_CHANGE" == intent.action) { if (status == NetworkUtils.NETWORK_STATUS_NOT_CONNECTED) { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + stopVpn() } else { - if(isStarted) { - stopVpn() - Thread.sleep(1000) - startVpn() - } + startVpn() } } } } - }*/ + } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { val sourceDir: String = this.applicationInfo.sourceDir val dexFile = DexFile(sourceDir) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt index 37f3fac..e516138 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt @@ -34,14 +34,13 @@ import java.net.URI import java.net.URL import java.nio.charset.Charset - class PeerListActivity : AppCompatActivity() { companion object { const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json" } - fun downloadJson(link: String): String { + private fun downloadJson(link: String): String { URL(link).openStream().use { input -> var outStream = ByteArrayOutputStream() outStream.use { output -> 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 52a0892..3d1a797 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -31,7 +31,7 @@ import kotlin.concurrent.thread class YggdrasilTunService : VpnService() { - private lateinit var ygg: Yggdrasil + //private lateinit var ygg: Yggdrasil private lateinit var tunInputStream: InputStream private lateinit var tunOutputStream: OutputStream private lateinit var address: String @@ -43,6 +43,7 @@ class YggdrasilTunService : VpnService() { companion object { private const val TAG = "Yggdrasil-service" + private val ygg = Yggdrasil() } private val FOREGROUND_ID = 1338 @@ -58,7 +59,7 @@ class YggdrasilTunService : VpnService() { val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS)) val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS)) val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false) - ygg = Yggdrasil() + setupTunInterface(pi, peers, dns, staticIP) foregroundNotification(FOREGROUND_ID, "Yggdrasil service started") } @@ -235,7 +236,7 @@ class YggdrasilTunService : VpnService() { tunOutputStream.close() tunInterface!!.close() Log.d(TAG,"Stop is running from service") - ygg.stop() + //ygg.stop() val intent: Intent = Intent() pi!!.send(this, MainActivity.STATUS_STOP, intent) stopForeground(true)