From f8f17b5d385dc6ed864595a58c43c6171cb6160e Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Thu, 26 Sep 2024 13:25:39 +0800
Subject: [PATCH] Subscribe to add alias regular filter Add const LOOPBACK
---
.../main/kotlin/com/v2ray/ang/AppConfig.kt | 1 +
.../com/v2ray/ang/dto/SubscriptionItem.kt | 1 +
.../com/v2ray/ang/service/V2RayVpnService.kt | 5 +++--
.../com/v2ray/ang/ui/SubEditActivity.kt | 5 ++++-
.../com/v2ray/ang/ui/UserAssetActivity.kt | 3 ++-
.../com/v2ray/ang/util/AngConfigManager.kt | 11 ++++++++++-
.../com/v2ray/ang/util/SpeedtestUtil.kt | 3 ++-
.../main/kotlin/com/v2ray/ang/util/Utils.kt | 3 ++-
.../src/main/res/layout/activity_sub_edit.xml | 19 +++++++++++++++++++
.../app/src/main/res/values-ar/strings.xml | 1 +
.../app/src/main/res/values-bn/strings.xml | 1 +
.../app/src/main/res/values-fa/strings.xml | 1 +
.../app/src/main/res/values-ru/strings.xml | 1 +
.../app/src/main/res/values-vi/strings.xml | 1 +
.../src/main/res/values-zh-rCN/strings.xml | 1 +
.../src/main/res/values-zh-rTW/strings.xml | 3 ++-
V2rayNG/app/src/main/res/values/strings.xml | 1 +
17 files changed, 53 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 bf5803a9..f17c93f5 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt
@@ -113,6 +113,7 @@ object AppConfig {
const val WIREGUARD_LOCAL_ADDRESS_V4 = "172.16.0.2/32"
const val WIREGUARD_LOCAL_ADDRESS_V6 = "2606:4700:110:8f81:d551:a0:532e:a2b3/128"
const val WIREGUARD_LOCAL_MTU = "1420"
+ const val LOOPBACK = "127.0.0.1"
/** Message constants for communication. */
const val MSG_REGISTER_CLIENT = 1
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/SubscriptionItem.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/SubscriptionItem.kt
index b2a3a9a3..8e8c66a4 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/SubscriptionItem.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/SubscriptionItem.kt
@@ -10,5 +10,6 @@ data class SubscriptionItem(
val updateInterval: Int? = null,
var prevProfile: String? = null,
var nextProfile: String? = null,
+ var filter: String? = null,
)
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt
index 8a132d22..c42e33fb 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt
@@ -17,6 +17,7 @@ import android.os.StrictMode
import android.util.Log
import androidx.annotation.RequiresApi
import com.v2ray.ang.AppConfig
+import com.v2ray.ang.AppConfig.LOOPBACK
import com.v2ray.ang.BuildConfig
import com.v2ray.ang.R
import com.v2ray.ang.util.MmkvManager.settingsStorage
@@ -207,7 +208,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
File(applicationContext.applicationInfo.nativeLibraryDir, TUN2SOCKS).absolutePath,
"--netif-ipaddr", PRIVATE_VLAN4_ROUTER,
"--netif-netmask", "255.255.255.252",
- "--socks-server-addr", "127.0.0.1:${socksPort}",
+ "--socks-server-addr", "$LOOPBACK:${socksPort}",
"--tunmtu", VPN_MTU.toString(),
"--sock-path", "sock_path",//File(applicationContext.filesDir, "sock_path").absolutePath,
"--enable-udprelay",
@@ -221,7 +222,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
if (settingsStorage?.decodeBool(AppConfig.PREF_LOCAL_DNS_ENABLED) == true) {
val localDnsPort = Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_LOCAL_DNS_PORT), AppConfig.PORT_LOCAL_DNS.toInt())
cmd.add("--dnsgw")
- cmd.add("127.0.0.1:${localDnsPort}")
+ cmd.add("$LOOPBACK:${localDnsPort}")
}
Log.d(packageName, cmd.toString())
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SubEditActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SubEditActivity.kt
index 76a43330..86b27da5 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SubEditActivity.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SubEditActivity.kt
@@ -42,6 +42,7 @@ class SubEditActivity : BaseActivity() {
private fun bindingServer(subItem: SubscriptionItem): Boolean {
binding.etRemarks.text = Utils.getEditable(subItem.remarks)
binding.etUrl.text = Utils.getEditable(subItem.url)
+ binding.etFilter.text = Utils.getEditable(subItem.filter)
binding.chkEnable.isChecked = subItem.enabled
binding.autoUpdateCheck.isChecked = subItem.autoUpdate
binding.etPreProfile.text = Utils.getEditable(subItem.prevProfile)
@@ -55,6 +56,7 @@ class SubEditActivity : BaseActivity() {
private fun clearServer(): Boolean {
binding.etRemarks.text = null
binding.etUrl.text = null
+ binding.etFilter.text = null
binding.chkEnable.isChecked = true
binding.etPreProfile.text = null
binding.etNextProfile.text = null
@@ -65,10 +67,11 @@ class SubEditActivity : BaseActivity() {
* save server config
*/
private fun saveServer(): Boolean {
- val subItem = MmkvManager.decodeSubscription(editSubId)?:SubscriptionItem()
+ val subItem = MmkvManager.decodeSubscription(editSubId) ?: SubscriptionItem()
subItem.remarks = binding.etRemarks.text.toString()
subItem.url = binding.etUrl.text.toString()
+ subItem.filter = binding.etFilter.text.toString()
subItem.enabled = binding.chkEnable.isChecked
subItem.autoUpdate = binding.autoUpdateCheck.isChecked
subItem.prevProfile = binding.etPreProfile.text.toString()
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/UserAssetActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/UserAssetActivity.kt
index 3cfa7c4e..00983e2d 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/UserAssetActivity.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/UserAssetActivity.kt
@@ -21,6 +21,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.tbruyelle.rxpermissions3.RxPermissions
import com.v2ray.ang.AppConfig
+import com.v2ray.ang.AppConfig.LOOPBACK
import com.v2ray.ang.R
import com.v2ray.ang.databinding.ActivitySubSettingBinding
import com.v2ray.ang.databinding.ItemRecyclerUserAssetBinding
@@ -212,7 +213,7 @@ class UserAssetActivity : BaseActivity() {
URL(item.url).openConnection(
Proxy(
Proxy.Type.HTTP,
- InetSocketAddress("127.0.0.1", httpPort)
+ InetSocketAddress(LOOPBACK, httpPort)
)
) as HttpURLConnection
}
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
index 6d48a0aa..34cd94aa 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
@@ -32,6 +32,7 @@ object AngConfigManager {
private fun parseConfig(
str: String?,
subid: String,
+ subItem: SubscriptionItem?,
removedSelectedServer: ServerConfig?
): Int {
try {
@@ -60,6 +61,13 @@ object AngConfigManager {
if (config == null) {
return R.string.toast_incorrect_protocol
}
+ //filter
+ if (subItem?.filter != null && subItem.filter?.isNotEmpty() == true && config.remarks.isNotEmpty()) {
+ val matched = Regex(pattern = subItem.filter ?: "")
+ .containsMatchIn(input = config.remarks)
+ if (!matched) return -1
+ }
+
config.subscriptionId = subid
val guid = MmkvManager.encodeServerConfig("", config)
if (removedSelectedServer != null &&
@@ -244,11 +252,12 @@ object AngConfigManager {
MmkvManager.removeServerViaSubid(subid)
}
+ val subItem = MmkvManager.decodeSubscription(subid)
var count = 0
servers.lines()
.reversed()
.forEach {
- val resId = parseConfig(it, subid, removedSelectedServer)
+ val resId = parseConfig(it, subid, subItem, removedSelectedServer)
if (resId == 0) {
count++
}
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SpeedtestUtil.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SpeedtestUtil.kt
index 03a3f6ba..29e27de0 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SpeedtestUtil.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SpeedtestUtil.kt
@@ -5,6 +5,7 @@ import android.os.SystemClock
import android.text.TextUtils
import android.util.Log
import com.v2ray.ang.AppConfig
+import com.v2ray.ang.AppConfig.LOOPBACK
import com.v2ray.ang.R
import com.v2ray.ang.extension.responseLength
import kotlinx.coroutines.isActive
@@ -108,7 +109,7 @@ object SpeedtestUtil {
conn = url.openConnection(
Proxy(
Proxy.Type.HTTP,
- InetSocketAddress("127.0.0.1", port)
+ InetSocketAddress(LOOPBACK, port)
)
) as HttpURLConnection
conn.connectTimeout = 30000
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
index 24271013..062cef60 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
@@ -19,6 +19,7 @@ import android.webkit.URLUtil
import androidx.appcompat.app.AppCompatDelegate
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_PACKAGE
+import com.v2ray.ang.AppConfig.LOOPBACK
import com.v2ray.ang.BuildConfig
import com.v2ray.ang.R
import com.v2ray.ang.extension.toast
@@ -359,7 +360,7 @@ object Utils {
url.openConnection(
Proxy(
Proxy.Type.HTTP,
- InetSocketAddress("127.0.0.1", httpPort)
+ InetSocketAddress(LOOPBACK, httpPort)
)
)
}
diff --git a/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml b/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml
index 0ea797c4..00b8fcbb 100644
--- a/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml
+++ b/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml
@@ -72,6 +72,25 @@
+
+
+
+
+
+
+
+
إعداد مجموعة الاشتراك
ملاحظات
عنوان URL اختياري
+ Remarks regular filter
تفعيل التحديث
تفعيل التحديث التلقائي
Previous proxy remarks
diff --git a/V2rayNG/app/src/main/res/values-bn/strings.xml b/V2rayNG/app/src/main/res/values-bn/strings.xml
index f4836dc5..7c47a854 100644
--- a/V2rayNG/app/src/main/res/values-bn/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bn/strings.xml
@@ -229,6 +229,7 @@
সাবস্ক্রিপশন গ্রুপ সেটিং
মন্তব্য
ঐচ্ছিক URL
+ Remarks regular filter
আপডেট সক্রিয় করুন
স্বয়ংক্রিয় আপডেট সক্রিয় করুন
Previous proxy remarks
diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml
index dea8ed51..a2326790 100644
--- a/V2rayNG/app/src/main/res/values-fa/strings.xml
+++ b/V2rayNG/app/src/main/res/values-fa/strings.xml
@@ -227,6 +227,7 @@
تنظیمات گروهی اشتراک
ملاحظات
نشانی اینترنتی اختیاری
+ Remarks regular filter
فعال کردن بهروزرسانی
فعال سازی بهروزرسانی خودکار
Previous proxy remarks
diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml
index 86d01e45..835c6cb9 100644
--- a/V2rayNG/app/src/main/res/values-ru/strings.xml
+++ b/V2rayNG/app/src/main/res/values-ru/strings.xml
@@ -231,6 +231,7 @@
Группы
Название
URL (необязательно)
+ Remarks regular filter
Использовать обновление
Использовать автоматическое обновление
Название предыдущего прокси
diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml
index 5621af00..b44a91f2 100644
--- a/V2rayNG/app/src/main/res/values-vi/strings.xml
+++ b/V2rayNG/app/src/main/res/values-vi/strings.xml
@@ -230,6 +230,7 @@
Các gói đăng ký
Tên gói đăng ký
URL gói đăng ký
+ Remarks regular filter
Sử dụng gói đăng ký này
Bật tự động cập nhật
Previous proxy remarks
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 d1e31ba7..603f40fa 100644
--- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
@@ -228,6 +228,7 @@
订阅分组设置
备注
可选地址(url)
+ 别名正则过滤
启用更新
启用自动更新
前置代理别名
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 f95323e2..1d9e85ac 100644
--- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
@@ -228,7 +228,8 @@
匯出目前群組配置至剪貼簿
訂閱分組設定
備註
- Optional URL
+ 可選位址(url)
+ 別名正規過濾
啟用更新
啟用自動更新
前置代理别名
diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml
index 764cdbd8..217567ea 100644
--- a/V2rayNG/app/src/main/res/values/strings.xml
+++ b/V2rayNG/app/src/main/res/values/strings.xml
@@ -234,6 +234,7 @@
Subscription group setting
remarks
Optional URL
+ Remarks regular filter
Enable update
Enable automatic update
Previous proxy remarks