add hevtun option (#4817)

This commit is contained in:
fuilloi
2025-08-08 17:03:27 +08:00
committed by GitHub
parent 785aa7eb8a
commit 6318dd554b
15 changed files with 78 additions and 9 deletions

View File

@@ -63,6 +63,8 @@ object AppConfig {
const val PREF_CHECK_UPDATE_PRE_RELEASE = "pref_check_update_pre_release" const val PREF_CHECK_UPDATE_PRE_RELEASE = "pref_check_update_pre_release"
const val PREF_GEO_FILES_SOURCES = "pref_geo_files_sources" const val PREF_GEO_FILES_SOURCES = "pref_geo_files_sources"
const val PREF_USE_HEV_TUNNEL = "pref_use_hev_tunnel" const val PREF_USE_HEV_TUNNEL = "pref_use_hev_tunnel"
const val PREF_HEV_TUNNEL_LOGLEVEL = "pref_hev_tunnel_loglevel"
const val PREF_HEV_TUNNEL_RW_TIMEOUT = "pref_hev_tunnel_rw_timeout"
/** Cache keys. */ /** Cache keys. */
const val CACHE_SUBSCRIPTION_ID = "cache_subscription_id" const val CACHE_SUBSCRIPTION_ID = "cache_subscription_id"
@@ -166,6 +168,9 @@ object AppConfig {
const val VPN = "VPN" const val VPN = "VPN"
const val VPN_MTU = 1500 const val VPN_MTU = 1500
/** hev-sock5-tunnel read-write-timeout value */
const val HEVTUN_RW_TIMEOUT = "300000"
// Google API rule constants // Google API rule constants
const val GOOGLEAPIS_CN_DOMAIN = "domain:googleapis.cn" const val GOOGLEAPIS_CN_DOMAIN = "domain:googleapis.cn"
const val GOOGLEAPIS_COM_DOMAIN = "googleapis.com" const val GOOGLEAPIS_COM_DOMAIN = "googleapis.com"

View File

@@ -72,12 +72,11 @@ class TProxyService(
appendLine(" address: ${AppConfig.LOOPBACK}") appendLine(" address: ${AppConfig.LOOPBACK}")
appendLine(" udp: 'udp'") appendLine(" udp: 'udp'")
MmkvManager.decodeSettingsString(AppConfig.PREF_LOGLEVEL)?.let { logPref ->
if (logPref != "none") {
val logLevel = if (logPref == "warning") "warn" else logPref
appendLine("misc:") appendLine("misc:")
appendLine(" log-level: $logLevel") appendLine(" read-write-timeout: ${MmkvManager.decodeSettingsString(AppConfig.PREF_HEV_TUNNEL_RW_TIMEOUT) ?: AppConfig.HEVTUN_RW_TIMEOUT}")
} val hevTunLogLevel = MmkvManager.decodeSettingsString(AppConfig.PREF_HEV_TUNNEL_LOGLEVEL) ?: "none"
if (hevTunLogLevel != "none") {
appendLine(" log-level: $hevTunLogLevel")
} }
} }
} }

View File

