mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 07:56:30 +00:00
1. IP address state fix, code refactoring
This commit is contained in:
parent
63f777d2c4
commit
5bb9ddc2de
@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
@JvmStatic var isStarted = false
|
@JvmStatic var isStarted = false
|
||||||
@JvmStatic var isCancelled = false
|
@JvmStatic var isCancelled = false
|
||||||
|
@JvmStatic var address = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentPeers = setOf<PeerInfo>()
|
private var currentPeers = setOf<PeerInfo>()
|
||||||
@ -133,6 +133,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
intent.putStringArrayListExtra(DNS_LIST, serializeDNSInfoSet2StringList(currentDNS))
|
intent.putStringArrayListExtra(DNS_LIST, serializeDNSInfoSet2StringList(currentDNS))
|
||||||
startActivityForResult(intent, DNS_LIST_CODE)
|
startActivityForResult(intent, DNS_LIST_CODE)
|
||||||
}
|
}
|
||||||
|
if(isStarted){
|
||||||
|
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
||||||
|
ipLayout.visibility = View.VISIBLE
|
||||||
|
findViewById<TextView>(R.id.ip).text = address
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopVpn(){
|
private fun stopVpn(){
|
||||||
@ -242,8 +247,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
isStarted = true
|
isStarted = true
|
||||||
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
||||||
ipLayout.visibility = View.VISIBLE
|
ipLayout.visibility = View.VISIBLE
|
||||||
val result: String = data!!.getStringExtra(IPv6)
|
address = data!!.getStringExtra(IPv6)
|
||||||
findViewById<TextView>(R.id.ip).text = result
|
findViewById<TextView>(R.id.ip).text = address
|
||||||
}
|
}
|
||||||
STATUS_STOP -> {
|
STATUS_STOP -> {
|
||||||
isStarted = false
|
isStarted = false
|
||||||
|
@ -39,21 +39,22 @@ class YggdrasilTunService : VpnService() {
|
|||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
|
||||||
if (intent?.getStringExtra(MainActivity.COMMAND) == MainActivity.STOP) {
|
when(intent?.getStringExtra(MainActivity.COMMAND)){
|
||||||
val pi: PendingIntent = intent.getParcelableExtra(MainActivity.PARAM_PINTENT)
|
MainActivity.STOP ->{
|
||||||
stopVpn(pi)
|
val pi: PendingIntent? = intent.getParcelableExtra(MainActivity.PARAM_PINTENT)
|
||||||
}
|
stopVpn(pi)
|
||||||
if (intent?.getStringExtra(MainActivity.COMMAND) == MainActivity.START) {
|
}
|
||||||
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.PEERS))
|
MainActivity.START ->{
|
||||||
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.DNS))
|
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.PEERS))
|
||||||
val pi: PendingIntent = intent.getParcelableExtra(MainActivity.PARAM_PINTENT)
|
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.DNS))
|
||||||
ygg = Yggdrasil()
|
val pi: PendingIntent = intent.getParcelableExtra(MainActivity.PARAM_PINTENT)
|
||||||
setupTunInterface(pi, peers, dns)
|
ygg = Yggdrasil()
|
||||||
}
|
setupTunInterface(pi, peers, dns)
|
||||||
if (intent?.getStringExtra(MainActivity.COMMAND) == MainActivity.UPDATE_DNS) {
|
}
|
||||||
val pi: PendingIntent = intent.getParcelableExtra(MainActivity.PARAM_PINTENT)
|
MainActivity.UPDATE_DNS ->{
|
||||||
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.DNS))
|
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.DNS))
|
||||||
setupIOStreams(dns)
|
setupIOStreams(dns)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onStartCommand(intent, flags, startId)
|
return super.onStartCommand(intent, flags, startId)
|
||||||
@ -82,11 +83,11 @@ class YggdrasilTunService : VpnService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTunInterface(
|
private fun setupTunInterface(
|
||||||
pi: PendingIntent,
|
pi: PendingIntent?,
|
||||||
peers: Set<PeerInfo>,
|
peers: Set<PeerInfo>,
|
||||||
dns: MutableSet<DNSInfo>
|
dns: MutableSet<DNSInfo>
|
||||||
) {
|
) {
|
||||||
pi.send(MainActivity.STATUS_START)
|
pi!!.send(MainActivity.STATUS_START)
|
||||||
var configJson = Mobile.generateConfigJSON()
|
var configJson = Mobile.generateConfigJSON()
|
||||||
val gson = Gson()
|
val gson = Gson()
|
||||||
var config = gson.fromJson(String(configJson), Map::class.java).toMutableMap()
|
var config = gson.fromJson(String(configJson), Map::class.java).toMutableMap()
|
||||||
@ -173,7 +174,7 @@ class YggdrasilTunService : VpnService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopVpn(pi: PendingIntent) {
|
private fun stopVpn(pi: PendingIntent?) {
|
||||||
isClosed = true;
|
isClosed = true;
|
||||||
scope!!.coroutineContext.cancelChildren()
|
scope!!.coroutineContext.cancelChildren()
|
||||||
tunInputStream!!.close()
|
tunInputStream!!.close()
|
||||||
@ -183,7 +184,7 @@ class YggdrasilTunService : VpnService() {
|
|||||||
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)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,21 +12,25 @@ class Utils {
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun deserializeStringList2PeerInfoSet(list: List<String>): MutableSet<PeerInfo> {
|
fun deserializeStringList2PeerInfoSet(list: List<String>?): MutableSet<PeerInfo> {
|
||||||
var gson = Gson()
|
var gson = Gson()
|
||||||
var out = mutableSetOf<PeerInfo>()
|
var out = mutableSetOf<PeerInfo>()
|
||||||
for(s in list) {
|
if (list != null) {
|
||||||
out.add(gson.fromJson(s, PeerInfo::class.java))
|
for(s in list) {
|
||||||
|
out.add(gson.fromJson(s, PeerInfo::class.java))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun deserializeStringList2DNSInfoSet(list: List<String>): MutableSet<DNSInfo> {
|
fun deserializeStringList2DNSInfoSet(list: List<String>?): MutableSet<DNSInfo> {
|
||||||
var gson = Gson()
|
var gson = Gson()
|
||||||
var out = mutableSetOf<DNSInfo>()
|
var out = mutableSetOf<DNSInfo>()
|
||||||
for(s in list) {
|
if (list != null) {
|
||||||
out.add(gson.fromJson(s, DNSInfo::class.java))
|
for(s in list) {
|
||||||
|
out.add(gson.fromJson(s, DNSInfo::class.java))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user