1. fix for bug #19

This commit is contained in:
vadym 2020-08-26 12:34:14 +03:00
parent 0c5a3b0f82
commit 63dcc3802b
3 changed files with 11 additions and 27 deletions

View File

@ -143,24 +143,16 @@ class MainActivity : AppCompatActivity() {
ipLayout.visibility = View.VISIBLE ipLayout.visibility = View.VISIBLE
findViewById<TextView>(R.id.ip).text = address findViewById<TextView>(R.id.ip).text = address
} }
/*
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
connectivityManager?.let { connectivityManager?.let {
it.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() { it.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) { override fun onAvailable(network: Network) {
if(isStarted) {
stopVpn()
Thread.sleep(1000)
startVpn() startVpn()
} }
}
override fun onLost(network: Network?) { override fun onLost(network: Network?) {
if(isStarted) {
stopVpn() stopVpn()
Thread.sleep(1000)
startVpn()
}
} }
}) })
} }
@ -171,22 +163,14 @@ class MainActivity : AppCompatActivity() {
Log.i(TAG, "Network state has been changed") Log.i(TAG, "Network state has been changed")
if ("android.net.conn.CONNECTIVITY_CHANGE" == intent.action) { if ("android.net.conn.CONNECTIVITY_CHANGE" == intent.action) {
if (status == NetworkUtils.NETWORK_STATUS_NOT_CONNECTED) { if (status == NetworkUtils.NETWORK_STATUS_NOT_CONNECTED) {
if(isStarted) {
stopVpn() stopVpn()
Thread.sleep(1000)
startVpn()
}
} else { } else {
if(isStarted) {
stopVpn()
Thread.sleep(1000)
startVpn() startVpn()
} }
} }
} }
} }
} }
}*/
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
val sourceDir: String = this.applicationInfo.sourceDir val sourceDir: String = this.applicationInfo.sourceDir
val dexFile = DexFile(sourceDir) val dexFile = DexFile(sourceDir)

View File

@ -34,14 +34,13 @@ import java.net.URI
import java.net.URL import java.net.URL
import java.nio.charset.Charset import java.nio.charset.Charset
class PeerListActivity : AppCompatActivity() { class PeerListActivity : AppCompatActivity() {
companion object { companion object {
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json" 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 -> URL(link).openStream().use { input ->
var outStream = ByteArrayOutputStream() var outStream = ByteArrayOutputStream()
outStream.use { output -> outStream.use { output ->

View File

@ -31,7 +31,7 @@ import kotlin.concurrent.thread
class YggdrasilTunService : VpnService() { class YggdrasilTunService : VpnService() {
private lateinit var ygg: Yggdrasil //private lateinit var ygg: Yggdrasil
private lateinit var tunInputStream: InputStream private lateinit var tunInputStream: InputStream
private lateinit var tunOutputStream: OutputStream private lateinit var tunOutputStream: OutputStream
private lateinit var address: String private lateinit var address: String
@ -43,6 +43,7 @@ class YggdrasilTunService : VpnService() {
companion object { companion object {
private const val TAG = "Yggdrasil-service" private const val TAG = "Yggdrasil-service"
private val ygg = Yggdrasil()
} }
private val FOREGROUND_ID = 1338 private val FOREGROUND_ID = 1338
@ -58,7 +59,7 @@ class YggdrasilTunService : VpnService() {
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS)) val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS))
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS)) val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS))
val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false) val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false)
ygg = Yggdrasil()
setupTunInterface(pi, peers, dns, staticIP) setupTunInterface(pi, peers, dns, staticIP)
foregroundNotification(FOREGROUND_ID, "Yggdrasil service started") foregroundNotification(FOREGROUND_ID, "Yggdrasil service started")
} }
@ -235,7 +236,7 @@ class YggdrasilTunService : VpnService() {
tunOutputStream.close() tunOutputStream.close()
tunInterface!!.close() tunInterface!!.close()
Log.d(TAG,"Stop is running from service") Log.d(TAG,"Stop is running from service")
ygg.stop() //ygg.stop()
val intent: Intent = Intent() val intent: Intent = Intent()
pi!!.send(this, MainActivity.STATUS_STOP, intent) pi!!.send(this, MainActivity.STATUS_STOP, intent)
stopForeground(true) stopForeground(true)