1. Added vpn state fix

This commit is contained in:
vadym 2020-08-08 01:19:45 -07:00
parent e73b6c8814
commit 394a0a9177

View File

@ -148,17 +148,21 @@ class MainActivity : AppCompatActivity() {
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) {
showToast("network on") showToast("network on")
stopVpn() stopVpn()
Thread.sleep(1000) Thread.sleep(1000)
startVpn() startVpn()
} }
}
override fun onLost(network: Network?) { override fun onLost(network: Network?) {
if(isStarted) {
showToast("network off") showToast("network off")
stopVpn() stopVpn()
Thread.sleep(1000) Thread.sleep(1000)
startVpn() startVpn()
} }
}
}) })
} }
} else { } else {
@ -168,12 +172,20 @@ 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) {
showToast("network on") showToast("network on")
stopVpn() stopVpn()
} else { Thread.sleep(1000)
showToast("network of")
startVpn() startVpn()
} }
} else {
if(isStarted) {
showToast("network off")
stopVpn()
Thread.sleep(1000)
startVpn()
}
}
} }
} }
} }