From dc1c5400b8e11e999917ea6221dfa4c351c8b67f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:49:09 +0800 Subject: [PATCH] Add mux concurency setting --- .../main/kotlin/com/v2ray/ang/AppConfig.kt | 1 + .../com/v2ray/ang/ui/SettingsActivity.kt | 22 +++++++++++++++---- .../com/v2ray/ang/util/V2rayConfigUtil.kt | 3 ++- .../v2ray/ang/viewmodel/SettingsViewModel.kt | 1 + .../src/main/res/values-zh-rCN/strings.xml | 3 ++- .../src/main/res/values-zh-rTW/strings.xml | 3 ++- V2rayNG/app/src/main/res/values/strings.xml | 3 ++- .../app/src/main/res/xml/pref_settings.xml | 6 +++++ 8 files changed, 34 insertions(+), 8 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt index da6d2d5cd..47784bbc8 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt @@ -41,6 +41,7 @@ object AppConfig { const val PREF_CONFIRM_REMOVE = "pref_confirm_remove" const val PREF_START_SCAN_IMMEDIATE = "pref_start_scan_immediate" const val PREF_MUX_ENABLED = "pref_mux_enabled" + const val PREF_MUX_CONCURRENCY = "pref_mux_concurency" const val PREF_MUX_XUDP_CONCURRENCY = "pref_mux_xudp_concurency" const val PREF_MUX_XUDP_QUIC = "pref_mux_xudp_quic" diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt index f1754f02d..b9e1dd04f 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt @@ -6,9 +6,7 @@ import android.text.TextUtils import android.view.View import androidx.activity.viewModels import androidx.preference.* -import androidx.work.Constraints import androidx.work.ExistingPeriodicWorkPolicy -import androidx.work.NetworkType import androidx.work.PeriodicWorkRequest import androidx.work.multiprocess.RemoteWorkManager import com.v2ray.ang.AngApplication @@ -39,6 +37,7 @@ class SettingsActivity : BaseActivity() { private val vpnDns by lazy { findPreference(AppConfig.PREF_VPN_DNS) } private val mux by lazy { findPreference(AppConfig.PREF_MUX_ENABLED) } + private val muxConcurrency by lazy { findPreference(AppConfig.PREF_MUX_CONCURRENCY) } private val muxXudpConcurrency by lazy { findPreference(AppConfig.PREF_MUX_XUDP_CONCURRENCY) } private val muxXudpQuic by lazy { findPreference(AppConfig.PREF_MUX_XUDP_QUIC) } @@ -161,10 +160,14 @@ class SettingsActivity : BaseActivity() { updateMux(newValue as Boolean) true } - muxXudpConcurrency?.setOnPreferenceChangeListener { _, newValue -> + muxConcurrency?.setOnPreferenceChangeListener { _, newValue -> updateMuxConcurrency(newValue as String) true } + muxXudpConcurrency?.setOnPreferenceChangeListener { _, newValue -> + updateMuxXudpConcurrency(newValue as String) + true + } } override fun onStart() { @@ -179,6 +182,7 @@ class SettingsActivity : BaseActivity() { socksPort?.summary = defaultSharedPreferences.getString(AppConfig.PREF_SOCKS_PORT, AppConfig.PORT_SOCKS) httpPort?.summary = defaultSharedPreferences.getString(AppConfig.PREF_HTTP_PORT, AppConfig.PORT_HTTP) updateMux(defaultSharedPreferences.getBoolean(AppConfig.PREF_MUX_ENABLED, false)) + muxConcurrency?.summary = defaultSharedPreferences.getString(AppConfig.PREF_MUX_CONCURRENCY, "8") muxXudpConcurrency?.summary = defaultSharedPreferences.getString(AppConfig.PREF_MUX_XUDP_CONCURRENCY, "8") autoUpdateInterval?.summary = defaultSharedPreferences.getString(AppConfig.SUBSCRIPTION_AUTO_UPDATE_INTERVAL,AppConfig.SUBSCRIPTION_DEFAULT_UPDATE_INTERVAL) autoUpdateInterval?.isEnabled = defaultSharedPreferences.getBoolean(AppConfig.SUBSCRIPTION_AUTO_UPDATE, false) @@ -257,14 +261,24 @@ class SettingsActivity : BaseActivity() { private fun updateMux(enabled: Boolean) { val defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()) + muxConcurrency?.isEnabled = enabled muxXudpConcurrency?.isEnabled = enabled muxXudpQuic?.isEnabled = enabled if (enabled) { - updateMuxConcurrency(defaultSharedPreferences.getString(AppConfig.PREF_MUX_XUDP_CONCURRENCY, "8")) + updateMuxConcurrency(defaultSharedPreferences.getString(AppConfig.PREF_MUX_CONCURRENCY, "8")) + updateMuxXudpConcurrency(defaultSharedPreferences.getString(AppConfig.PREF_MUX_XUDP_CONCURRENCY, "8")) } } private fun updateMuxConcurrency(value: String?) { + if (value == null) { + } else { + val concurrency = value.toIntOrNull() ?: 8 + muxConcurrency?.summary = concurrency.toString() + } + } + + private fun updateMuxXudpConcurrency(value: String?) { if (value == null) { muxXudpQuic?.isEnabled = true } else { diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt index 4e0df2224..9a785c16c 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt @@ -417,7 +417,8 @@ object V2rayConfigUtil { if (muxEnabled == true) { outbound.mux?.enabled = true - outbound.mux?.concurrency = 8 + outbound.mux?.concurrency = + settingsStorage?.decodeInt(AppConfig.PREF_MUX_CONCURRENCY) ?: 8 outbound.mux?.xudpConcurrency = settingsStorage?.decodeInt(AppConfig.PREF_MUX_XUDP_CONCURRENCY) ?: 8 outbound.mux?.xudpProxyUDP443 = diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt index 4fa407e86..98230e611 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/SettingsViewModel.kt @@ -61,6 +61,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application AppConfig.PREF_SNIFFING_ENABLED -> { settingsStorage?.encode(key, sharedPreferences.getBoolean(key, true)) } + AppConfig.PREF_MUX_CONCURRENCY, AppConfig.PREF_MUX_XUDP_CONCURRENCY -> { settingsStorage?.encode(key, sharedPreferences.getString(key, "8")?.toIntOrNull() ?: 8) } diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index ca069c49f..70da38bd8 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -97,7 +97,8 @@ 常规:勾选的App被代理,未勾选的直连;\n绕行模式:勾选的App直连,未勾选的被代理.\n不明白者在菜单中选择自动选中需代理应用 启用 Mux 多路复用 - 减低延时,但可能会断流,建议不要启用。\nTCP 默认复用 8 个子链接,UDP 及 QUIC 流量处理方式下方可选。 + 减低延时,但可能会断流,建议不要启用。\nTCP,UDP 及 QUIC 流量处理方式下方可选。 + TCP 复用子链接数(可填 -1 至 1024) XUDP 复用子链接数(可填 -1 至 1024) QUIC 流量处理方式 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index f05daff58..6f8c36b8b 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -97,7 +97,8 @@ 常規:勾選的 App 啟用 Proxy,未勾選的直接連線;\n繞行模式:勾選的 App 直接連線,未勾選的啟用 Proxy。\n可在選單中選擇自動選中需 Proxy 應用 啟用 Mux 多路復用 - 減低延時 但可能會斷流\nTCP 默認復用 8 個子鏈接,UDP 及 QUIC 流量處理方式下方可選 + 減低延時 但可能會斷流\nTCP,UDP 及 QUIC 流量處理方式下方可選 + TCP 復用子鏈接數(可填 -1 至 1024) XUDP 復用子鏈接數(可填 -1 至 1024) QUIC 流量處理方式 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index bf6a2654b..2805ae076 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -103,7 +103,8 @@ General: Checked App is proxy, unchecked direct connection; \nbypass mode: checked app directly connected, unchecked proxy. \nThe option to automatically select the proxy application in the menu Enable Mux - Faster, but it may cause unstable connectivity\nTCP traffic mux with default 8 connections,customize how to handle UDP and QUIC below + Faster, but it may cause unstable connectivity\ncustomize how to handle TCP, UDP and QUIC below + TCP connections(range -1 to 1024) XUDP connections(range -1 to 1024) Handling of QUIC in mux tunnel diff --git a/V2rayNG/app/src/main/res/xml/pref_settings.xml b/V2rayNG/app/src/main/res/xml/pref_settings.xml index 21c1751dc..b4793db95 100644 --- a/V2rayNG/app/src/main/res/xml/pref_settings.xml +++ b/V2rayNG/app/src/main/res/xml/pref_settings.xml @@ -12,6 +12,12 @@ android:summary="@string/summary_pref_mux_enabled" android:title="@string/title_pref_mux_enabled" /> + +