From 6039426bac59ff73db1c09c773e3a5152036a815 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Tue, 24 Sep 2024 17:37:19 +0800
Subject: [PATCH] Process self package at VpnService using
addDisallowedApplication
---
.../app/src/main/kotlin/com/v2ray/ang/AngApplication.kt | 1 -
.../kotlin/com/v2ray/ang/service/V2RayServiceManager.kt | 3 ---
.../main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt | 7 ++++++-
V2rayNG/app/src/main/res/raw/licenses.xml | 6 ------
4 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AngApplication.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AngApplication.kt
index 37b40f6e..fb81a00e 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AngApplication.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/AngApplication.kt
@@ -33,7 +33,6 @@ class AngApplication : MultiDexApplication() {
// if (firstRun)
// defaultSharedPreferences.edit().putInt(PREF_LAST_VERSION, BuildConfig.VERSION_CODE).apply()
- //Logger.init().logLevel(if (BuildConfig.DEBUG) LogLevel.FULL else LogLevel.NONE)
MMKV.initialize(this)
Utils.setNightMode(application)
diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt
index 687d0e80..86a09153 100644
--- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt
+++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt
@@ -106,13 +106,11 @@ object V2RayServiceManager {
}
override fun onEmitStatus(l: Long, s: String?): Long {
- //Logger.d(s)
return 0
}
override fun setup(s: String): Long {
val serviceControl = serviceControl?.get() ?: return -1
- //Logger.d(s)
return try {
serviceControl.startService()
lastQueryTime = System.currentTimeMillis()
@@ -197,7 +195,6 @@ object V2RayServiceManager {
val serviceControl = serviceControl?.get() ?: return
when (intent?.getIntExtra("key", 0)) {
AppConfig.MSG_REGISTER_CLIENT -> {
- //Logger.e("ReceiveMessageHandler", intent?.getIntExtra("key", 0).toString())
if (v2rayPoint.isRunning) {
MessageUtil.sendMsg2UI(serviceControl.getService(), AppConfig.MSG_STATE_RUNNING, "")
} else {
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 4c93bdc1..2de99d49 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.BuildConfig
import com.v2ray.ang.R
import com.v2ray.ang.util.MmkvManager.settingsStorage
import com.v2ray.ang.util.MyContextWrapper
@@ -150,9 +151,12 @@ class V2RayVpnService : VpnService(), ServiceControl {
builder.setSession(V2RayServiceManager.currentConfig?.remarks.orEmpty())
+ val selfPackageName = BuildConfig.APPLICATION_ID
if (settingsStorage?.decodeBool(AppConfig.PREF_PER_APP_PROXY) == true) {
val apps = settingsStorage?.decodeStringSet(AppConfig.PREF_PER_APP_PROXY_SET)
val bypassApps = settingsStorage?.decodeBool(AppConfig.PREF_BYPASS_APPS) ?: false
+ //process self package
+ if (bypassApps) apps?.add(selfPackageName) else apps?.remove(selfPackageName)
apps?.forEach {
try {
if (bypassApps)
@@ -160,9 +164,10 @@ class V2RayVpnService : VpnService(), ServiceControl {
else
builder.addAllowedApplication(it)
} catch (e: PackageManager.NameNotFoundException) {
- //Logger.d(e)
}
}
+ } else {
+ builder.addDisallowedApplication(selfPackageName)
}
// Close the old interface since the parameters have been changed.
diff --git a/V2rayNG/app/src/main/res/raw/licenses.xml b/V2rayNG/app/src/main/res/raw/licenses.xml
index 06723342..0ab99d8b 100644
--- a/V2rayNG/app/src/main/res/raw/licenses.xml
+++ b/V2rayNG/app/src/main/res/raw/licenses.xml
@@ -29,12 +29,6 @@
Copyright 2010-2016 JetBrains s.r.o.
Apache Software License 2.0
-
- Logger
- https://github.com/orhanobut/logger
- Copyright 2015 Orhan Obut
- Apache Software License 2.0
-
LeakCanary
https://github.com/square/leakcanary