From ec16ff0c71cd9e2f0ac2d2e652b3d73f2e1ebba1 Mon Sep 17 00:00:00 2001 From: Asutorufa <16442314+Asutorufa@users.noreply.github.com> Date: Sat, 8 Jun 2024 11:33:41 +0800 Subject: [PATCH] add udp proxy fqdn --- app/build.gradle.kts | 2 +- .../github/asutorufa/yuhaiin/RulePreferenceFragment.kt | 8 ++++++++ .../io/github/asutorufa/yuhaiin/database/Profile.kt | 3 +++ .../github/asutorufa/yuhaiin/database/YuhaiinDatabase.kt | 9 +++++++-- .../asutorufa/yuhaiin/service/YuhaiinVpnService.kt | 4 ++-- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/rule.xml | 6 ++++++ 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5b11022..d7d9825 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -168,7 +168,7 @@ android { dependencies { implementation(fileTree(mapOf("include" to listOf("*.aar", "*.jar"), "dir" to "libs"))) - implementation("androidx.appcompat:appcompat:1.6.1") + implementation("androidx.appcompat:appcompat:1.7.0") implementation("androidx.preference:preference-ktx:1.2.1") implementation("com.google.android.material:material:1.12.0") implementation("androidx.browser:browser:1.8.0") diff --git a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/RulePreferenceFragment.kt b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/RulePreferenceFragment.kt index 7069d2d..4d3249b 100644 --- a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/RulePreferenceFragment.kt +++ b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/RulePreferenceFragment.kt @@ -115,12 +115,20 @@ class RulePreferenceFragment : PreferenceFragmentCompat() { profile.bypass.udp = strToBypassType(newValue as String).value } } + + findPreference(resources.getString(R.string.udp_proxy_fqdn))!!.also { + it.isChecked = profile.udpProxyFqdn + setOnPreferenceChangeListener(it) { _, newValue -> + profile.udpProxyFqdn = newValue as Boolean + } + } } override fun onDisplayPreferenceDialog(preference: Preference) { when (preference) { is ListPreference, is EditTextPreference, is MultiSelectListPreference -> showDialog(preference) + else -> super.onDisplayPreferenceDialog(preference) } } diff --git a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/Profile.kt b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/Profile.kt index c114351..8ff3829 100644 --- a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/Profile.kt +++ b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/Profile.kt @@ -74,6 +74,9 @@ data class Profile ( defaultValue = Bypass.DefaultJson ) var bypass: Bypass = Bypass.Default, + @ColumnInfo(name = "udp_proxy_fqdn", defaultValue = "0") + var udpProxyFqdn: Boolean = false, + @ColumnInfo( name = "hosts", defaultValue = "{}" diff --git a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/YuhaiinDatabase.kt b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/YuhaiinDatabase.kt index dee99eb..436a37a 100644 --- a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/YuhaiinDatabase.kt +++ b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/database/YuhaiinDatabase.kt @@ -10,7 +10,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase @Database( entities = [Profile::class, LastProfile::class], - version = 11, + version = 12, exportSchema = false ) @TypeConverters(Converters::class) @@ -45,7 +45,7 @@ abstract class YuhaiinDatabase : RoomDatabase() { .addMigrations( MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9, MIGRATION_9_10, - MIGRATION_10_11 + MIGRATION_10_11, MIGRATION_11_12 ) .build() } @@ -98,5 +98,10 @@ abstract class YuhaiinDatabase : RoomDatabase() { db.execSQL("ALTER TABLE profile ADD COLUMN fake_dnsv6_cidr TEXT NOT NULL DEFAULT 'fc00::/64'") } } + private val MIGRATION_11_12 = object : Migration(11, 12) { + override fun migrate(db: SupportSQLiteDatabase) { + db.execSQL("ALTER TABLE profile ADD COLUMN udp_proxy_fqdn INTEGER NOT NULL DEFAULT 0") + } + } } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/service/YuhaiinVpnService.kt b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/service/YuhaiinVpnService.kt index b2f0b3b..20cd784 100644 --- a/app/src/main/kotlin/io/github/asutorufa/yuhaiin/service/YuhaiinVpnService.kt +++ b/app/src/main/kotlin/io/github/asutorufa/yuhaiin/service/YuhaiinVpnService.kt @@ -205,8 +205,7 @@ class YuhaiinVpnService : VpnService() { setMtu(VPN_MTU) setSession(profile.name) - addAddress(PRIVATE_VLAN4_ADDRESS, 24). - addRoute(PRIVATE_VLAN4_PORTAL, 32) + addAddress(PRIVATE_VLAN4_ADDRESS, 24).addRoute(PRIVATE_VLAN4_PORTAL, 32) // Route all IPv6 traffic addAddress(PRIVATE_VLAN6_ADDRESS, 64) @@ -294,6 +293,7 @@ class YuhaiinVpnService : VpnService() { direct = profile.ruleDirect tcp = profile.bypass.tcp udp = profile.bypass.udp + udpSkipResolveFqdn = profile.udpProxyFqdn } tun = TUN().apply { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 183a306..bcf3773 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,6 +63,7 @@ @string/bypass_proxy @string/bypass_block + UDP proxy FQDN dns diff --git a/app/src/main/res/xml/rule.xml b/app/src/main/res/xml/rule.xml index 23b0ae0..a87f404 100644 --- a/app/src/main/res/xml/rule.xml +++ b/app/src/main/res/xml/rule.xml @@ -30,6 +30,12 @@ app:useSimpleSummaryProvider="true" android:entryValues="@array/adv_bypass_mode" /> + +