From 3c9683c859cdae5abc7405b23c1baec9d5014394 Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 3 Aug 2020 06:06:06 -0700 Subject: [PATCH 01/32] 1. Added API 15 support (Android 4.0.3) --- app/build.gradle | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index af555d2..53211cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,10 +6,10 @@ android { compileSdkVersion 29 defaultConfig { applicationId "io.github.chronosx88.yggdrasil" - minSdkVersion 21 + minSdkVersion 15 targetSdkVersion 29 - versionCode 3 - versionName "1.3" + versionCode 4 + versionName "1.4" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" project.ext.set("archivesBaseName", project.getParent().name+"-"+versionName) } @@ -38,17 +38,6 @@ android { } } -task ndkBuild(type: Exec) { - def rootDir = project.rootDir - workingDir = new File(rootDir,"yggdrasil") - commandLine 'make' -} - -gradle.projectsEvaluated { - tasks.compileDebugKotlin.dependsOn(ndkBuild) -} - - dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(path: ':yggdrasil') From 47d722c967ebdd36b0fe06abf38b056b861edbd6 Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 3 Aug 2020 06:09:03 -0700 Subject: [PATCH 02/32] 1. Material design lib upgrade --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 53211cc..15fa3d8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7' - implementation 'com.google.android.material:material:1.3.0-alpha01' + implementation 'com.google.android.material:material:1.3.0-alpha02' implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.hbb20:ccp:2.4.0' From 707f332b1091cea283ee58f59106260948fc0996 Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 3 Aug 2020 06:10:29 -0700 Subject: [PATCH 03/32] 1. Rollback ndk task removal --- app/build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 15fa3d8..c93ff3c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,6 +38,16 @@ android { } } +task ndkBuild(type: Exec) { + def rootDir = project.rootDir + workingDir = new File(rootDir,"yggdrasil") + commandLine 'make' +} + +gradle.projectsEvaluated { + tasks.compileDebugKotlin.dependsOn(ndkBuild) +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(path: ':yggdrasil') From 4b8c9235b4be001d526afa461e12d9fe0a2775c6 Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 3 Aug 2020 06:57:10 -0700 Subject: [PATCH 04/32] 1. API 15 support (Android 4.0.3) --- .../chronosx88/yggdrasil/PeerListActivity.kt | 4 +- .../yggdrasil/YggdrasilTunService.kt | 83 +++++++++++-------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt index 4f74ab2..bd248d7 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt @@ -140,7 +140,9 @@ class PeerListActivity : AppCompatActivity() { var schemaInput = view.findViewById(R.id.schemaInput) var ipInput = view.findViewById(R.id.ipInput) ipInput.requestFocus() - schemaInput.showSoftInputOnFocus = false + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + schemaInput.showSoftInputOnFocus = false + } schemaInput.setOnFocusChangeListener { v, _ -> if(schemaInput.isFocused) { onClickSchemaList(v) diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index b0e593a..8030ed8 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -59,7 +59,7 @@ class YggdrasilTunService : VpnService() { when(intent?.getStringExtra(MainActivity.COMMAND)){ MainActivity.STOP ->{ stopVpn(pi) - startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service stopped")) + foregroundNotification(FOREGROUND_ID, "Yggdrasil service stopped") } MainActivity.START ->{ val peers = deserializeStringList2PeerInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_PEERS)) @@ -67,7 +67,7 @@ class YggdrasilTunService : VpnService() { val staticIP: Boolean = intent.getBooleanExtra(MainActivity.STATIC_IP, false) ygg = Yggdrasil() setupTunInterface(pi, peers, dns, staticIP) - startForeground(FOREGROUND_ID, foregroundNotification("Yggdrasil service started")) + foregroundNotification(FOREGROUND_ID, "Yggdrasil service started") } MainActivity.UPDATE_DNS ->{ val dns = deserializeStringList2DNSInfoSet(intent.getStringArrayListExtra(MainActivity.CURRENT_DNS)) @@ -84,11 +84,17 @@ class YggdrasilTunService : VpnService() { private fun setupIOStreams(dns: MutableSet){ address = ygg.addressString - var builder = Builder() - .addAddress(address!!, 7) - .allowFamily(OsConstants.AF_INET) - .allowBypass() - .setMtu(MAX_PACKET_SIZE) + var builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Builder() + .addAddress(address!!, 7) + .allowFamily(OsConstants.AF_INET) + .allowBypass() + .setMtu(MAX_PACKET_SIZE) + } else { + Builder() + .addAddress(address!!, 7) + .setMtu(MAX_PACKET_SIZE) + } if (dns.size > 0) { for (d in dns) { builder.addDnsServer(d.address) @@ -265,14 +271,17 @@ class YggdrasilTunService : VpnService() { private fun hasIpv6DefaultRoute(): Boolean { val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - val networks = cm.allNetworks - for (network in networks) { - val linkProperties = cm.getLinkProperties(network) - if(linkProperties!=null) { - val routes = linkProperties.routes - for (route in routes) { - if (route.isDefaultRoute && route.gateway is Inet6Address) { - return true + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + val networks = cm.allNetworks + + for (network in networks) { + val linkProperties = cm.getLinkProperties(network) + if(linkProperties!=null) { + val routes = linkProperties.routes + for (route in routes) { + if (route.isDefaultRoute && route.gateway is Inet6Address) { + return true + } } } } @@ -280,27 +289,29 @@ class YggdrasilTunService : VpnService() { return false } - private fun foregroundNotification(text: String): Notification? { - val channelId = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - createNotificationChannel(TAG, "Yggdrasil service") - } else { - // If earlier version channel ID is not used - // https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context) - "" - } - var intent = Intent(this, MainActivity::class.java) - var stackBuilder = TaskStackBuilder.create(this) - stackBuilder.addNextIntentWithParentStack(intent) - var pi = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) - val b = NotificationCompat.Builder(this, channelId) - b.setOngoing(true) - .setContentIntent(pi) - .setContentTitle(getString(R.string.app_name)) - .setContentText(text) - .setSmallIcon(R.mipmap.ic_launcher) - .setTicker(text) - return b.build() + private fun foregroundNotification(FOREGROUND_ID: Int, text: String) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + val channelId = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + createNotificationChannel(TAG, "Yggdrasil service") + } else { + // If earlier version channel ID is not used + // https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context) + "" + } + var intent = Intent(this, MainActivity::class.java) + var stackBuilder = TaskStackBuilder.create(this) + stackBuilder.addNextIntentWithParentStack(intent) + var pi = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) + val b = NotificationCompat.Builder(this, channelId) + b.setOngoing(true) + .setContentIntent(pi) + .setContentTitle(getString(R.string.app_name)) + .setContentText(text) + .setSmallIcon(R.mipmap.ic_launcher) + .setTicker(text) + startForeground(FOREGROUND_ID, b.build()) + } } @RequiresApi(Build.VERSION_CODES.O) From 4cd7cf2a0ece17d4f362777ee197395a3e9fa8ba Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 3 Aug 2020 07:03:21 -0700 Subject: [PATCH 05/32] 1. API 15 support (Android 4.0.3) --- app/src/main/res/layout/activity_main.xml | 3 ++- app/src/main/res/layout/host_list_item.xml | 3 ++- app/src/main/res/values-v21/styles.xml | 7 +++++++ app/src/main/res/values/styles.xml | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/values-v21/styles.xml diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 11d6687..b73ee8e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -27,7 +27,8 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:popupTheme="@style/AppTheme.PopupOverlay" /> + app:popupTheme="@style/AppTheme.PopupOverlay" + android:layout_marginRight="240dp" /> + android:textColor="@color/white" + android:paddingRight="20dp" /> \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..b208867 --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d53b11f..764b9fa 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -10,7 +10,7 @@