mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 07:56:30 +00:00
1. added static IP option
This commit is contained in:
parent
729b44c127
commit
c5b5a0fa24
@ -2,9 +2,11 @@ package io.github.chronosx88.yggdrasil
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.content.*
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.VpnService
|
||||
import android.net.wifi.p2p.WifiP2pDevice
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
@ -85,18 +87,24 @@ class MainActivity : AppCompatActivity() {
|
||||
stopVpn()
|
||||
}
|
||||
}
|
||||
|
||||
val wifiDirect = findViewById<Switch>(R.id.staticIP)
|
||||
wifiDirect.setOnCheckedChangeListener { _, isChecked ->
|
||||
//save to shared preferences
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
val staticIP = findViewById<Switch>(R.id.staticIP)
|
||||
staticIP.isChecked =
|
||||
preferences.getString(STATIC_IP, null) != null
|
||||
staticIP.setOnCheckedChangeListener { _, isChecked ->
|
||||
if(isChecked){
|
||||
|
||||
preferences.edit()
|
||||
.putString(STATIC_IP,STATIC_IP).apply()
|
||||
} else {
|
||||
preferences.edit()
|
||||
.putString(STATIC_IP,null).apply()
|
||||
}
|
||||
}
|
||||
|
||||
val peersListView = findViewById<ListView>(R.id.peers)
|
||||
//save to shared preferences
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
|
||||
currentPeers = deserializeStringSet2PeerInfoSet(preferences.getStringSet(CURRENT_PEERS, HashSet())!!)
|
||||
val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping }))
|
||||
peersListView.adapter = adapter
|
||||
@ -141,6 +149,7 @@ class MainActivity : AppCompatActivity() {
|
||||
ipLayout.visibility = View.VISIBLE
|
||||
findViewById<TextView>(R.id.ip).text = address
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun stopVpn(){
|
||||
@ -287,4 +296,12 @@ class MainActivity : AppCompatActivity() {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
findViewById<Switch>(R.id.staticIP).isChecked =
|
||||
preferences.getString(STATIC_IP, null) != null
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class YggdrasilTunService : VpnService() {
|
||||
if(staticIP) {
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
if(preferences.getString(MainActivity.signingPrivateKey, null)==null) {
|
||||
if(preferences.getString(MainActivity.STATIC_IP, null)==null) {
|
||||
val encryptionPublicKey = config["EncryptionPublicKey"].toString()
|
||||
val encryptionPrivateKey = config["EncryptionPrivateKey"].toString()
|
||||
val signingPublicKey = config["SigningPublicKey"].toString()
|
||||
@ -155,19 +155,21 @@ class YggdrasilTunService : VpnService() {
|
||||
.putString(MainActivity.signingPrivateKey, signingPrivateKey)
|
||||
.putString(MainActivity.signingPublicKey, signingPublicKey)
|
||||
.putString(MainActivity.encryptionPrivateKey, encryptionPrivateKey)
|
||||
.putString(MainActivity.encryptionPublicKey, encryptionPublicKey).apply()
|
||||
.putString(MainActivity.encryptionPublicKey, encryptionPublicKey)
|
||||
.putString(MainActivity.STATIC_IP,MainActivity.STATIC_IP).apply()
|
||||
} else {
|
||||
config["signingPrivateKey"] = preferences.getString(MainActivity.signingPrivateKey, null)
|
||||
config["signingPublicKey"] = preferences.getString(MainActivity.signingPublicKey, null)
|
||||
config["encryptionPrivateKey"] = preferences.getString(MainActivity.encryptionPrivateKey, null)
|
||||
config["encryptionPublicKey"] = preferences.getString(MainActivity.encryptionPublicKey, null)
|
||||
val signingPrivateKey = preferences.getString(MainActivity.signingPrivateKey, null)
|
||||
val signingPublicKey = preferences.getString(MainActivity.signingPublicKey, null)
|
||||
val encryptionPrivateKey = preferences.getString(MainActivity.encryptionPrivateKey, null)
|
||||
val encryptionPublicKey = preferences.getString(MainActivity.encryptionPublicKey, null)
|
||||
|
||||
config["SigningPrivateKey"] = signingPrivateKey
|
||||
config["SigningPublicKey"] = signingPublicKey
|
||||
config["EncryptionPrivateKey"] = encryptionPrivateKey
|
||||
config["EncryptionPublicKey"] = encryptionPublicKey
|
||||
}
|
||||
}
|
||||
|
||||
//config["EncryptionPublicKey"] = "b15633cf66e63a04f03e9d1a5b2ac6411af819cde9e74175cf574d5599b1296c"
|
||||
//config["EncryptionPrivateKey"] = "a39e2da3ccbb5afc3854574a2e3823e881d2d720754d6fdc877f57b252d3b521"
|
||||
//config["SigningPublicKey"] = "4f248483c094aea370fba86f1630ba5099cb230aa1337ab6ef6ff0b132be2c2b"
|
||||
//config["SigningPrivateKey"] = "e4d56eb2e15e25d9098731e39d661a80c523f31d38b71cbd0ad25a5cde745eac4f248483c094aea370fba86f1630ba5099cb230aa1337ab6ef6ff0b132be2c2b"
|
||||
(config["SessionFirewall"] as MutableMap<Any, Any>)["Enable"] = false
|
||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromDirect"] = true
|
||||
//(config["SessionFirewall"] as MutableMap<Any, Any>)["AllowFromRemote"] = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user