Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Commit 7294166

Browse files
authored
Merge pull request #25 from vikulin/master
Fixed bug with checkmark clean up while adding new peers in list
2 parents 34d8113 + 8e0d575 commit 7294166

File tree

17 files changed

+362
-67
lines changed

17 files changed

+362
-67
lines changed

.idea/codeStyles/Project.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 29
6+
compileSdkVersion 30
77
defaultConfig {
88
applicationId "io.github.chronosx88.yggdrasil"
99
minSdkVersion 15
10-
targetSdkVersion 29
11-
versionCode 4
12-
versionName "1.4"
10+
targetSdkVersion 30
11+
versionCode 5
12+
versionName "1.5"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14-
project.ext.set("archivesBaseName", project.getParent().name+"-"+versionName)
14+
setProperty("archivesBaseName", project.getParent().name+"-"+versionName)
1515
}
1616
signingConfigs {
1717
release {
@@ -58,8 +58,8 @@ dependencies {
5858
implementation fileTree(dir: 'libs', include: ['*.jar'])
5959
implementation project(path: ':yggdrasil')
6060

61-
implementation 'androidx.appcompat:appcompat:1.1.0'
62-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
61+
implementation 'androidx.appcompat:appcompat:1.2.0'
62+
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
6363
implementation "androidx.preference:preference-ktx:1.1.1"
6464
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6565

@@ -69,6 +69,6 @@ dependencies {
6969
implementation 'com.hbb20:ccp:2.4.0'
7070

7171
testImplementation 'junit:junit:4.12'
72-
androidTestImplementation 'androidx.test:runner:1.2.0'
73-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
72+
androidTestImplementation 'androidx.test:runner:1.3.0'
73+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
7474
}

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
android:roundIcon="@mipmap/ic_launcher_round"
1515
android:supportsRtl="true"
1616
tools:ignore="GoogleAppIndexingWarning">
17+
<activity
18+
android:name=".AboutActivity"
19+
android:parentActivityName=".MainActivity"
20+
android:label="@string/title_activity_about"
21+
android:theme="@style/AppTheme.NoActionBar"
22+
android:screenOrientation="portrait"/>
1723
<activity
1824
android:name=".PeerListActivity"
1925
android:parentActivityName=".MainActivity"

app/src/main/java/io/github/chronosx88/yggdrasil/AboutActivity.kt

Lines changed: 205 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package io.github.chronosx88.yggdrasil
33
import android.app.Activity
44
import android.app.ActivityManager
55
import android.content.*
6-
import android.net.ConnectivityManager
7-
import android.net.Network
86
import android.net.VpnService
97
import android.os.Build
108
import android.os.Bundle
@@ -13,12 +11,12 @@ import android.view.Gravity
1311
import android.view.View
1412
import android.widget.*
1513
import androidx.appcompat.app.AppCompatActivity
14+
import androidx.appcompat.widget.SwitchCompat
1615
import androidx.preference.PreferenceManager
1716
import dalvik.system.DexFile
1817
import io.github.chronosx88.yggdrasil.models.DNSInfo
1918
import io.github.chronosx88.yggdrasil.models.PeerInfo
2019
import io.github.chronosx88.yggdrasil.models.config.DNSInfoListAdapter
21-
import io.github.chronosx88.yggdrasil.models.config.NetworkUtils
2220
import io.github.chronosx88.yggdrasil.models.config.PeerInfoListAdapter
2321
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializePeerStringList2PeerInfoSet
2422
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2DNSInfoSet
@@ -57,12 +55,16 @@ class MainActivity : AppCompatActivity() {
5755
const val CURRENT_PEERS = "CURRENT_PEERS_v1.2.1"
5856
const val CURRENT_DNS = "CURRENT_DNS_v1.2"
5957
const val START_VPN = "START_VPN"
60-
private const val TAG="Yggdrasil"
58+
private const val TAG = "Yggdrasil"
6159
private const val VPN_REQUEST_CODE = 0x0F
6260

63-
@JvmStatic var isStarted = false
64-
@JvmStatic var isCancelled = false
65-
@JvmStatic var address:String? = ""
61+
@JvmStatic
62+
var isStarted = false
63+
@JvmStatic
64+
var isCancelled = false
65+
@JvmStatic
66+
var address: String? = ""
67+
6668
}
6769

6870
private var currentPeers = setOf<PeerInfo>()
@@ -74,7 +76,7 @@ class MainActivity : AppCompatActivity() {
7476
setContentView(R.layout.activity_main)
7577
setSupportActionBar(findViewById(R.id.toolbar))
7678
isStarted = isYggServiceRunning(this)
77-
val switchOn = findViewById<Switch>(R.id.switchOn)
79+
val switchOn = findViewById<SwitchCompat>(R.id.switchOn)
7880
switchOn.isChecked = isStarted
7981

8082
switchOn.setOnCheckedChangeListener { _, isChecked ->
@@ -92,12 +94,17 @@ class MainActivity : AppCompatActivity() {
9294
//save to shared preferences
9395
val preferences =
9496
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
95-
val staticIP = findViewById<Switch>(R.id.staticIP)
97+
val staticIP = findViewById<SwitchCompat>(R.id.staticIP)
9698
staticIP.isChecked =
9799
preferences.getString(STATIC_IP, null) != null
98100
val peersListView = findViewById<ListView>(R.id.peers)
99101

100-
currentPeers = deserializeStringSet2PeerInfoSet(preferences.getStringSet(CURRENT_PEERS, HashSet())!!)
102+
currentPeers = deserializeStringSet2PeerInfoSet(
103+
preferences.getStringSet(
104+
CURRENT_PEERS,
105+
HashSet()
106+
)!!
107+
)
101108
val adapter = PeerInfoListAdapter(this, currentPeers.sortedWith(compareBy { it.ping }))
102109
peersListView.adapter = adapter
103110
if(isStarted && this.currentPeers.isEmpty()) {
@@ -125,7 +132,12 @@ class MainActivity : AppCompatActivity() {
125132
}
126133

127134
val listViewDNS = findViewById<ListView>(R.id.dns)
128-
currentDNS = deserializeStringSet2DNSInfoSet(preferences.getStringSet(CURRENT_DNS, HashSet())!!)
135+
currentDNS = deserializeStringSet2DNSInfoSet(
136+
preferences.getStringSet(
137+
CURRENT_DNS,
138+
HashSet()
139+
)!!
140+
)
129141
val adapterDns = DNSInfoListAdapter(this, currentDNS.sortedWith(compareBy { it.ping }))
130142
listViewDNS.adapter = adapterDns
131143
val editDnsButton = findViewById<Button>(R.id.editDNS)
@@ -193,10 +205,16 @@ class MainActivity : AppCompatActivity() {
193205
val cl = classLoader
194206
val c: Class<*> = dexFile.loadClass("dummy/Dummy", cl)
195207
}
208+
val versionName = findViewById<Button>(R.id.about)
209+
versionName.text = """version:${BuildConfig.VERSION_NAME} build:${BuildConfig.VERSION_CODE}"""
210+
versionName.setOnClickListener {
211+
val intent = Intent(this@MainActivity, AboutActivity::class.java)
212+
startActivity(intent)
213+
}
196214
}
197215

198216
private fun stopVpn(){
199-
Log.i(TAG,"Stop")
217+
Log.i(TAG, "Stop")
200218
val intent = Intent(this, YggdrasilTunService::class.java)
201219
val TASK_CODE = 100
202220
val pi = createPendingResult(TASK_CODE, intent, 0)
@@ -206,7 +224,7 @@ class MainActivity : AppCompatActivity() {
206224
}
207225

208226
private fun startVpn(){
209-
Log.i(TAG,"Start")
227+
Log.i(TAG, "Start")
210228
val intent= VpnService.prepare(this)
211229
if (intent!=null){
212230
startActivityForResult(intent, VPN_REQUEST_CODE)
@@ -216,7 +234,7 @@ class MainActivity : AppCompatActivity() {
216234
}
217235

218236
private fun updateDNS(){
219-
Log.i(TAG,"Update DNS")
237+
Log.i(TAG, "Update DNS")
220238
val intent = Intent(this, YggdrasilTunService::class.java)
221239
val TASK_CODE = 100
222240
val pi = createPendingResult(TASK_CODE, intent, 0)
@@ -227,7 +245,7 @@ class MainActivity : AppCompatActivity() {
227245
}
228246

229247
private fun updatePeers(){
230-
Log.d(TAG,"Update Peers")
248+
Log.d(TAG, "Update Peers")
231249
val intent = Intent(this, YggdrasilTunService::class.java)
232250
val TASK_CODE = 100
233251
val pi = createPendingResult(TASK_CODE, intent, 0)
@@ -258,9 +276,13 @@ class MainActivity : AppCompatActivity() {
258276
val pi = createPendingResult(TASK_CODE, intent, 0)
259277
intent.putExtra(PARAM_PINTENT, pi)
260278
intent.putExtra(COMMAND, START)
261-
intent.putStringArrayListExtra(CURRENT_PEERS, serializePeerInfoSet2StringList(currentPeers))
279+
intent.putStringArrayListExtra(
280+
CURRENT_PEERS, serializePeerInfoSet2StringList(
281+
currentPeers
282+
)
283+
)
262284
intent.putStringArrayListExtra(CURRENT_DNS, serializeDNSInfoSet2StringList(currentDNS))
263-
intent.putExtra(STATIC_IP, findViewById<Switch>(R.id.staticIP).isChecked)
285+
intent.putExtra(STATIC_IP, findViewById<SwitchCompat>(R.id.staticIP).isChecked)
264286

265287
startService(intent)
266288
}
@@ -272,7 +294,10 @@ class MainActivity : AppCompatActivity() {
272294
var currentPeers = data.extras!!.getStringArrayList(PEER_LIST)
273295
/*WiFi Direct test. need peer empty list*/
274296
this.currentPeers = deserializeStringList2PeerInfoSet(currentPeers)
275-
val adapter = PeerInfoListAdapter(this, this.currentPeers.sortedWith(compareBy { it.ping }))
297+
val adapter = PeerInfoListAdapter(
298+
this,
299+
this.currentPeers.sortedWith(compareBy { it.ping })
300+
)
276301
val listView = findViewById<ListView>(R.id.peers)
277302
listView.adapter = adapter
278303

@@ -297,7 +322,10 @@ class MainActivity : AppCompatActivity() {
297322
if(data!!.extras!=null){
298323
var currentDNS = data.extras!!.getStringArrayList(DNS_LIST)
299324
this.currentDNS = deserializeStringList2DNSInfoSet(currentDNS)
300-
val adapter = DNSInfoListAdapter(this, this.currentDNS.sortedWith(compareBy { it.ping }))
325+
val adapter = DNSInfoListAdapter(
326+
this,
327+
this.currentDNS.sortedWith(compareBy { it.ping })
328+
)
301329
val listView = findViewById<ListView>(R.id.dns)
302330
listView.adapter = adapter
303331
//save to shared preferences
@@ -313,7 +341,7 @@ class MainActivity : AppCompatActivity() {
313341
when (resultCode) {
314342
STATUS_START -> {
315343
print("service started")
316-
if(this.currentPeers.isEmpty()){
344+
if (this.currentPeers.isEmpty()) {
317345
checkPeers()
318346
}
319347
}
@@ -329,16 +357,17 @@ class MainActivity : AppCompatActivity() {
329357
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
330358
ipLayout.visibility = View.GONE
331359
}
332-
STATUS_PEERS_UPDATE ->{
333-
if(data!!.extras!=null) {
360+
STATUS_PEERS_UPDATE -> {
361+
if (data!!.extras != null) {
334362
thread(start = true) {
335363
val meshPeers = deserializePeerStringList2PeerInfoSet(
336364
data.extras!!.getStringArrayList(MESH_PEERS)
337365
)
338366
val listView = findViewById<ListView>(R.id.peers)
339367
val adapter = PeerInfoListAdapter(
340368
this@MainActivity,
341-
meshPeers.filter { it.schema!="self" }.sortedWith(compareBy { it.ping })
369+
meshPeers.filter { it.schema != "self" }
370+
.sortedWith(compareBy { it.ping })
342371
)
343372
runOnUiThread {
344373
listView.adapter = adapter

app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,6 @@ class PeerListActivity : AppCompatActivity() {
241241
val result = Intent(this, MainActivity::class.java)
242242
var adapter = findViewById<ListView>(R.id.peerList).adapter as SelectPeerInfoListAdapter
243243
val selectedPeers = adapter.getSelectedPeers()
244-
/* WiFi Direct test - no peers is needed
245-
if(selectedPeers.size>0) {
246-
result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers))
247-
setResult(Activity.RESULT_OK, result)
248-
finish()
249-
} else {
250-
val text = "Select at least one peer"
251-
val duration = Toast.LENGTH_SHORT
252-
val toast = Toast.makeText(applicationContext, text, duration)
253-
toast.setGravity(Gravity.CENTER, 0, 0)
254-
toast.show()
255-
}*/
256244
result.putExtra(MainActivity.PEER_LIST, serializePeerInfoSet2StringList(selectedPeers))
257245
setResult(Activity.RESULT_OK, result)
258246
finish()

app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import mobile.Mobile
2727
import mobile.Yggdrasil
2828
import java.io.*
2929
import java.net.Inet6Address
30+
import kotlin.concurrent.thread
3031

3132
class YggdrasilTunService : VpnService() {
3233

@@ -44,8 +45,6 @@ class YggdrasilTunService : VpnService() {
4445
private const val TAG = "Yggdrasil-service"
4546
}
4647

47-
private var scope: CoroutineScope? = null
48-
4948
private val FOREGROUND_ID = 1338
5049

5150
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@@ -124,15 +123,13 @@ class YggdrasilTunService : VpnService() {
124123

125124
setupIOStreams(dns)
126125

127-
val job = SupervisorJob()
128-
scope = CoroutineScope(Dispatchers.Default + job)
129-
scope!!.launch {
126+
thread(start = true) {
130127
val buffer = ByteArray(MAX_PACKET_SIZE)
131128
while (!isClosed) {
132129
readPacketsFromTun(yggConduitEndpoint, buffer)
133130
}
134131
}
135-
scope!!.launch {
132+
thread(start = true) {
136133
while (!isClosed) {
137134
writePacketsToTun(yggConduitEndpoint)
138135
}
@@ -234,7 +231,6 @@ class YggdrasilTunService : VpnService() {
234231

235232
private fun stopVpn(pi: PendingIntent?) {
236233
isClosed = true;
237-
scope!!.coroutineContext.cancelChildren()
238234
tunInputStream.close()
239235
tunOutputStream.close()
240236
tunInterface!!.close()

app/src/main/java/io/github/chronosx88/yggdrasil/models/config/SelectPeerInfoListAdapter.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ class SelectPeerInfoListAdapter(
5757
peerInfoHolder.peerInfoText.setTextColor(Color.WHITE)
5858
}
5959
peerInfoHolder.checkbox.setOnCheckedChangeListener { _, isChecked ->
60-
if(!isLoading) {
61-
if (isChecked) {
62-
if (!currentPeers.contains(currentPeer)) {
63-
currentPeers.add(currentPeer)
64-
}
65-
} else {
66-
if (currentPeers.contains(currentPeer)) {
67-
currentPeers.remove(currentPeer)
68-
}
60+
if (isChecked) {
61+
if (!currentPeers.contains(currentPeer)) {
62+
currentPeers.add(currentPeer)
63+
}
64+
} else {
65+
if (currentPeers.contains(currentPeer)) {
66+
currentPeers.remove(currentPeer)
6967
}
7068
}
7169
}

0 commit comments

Comments
 (0)