From fc852281dd4470456b94f772489e2152057c5281 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sun, 3 Dec 2023 16:04:31 -0500 Subject: [PATCH] Use Android ID as XUDP basekey Since Xray 1.8.1, XUDP pass basekey as the global ID. It can maintain the same UDP port on the proxy server outbound. To enable maximum UDP connectivity, client should pass the device unique ID in the environment variable. --- .../kotlin/com/v2ray/ang/service/V2RayServiceManager.kt | 2 +- .../main/kotlin/com/v2ray/ang/service/V2RayTestService.kt | 2 +- V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) 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 15f4a1e8..023df39a 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 @@ -50,7 +50,7 @@ object V2RayServiceManager { set(value) { field = value Seq.setContext(value?.get()?.getService()?.applicationContext) - Libv2ray.initV2Env(Utils.userAssetPath(value?.get()?.getService())) + Libv2ray.initV2Env(Utils.userAssetPath(value?.get()?.getService()), Utils.getDeviceIdForXUDPBaseKey()) } var currentConfig: ServerConfig? = null diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayTestService.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayTestService.kt index 362b7196..d8414000 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayTestService.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayTestService.kt @@ -20,7 +20,7 @@ class V2RayTestService : Service() { override fun onCreate() { super.onCreate() Seq.setContext(this) - Libv2ray.initV2Env(Utils.userAssetPath(this)) + Libv2ray.initV2Env(Utils.userAssetPath(this), Utils.getDeviceIdForXUDPBaseKey()) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { 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 33aa5933..07ea467b 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 @@ -13,6 +13,7 @@ import android.content.res.Configuration.UI_MODE_NIGHT_NO import android.net.Uri import android.os.Build import android.os.LocaleList +import android.provider.Settings import android.util.Log import android.util.Patterns import android.webkit.URLUtil @@ -317,6 +318,11 @@ object Utils { return extDir.absolutePath } + fun getDeviceIdForXUDPBaseKey(): String { + val androidId = Settings.Secure.ANDROID_ID.toByteArray(charset("UTF-8")) + return Base64.encodeToString(androidId.copyOf(32), Base64.NO_PADDING.or(Base64.URL_SAFE)) + } + fun getUrlContext(url: String, timeout: Int): String { var result: String var conn: HttpURLConnection? = null