mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
3. DNS dynamic list selection fixes
This commit is contained in:
parent
0201705c45
commit
d403c0c15d
@ -52,11 +52,12 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
var dnsList = findViewById<ListView>(R.id.dnsList)
|
var dnsList = findViewById<ListView>(R.id.dnsList)
|
||||||
var adapter = SelectDNSInfoListAdapter(this, arrayListOf(), mutableSetOf())
|
var adapter = SelectDNSInfoListAdapter(this, arrayListOf(), mutableSetOf())
|
||||||
dnsList.adapter = adapter
|
dnsList.adapter = adapter
|
||||||
thread(start = true) {
|
|
||||||
try {
|
|
||||||
var cd = deserializeStringList2DNSInfoSet(
|
var cd = deserializeStringList2DNSInfoSet(
|
||||||
extras!!.getStringArrayList(MainActivity.DNS_LIST)!!
|
extras!!.getStringArrayList(MainActivity.DNS_LIST)!!
|
||||||
)
|
)
|
||||||
|
thread(start = true) {
|
||||||
|
try {
|
||||||
|
|
||||||
for (d in cd) {
|
for (d in cd) {
|
||||||
var ping = ping(d.address, 53)
|
var ping = ping(d.address, 53)
|
||||||
d.ping = ping
|
d.ping = ping
|
||||||
@ -72,14 +73,22 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
{
|
{
|
||||||
adapter.addItem(dns)
|
adapter.addItem(dns)
|
||||||
adapter.sort()
|
adapter.sort()
|
||||||
isLoading = false
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
runOnUiThread(
|
||||||
|
Runnable
|
||||||
|
{
|
||||||
|
var currentDNS = ArrayList(cd.sortedWith(compareBy { it.ping }))
|
||||||
|
adapter.addAll(0, currentDNS)
|
||||||
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewDNS() {
|
private fun addNewDNS() {
|
||||||
@ -133,18 +142,9 @@ class DNSListActivity : AppCompatActivity() {
|
|||||||
val result = Intent(this, MainActivity::class.java)
|
val result = Intent(this, MainActivity::class.java)
|
||||||
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
|
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
|
||||||
val selectedDNS = adapter.getSelectedDNS()
|
val selectedDNS = adapter.getSelectedDNS()
|
||||||
if(selectedDNS.isNotEmpty()) {
|
|
||||||
result.putExtra(MainActivity.DNS_LIST, serializeDNSInfoSet2StringList(selectedDNS))
|
result.putExtra(MainActivity.DNS_LIST, serializeDNSInfoSet2StringList(selectedDNS))
|
||||||
setResult(Activity.RESULT_OK, result)
|
setResult(Activity.RESULT_OK, result)
|
||||||
finish()
|
finish() }
|
||||||
} else {
|
|
||||||
val text = "Select at least one DNS"
|
|
||||||
val duration = Toast.LENGTH_SHORT
|
|
||||||
val toast = Toast.makeText(applicationContext, text, duration)
|
|
||||||
toast.setGravity(Gravity.CENTER, 0, 0)
|
|
||||||
toast.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,8 +50,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
const val STATUS_FINISH = 8
|
const val STATUS_FINISH = 8
|
||||||
const val STATUS_STOP = 9
|
const val STATUS_STOP = 9
|
||||||
const val IPv6: String = "IPv6"
|
const val IPv6: String = "IPv6"
|
||||||
const val PEERS: String = "PEERS"
|
|
||||||
const val DNS: String = "DNS"
|
|
||||||
const val PEER_LIST_CODE = 1000
|
const val PEER_LIST_CODE = 1000
|
||||||
const val DNS_LIST_CODE = 2000
|
const val DNS_LIST_CODE = 2000
|
||||||
const val PEER_LIST = "PEERS_LIST"
|
const val PEER_LIST = "PEERS_LIST"
|
||||||
@ -173,7 +171,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val pi = createPendingResult(TASK_CODE, intent, 0)
|
val pi = createPendingResult(TASK_CODE, intent, 0)
|
||||||
intent.putExtra(PARAM_PINTENT, pi)
|
intent.putExtra(PARAM_PINTENT, pi)
|
||||||
intent.putExtra(COMMAND, UPDATE_DNS)
|
intent.putExtra(COMMAND, UPDATE_DNS)
|
||||||
intent.putStringArrayListExtra(DNS, serializeDNSInfoSet2StringList(currentDNS))
|
intent.putStringArrayListExtra(CURRENT_DNS, serializeDNSInfoSet2StringList(currentDNS))
|
||||||
startService(intent)
|
startService(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,8 +195,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val pi = createPendingResult(TASK_CODE, intent, 0)
|
val pi = createPendingResult(TASK_CODE, intent, 0)
|
||||||
intent.putExtra(PARAM_PINTENT, pi)
|
intent.putExtra(PARAM_PINTENT, pi)
|
||||||
intent.putExtra(COMMAND, START)
|
intent.putExtra(COMMAND, START)
|
||||||
intent.putStringArrayListExtra(PEERS, serializePeerInfoSet2StringList(currentPeers))
|
intent.putStringArrayListExtra(CURRENT_PEERS, serializePeerInfoSet2StringList(currentPeers))
|
||||||
intent.putStringArrayListExtra(DNS, serializeDNSInfoSet2StringList(currentDNS))
|
intent.putStringArrayListExtra(CURRENT_DNS, serializeDNSInfoSet2StringList(currentDNS))
|
||||||
intent.putExtra(STATIC_IP, findViewById<Switch>(R.id.staticIP).isChecked)
|
intent.putExtra(STATIC_IP, findViewById<Switch>(R.id.staticIP).isChecked)
|
||||||
|
|
||||||
startService(intent)
|
startService(intent)
|
||||||
@ -235,9 +233,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (requestCode == DNS_LIST_CODE && resultCode== Activity.RESULT_OK){
|
if (requestCode == DNS_LIST_CODE && resultCode== Activity.RESULT_OK){
|
||||||
if(data!!.extras!=null){
|
if(data!!.extras!=null){
|
||||||
var currentDNS = data.extras!!.getStringArrayList(DNS_LIST)
|
var currentDNS = data.extras!!.getStringArrayList(DNS_LIST)
|
||||||
if(currentDNS==null || currentDNS.size==0){
|
|
||||||
showToast("No DNS selected!")
|
|
||||||
} else {
|
|
||||||
this.currentDNS = deserializeStringList2DNSInfoSet(currentDNS)
|
this.currentDNS = deserializeStringList2DNSInfoSet(currentDNS)
|
||||||
val adapter = DNSInfoListAdapter(this, this.currentDNS.sortedWith(compareBy { it.ping }))
|
val adapter = DNSInfoListAdapter(this, this.currentDNS.sortedWith(compareBy { it.ping }))
|
||||||
val listView = findViewById<ListView>(R.id.dns)
|
val listView = findViewById<ListView>(R.id.dns)
|
||||||
@ -251,7 +246,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
when (resultCode) {
|
when (resultCode) {
|
||||||
STATUS_START -> {
|
STATUS_START -> {
|
||||||
|
@ -181,7 +181,7 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onClickSchemaList(v: View) {
|
private fun onClickSchemaList(v: View) {
|
||||||
val height = -1 * v.height +30
|
val height = -1 * v.height +30
|
||||||
getAddressListPopup()?.showAsDropDown(v, -5, height)
|
getAddressListPopup()?.showAsDropDown(v, -5, height)
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ class YggdrasilTunService : VpnService() {
|
|||||||
private lateinit var ygg: Yggdrasil
|
private lateinit var ygg: Yggdrasil
|
||||||
private var isClosed = false
|
private var isClosed = false
|
||||||
|
|
||||||
/** Maximum packet size is constrained by the MTU, which is given as a signed short - 256 */
|
/** Maximum packet size is constrained by the MTU, which is given as a signed short/2 */
|
||||||
private val MAX_PACKET_SIZE = 65535
|
private val MAX_PACKET_SIZE = Short.MAX_VALUE/2
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "Yggdrasil-service"
|
private const val TAG = "Yggdrasil-service"
|
||||||
@ -65,15 +65,15 @@ class YggdrasilTunService : VpnService() {
|
|||||||
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service stopped"))
|
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service stopped"))
|
||||||
}
|
}
|
||||||
MainActivity.START ->{
|
MainActivity.START ->{
|
||||||
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.PEERS))
|
val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS))
|
||||||
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.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()
|
ygg = Yggdrasil()
|
||||||
setupTunInterface(pi, peers, dns, staticIP)
|
setupTunInterface(pi, peers, dns, staticIP)
|
||||||
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service started"))
|
startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service started"))
|
||||||
}
|
}
|
||||||
MainActivity.UPDATE_DNS ->{
|
MainActivity.UPDATE_DNS ->{
|
||||||
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.DNS))
|
val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS))
|
||||||
setupIOStreams(dns)
|
setupIOStreams(dns)
|
||||||
}
|
}
|
||||||
MainActivity.UPDATE_PEERS ->{
|
MainActivity.UPDATE_PEERS ->{
|
||||||
@ -90,6 +90,7 @@ class YggdrasilTunService : VpnService() {
|
|||||||
var builder = Builder()
|
var builder = Builder()
|
||||||
.addAddress(address, 7)
|
.addAddress(address, 7)
|
||||||
.allowFamily(OsConstants.AF_INET)
|
.allowFamily(OsConstants.AF_INET)
|
||||||
|
.allowBypass()
|
||||||
.setMtu(MAX_PACKET_SIZE)
|
.setMtu(MAX_PACKET_SIZE)
|
||||||
if (dns.size > 0) {
|
if (dns.size > 0) {
|
||||||
builder.addDnsServer(address)
|
builder.addDnsServer(address)
|
||||||
|
@ -82,6 +82,13 @@ class SelectDNSInfoListAdapter(
|
|||||||
allDNS.add(index, peerInfo)
|
allDNS.add(index, peerInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addAll(index: Int, dnsInfo: ArrayList<DNSInfo>){
|
||||||
|
currentDNS.addAll(dnsInfo)
|
||||||
|
allDNS.removeAll(dnsInfo)
|
||||||
|
allDNS.addAll(index, dnsInfo)
|
||||||
|
this.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
fun sort(){
|
fun sort(){
|
||||||
allDNS = ArrayList(allDNS.sortedWith(compareBy { it.ping }))
|
allDNS = ArrayList(allDNS.sortedWith(compareBy { it.ping }))
|
||||||
this.notifyDataSetChanged()
|
this.notifyDataSetChanged()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user