@@ -66,6 +66,10 @@ class SettingsActivity : BaseActivity() {
private val delayTestUrl by lazy { findPreference<EditTextPreference>(AppConfig.PREF_DELAY_TEST_URL) } private val delayTestUrl by lazy { findPreference<EditTextPreference>(AppConfig.PREF_DELAY_TEST_URL) }
private val mode by lazy { findPreference<ListPreference>(AppConfig.PREF_MODE) } private val mode by lazy { findPreference<ListPreference>(AppConfig.PREF_MODE) }
private val hevTunLogLevel by lazy { findPreference<ListPreference>(AppConfig.PREF_HEV_TUNNEL_LOGLEVEL) }
private val hevTunRwTimeout by lazy { findPreference<EditTextPreference>(AppConfig.PREF_HEV_TUNNEL_RW_TIMEOUT) }
private val useHevTun by lazy { findPreference<CheckBoxPreference>(AppConfig.PREF_USE_HEV_TUNNEL) }
override fun onCreatePreferences(bundle: Bundle?, s: String?) { override fun onCreatePreferences(bundle: Bundle?, s: String?) {
addPreferencesFromResource(R.xml.pref_settings) addPreferencesFromResource(R.xml.pref_settings)
@@ -172,6 +176,16 @@ class SettingsActivity : BaseActivity() {
mode?.dialogLayoutResource = R.layout.preference_with_help_link mode?.dialogLayoutResource = R.layout.preference_with_help_link
//loglevel.summary = "LogLevel" //loglevel.summary = "LogLevel"
useHevTun?.setOnPreferenceChangeListener { _, newValue ->
updateHevTunSettings(newValue as Boolean)
true
}
hevTunRwTimeout?.setOnPreferenceChangeListener { _, any ->
val nval = any as String
hevTunRwTimeout?.summary = if (TextUtils.isEmpty(nval)) AppConfig.HEVTUN_RW_TIMEOUT else nval
true
}
} }
override fun onStart() { override fun onStart() {
@@ -205,6 +219,9 @@ class SettingsActivity : BaseActivity() {
dnsHosts?.summary = MmkvManager.decodeSettingsString(AppConfig.PREF_DNS_HOSTS) dnsHosts?.summary = MmkvManager.decodeSettingsString(AppConfig.PREF_DNS_HOSTS)
delayTestUrl?.summary = MmkvManager.decodeSettingsString(AppConfig.PREF_DELAY_TEST_URL, AppConfig.DELAY_TEST_URL) delayTestUrl?.summary = MmkvManager.decodeSettingsString(AppConfig.PREF_DELAY_TEST_URL, AppConfig.DELAY_TEST_URL)
updateHevTunSettings(MmkvManager.decodeSettingsBool(AppConfig.PREF_USE_HEV_TUNNEL, false))
hevTunRwTimeout?.summary = MmkvManager.decodeSettingsString(AppConfig.PREF_HEV_TUNNEL_RW_TIMEOUT, AppConfig.HEVTUN_RW_TIMEOUT)
initSharedPreference() initSharedPreference()
} }
@@ -220,7 +237,8 @@ class SettingsActivity : BaseActivity() {
socksPort, socksPort,
remoteDns, remoteDns,
domesticDns, domesticDns,
delayTestUrl delayTestUrl,
hevTunRwTimeout
).forEach { key -> ).forEach { key ->
key?.text = key?.summary.toString() key?.text = key?.summary.toString()
} }
@@ -260,7 +278,8 @@ class SettingsActivity : BaseActivity() {
AppConfig.PREF_LOGLEVEL, AppConfig.PREF_LOGLEVEL,
AppConfig.PREF_OUTBOUND_DOMAIN_RESOLVE_METHOD, AppConfig.PREF_OUTBOUND_DOMAIN_RESOLVE_METHOD,
AppConfig.PREF_INTELLIGENT_SELECTION_METHOD, AppConfig.PREF_INTELLIGENT_SELECTION_METHOD,
AppConfig.PREF_MODE AppConfig.PREF_MODE,
AppConfig.PREF_HEV_TUNNEL_LOGLEVEL
).forEach { key -> ).forEach { key ->
if (MmkvManager.decodeSettingsString(key) != null) { if (MmkvManager.decodeSettingsString(key) != null) {
findPreference<ListPreference>(key)?.value = MmkvManager.decodeSettingsString(key) findPreference<ListPreference>(key)?.value = MmkvManager.decodeSettingsString(key)
@@ -366,6 +385,11 @@ class SettingsActivity : BaseActivity() {
private fun updateFragmentInterval(value: String?) { private fun updateFragmentInterval(value: String?) {
fragmentInterval?.summary = value.toString() fragmentInterval?.summary = value.toString()
} }
private fun updateHevTunSettings(enabled: Boolean) {
hevTunLogLevel?.isEnabled = enabled
hevTunRwTimeout?.isEnabled = enabled
}
} }
fun onModeHelpClicked(view: View) { fun onModeHelpClicked(view: View) {

View File

@@ -59,6 +59,8 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
AppConfig.PREF_FRAGMENT_LENGTH, AppConfig.PREF_FRAGMENT_LENGTH,
AppConfig.PREF_FRAGMENT_INTERVAL, AppConfig.PREF_FRAGMENT_INTERVAL,
AppConfig.PREF_MUX_XUDP_QUIC, AppConfig.PREF_MUX_XUDP_QUIC,
AppConfig.PREF_HEV_TUNNEL_LOGLEVEL,
AppConfig.PREF_HEV_TUNNEL_RW_TIMEOUT
-> { -> {
MmkvManager.encodeSettings(key, sharedPreferences.getString(key, "")) MmkvManager.encodeSettings(key, sharedPreferences.getString(key, ""))
} }

View File

@@ -249,6 +249,8 @@
<string name="title_pref_ui_mode_night">إعدادات وضع واجهة المستخدم ليلاً</string> <string name="title_pref_ui_mode_night">إعدادات وضع واجهة المستخدم ليلاً</string>
<string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string> <string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string>
<string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string> <string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">Logcat</string> <string name="title_logcat">Logcat</string>
<string name="logcat_copy">نسخ</string> <string name="logcat_copy">نسخ</string>

View File

@@ -250,6 +250,8 @@
<string name="title_pref_ui_mode_night">ইউআই মোড সেটিংস</string> <string name="title_pref_ui_mode_night">ইউআই মোড সেটিংস</string>
<string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string> <string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string>
<string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string> <string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">লগক্যাট</string> <string name="title_logcat">লগক্যাট</string>
<string name="logcat_copy">কপি করুন</string> <string name="logcat_copy">কপি করুন</string>

View File

@@ -250,6 +250,8 @@
<string name="title_pref_ui_mode_night">سامووا هالت رابت منتوری</string> <string name="title_pref_ui_mode_night">سامووا هالت رابت منتوری</string>
<string name="title_pref_use_hev_tunnel">فعال کردن ویژیی نۊ TUN</string> <string name="title_pref_use_hev_tunnel">فعال کردن ویژیی نۊ TUN</string>
<string name="summary_pref_use_hev_tunnel">مجالی ک فعال بۊ، TUN ، hev-socks5-tunnel ن و کار اگره؛ ٱر چینووݩ نبۊ و جاس badvpn-tun2socks و کار گرؽڌه ابۊ.</string> <string name="summary_pref_use_hev_tunnel">مجالی ک فعال بۊ، TUN ، hev-socks5-tunnel ن و کار اگره؛ ٱر چینووݩ نبۊ و جاس badvpn-tun2socks و کار گرؽڌه ابۊ.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">داسووا</string> <string name="title_logcat">داسووا</string>
<string name="logcat_copy">لف گیری</string> <string name="logcat_copy">لف گیری</string>

View File

@@ -247,6 +247,8 @@
<string name="title_pref_ui_mode_night">تنظیمات حالت رابط کاربری</string> <string name="title_pref_ui_mode_night">تنظیمات حالت رابط کاربری</string>
<string name="title_pref_use_hev_tunnel">فعالسازی قابلیت TUN جدید</string> <string name="title_pref_use_hev_tunnel">فعالسازی قابلیت TUN جدید</string>
<string name="summary_pref_use_hev_tunnel">در صورت فعال بودن، TUN از hev-socks5-tunnel استفاده می‌کند؛ در غیر این صورت از badvpn-tun2socks.</string> <string name="summary_pref_use_hev_tunnel">در صورت فعال بودن، TUN از hev-socks5-tunnel استفاده می‌کند؛ در غیر این صورت از badvpn-tun2socks.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">گزارشات</string> <string name="title_logcat">گزارشات</string>
<string name="logcat_copy">کپی</string> <string name="logcat_copy">کپی</string>

View File

@@ -249,6 +249,8 @@
<string name="title_pref_ui_mode_night">Тема интерфейса</string> <string name="title_pref_ui_mode_night">Тема интерфейса</string>
<string name="title_pref_use_hev_tunnel">Использовать новую версию TUN</string> <string name="title_pref_use_hev_tunnel">Использовать новую версию TUN</string>
<string name="summary_pref_use_hev_tunnel">Если включено, TUN будет использовать hev-socks5-tunnel; иначе будет использоваться badvpn-tun2socks.</string> <string name="summary_pref_use_hev_tunnel">Если включено, TUN будет использовать hev-socks5-tunnel; иначе будет использоваться badvpn-tun2socks.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">Журнал</string> <string name="title_logcat">Журнал</string>
<string name="logcat_copy">Копировать</string> <string name="logcat_copy">Копировать</string>

View File

@@ -250,6 +250,8 @@
<string name="title_pref_ui_mode_night">Cài đặt chế độ UI</string> <string name="title_pref_ui_mode_night">Cài đặt chế độ UI</string>
<string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string> <string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string>
<string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string> <string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">Logcat</string> <string name="title_logcat">Logcat</string>
<string name="logcat_copy">Sao chép</string> <string name="logcat_copy">Sao chép</string>

View File

@@ -247,6 +247,8 @@
<string name="title_pref_ui_mode_night">界面颜色设置</string> <string name="title_pref_ui_mode_night">界面颜色设置</string>
<string name="title_pref_use_hev_tunnel">启用新的 TUN 功能</string> <string name="title_pref_use_hev_tunnel">启用新的 TUN 功能</string>
<string name="summary_pref_use_hev_tunnel">选择启用后 TUN 将使用 hev-socks5-tunnel 否则使用 badvpn-tun2socks</string> <string name="summary_pref_use_hev_tunnel">选择启用后 TUN 将使用 hev-socks5-tunnel 否则使用 badvpn-tun2socks</string>
<string name="title_pref_hev_tunnel_loglevel">HevTun日志级别</string>
<string name="title_pref_hev_tunnel_rw_timeout">HevTun读写超时 (ms)</string>
<string name="title_logcat">Logcat</string> <string name="title_logcat">Logcat</string>
<string name="logcat_copy">复制</string> <string name="logcat_copy">复制</string>

View File

@@ -248,6 +248,8 @@
<string name="title_pref_ui_mode_night">介面顯示模式</string> <string name="title_pref_ui_mode_night">介面顯示模式</string>
<string name="title_pref_use_hev_tunnel">啟用新 TUN 功能</string> <string name="title_pref_use_hev_tunnel">啟用新 TUN 功能</string>
<string name="summary_pref_use_hev_tunnel">選擇啟用後TUN 將使用 hev-socks5-tunnel否則使用 badvpn-tun2socks。</string> <string name="summary_pref_use_hev_tunnel">選擇啟用後TUN 將使用 hev-socks5-tunnel否則使用 badvpn-tun2socks。</string>
<string name="title_pref_hev_tunnel_loglevel">HevTun日誌級別</string>
<string name="title_pref_hev_tunnel_rw_timeout">HevTun讀寫超時 (ms)</string>
<string name="title_logcat">Logcat</string> <string name="title_logcat">Logcat</string>
<string name="logcat_copy">複製</string> <string name="logcat_copy">複製</string>

View File

@@ -118,6 +118,13 @@
<item>Proxy only</item> <item>Proxy only</item>
</string-array> </string-array>
<string-array name="hev_tunnel_loglevel" translatable="false">
<item>none</item>
<item>error</item>
<item>warn</item>
<item>debug</item>
</string-array>
<string-array name="flows" translatable="false"> <string-array name="flows" translatable="false">
<item></item> <item></item>
<item>xtls-rprx-vision</item> <item>xtls-rprx-vision</item>

View File

@@ -251,6 +251,8 @@
<string name="title_pref_ui_mode_night">UI mode settings</string> <string name="title_pref_ui_mode_night">UI mode settings</string>
<string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string> <string name="title_pref_use_hev_tunnel">Enable New TUN Feature</string>
<string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string> <string name="summary_pref_use_hev_tunnel">When enabled, TUN will use hev-socks5-tunnel; otherwise, it will use badvpn-tun2socks.</string>
<string name="title_pref_hev_tunnel_loglevel">Hev Tun Log Level</string>
<string name="title_pref_hev_tunnel_rw_timeout">Hev Tun Read/Write Timeout (ms)</string>
<string name="title_logcat">Logcat</string> <string name="title_logcat">Logcat</string>
<string name="logcat_copy">Copy</string> <string name="logcat_copy">Copy</string>

View File

@@ -260,7 +260,21 @@
android:key="pref_use_hev_tunnel" android:key="pref_use_hev_tunnel"
android:summary="@string/summary_pref_use_hev_tunnel" android:summary="@string/summary_pref_use_hev_tunnel"
android:title="@string/title_pref_use_hev_tunnel" /> android:title="@string/title_pref_use_hev_tunnel" />
<ListPreference
android:defaultValue="none"
android:entries="@array/hev_tunnel_loglevel"
android:entryValues="@array/hev_tunnel_loglevel"
android:key="pref_hev_tunnel_loglevel"
android:summary="%s"
android:title="@string/title_pref_hev_tunnel_loglevel" />
<EditTextPreference
android:inputType="number"
android:key="pref_hev_tunnel_rw_timeout"
android:summary="300000"
android:title="@string/title_pref_hev_tunnel_rw_timeout" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>