Code cleanup: imports, formatting, and minor fixes

This commit is contained in:
2dust
2026-05-09 11:42:23 +08:00
parent a4e2e6d6a2
commit fd84ea4114
24 changed files with 72 additions and 61 deletions
@@ -97,8 +97,7 @@ object CoreConfigContextBuilder {
.filter { it.configType != EConfigType.POLICYGROUP }
.filter { it.configType != EConfigType.PROXYCHAIN }
.toList()
}
catch (e: Exception) {
} catch (e: Exception) {
LogUtil.e(AppConfig.TAG, "Failed to resolve policy group profiles for config '${config.remarks}'", e)
return listOf(config)
}
@@ -121,8 +120,7 @@ object CoreConfigContextBuilder {
.filter { it.configType != EConfigType.PROXYCHAIN }
.toList()
.reversed()
}
catch (e: Exception) {
} catch (e: Exception) {
LogUtil.e(AppConfig.TAG, "Failed to resolve proxy chain profiles for config '${config.remarks}'", e)
return listOf(config)
}
@@ -4,7 +4,6 @@ import com.v2ray.ang.AppConfig
import com.v2ray.ang.dto.ProfileItem
import com.v2ray.ang.enums.NetworkType
import com.v2ray.ang.extension.nullIfBlank
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.util.HttpUtil
import com.v2ray.ang.util.Utils
import java.net.URI
@@ -1,8 +1,6 @@
package com.v2ray.ang.handler
import android.os.SystemClock
import com.v2ray.ang.AppConfig
import com.v2ray.ang.R
import com.v2ray.ang.dto.IPAPIInfo
import com.v2ray.ang.util.HttpUtil
import com.v2ray.ang.util.JsonUtil
@@ -14,9 +14,9 @@ import com.v2ray.ang.AngApplication
import com.v2ray.ang.AppConfig
import com.v2ray.ang.R
import com.v2ray.ang.dto.SubscriptionCache
import com.v2ray.ang.enums.NotificationChannelType
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.NotificationHelper
import com.v2ray.ang.enums.NotificationChannelType
import java.util.concurrent.TimeUnit
object SubscriptionUpdater {
@@ -1,6 +1,5 @@
package com.v2ray.ang.handler
import android.content.Context
import android.os.Build
import com.v2ray.ang.AppConfig
import com.v2ray.ang.BuildConfig
@@ -12,8 +11,6 @@ import com.v2ray.ang.util.JsonUtil
import com.v2ray.ang.util.LogUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
object UpdateCheckerManager {
suspend fun checkForUpdate(includePreRelease: Boolean = false): CheckUpdateResult = withContext(Dispatchers.IO) {
@@ -4,9 +4,9 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.v2ray.ang.AppConfig
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SubscriptionUpdater
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.util.LogUtil
class BootReceiver : BroadcastReceiver() {
@@ -6,8 +6,8 @@ import android.content.Intent
import android.os.IBinder
import com.v2ray.ang.AppConfig
import com.v2ray.ang.contracts.ServiceControl
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.MyContextWrapper
import java.lang.ref.SoftReference
@@ -5,15 +5,15 @@ import android.content.Intent
import android.os.IBinder
import com.v2ray.ang.AppConfig
import com.v2ray.ang.R
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.dto.RealPingEvent
import com.v2ray.ang.dto.TestServiceMessage
import com.v2ray.ang.enums.NotificationChannelType
import com.v2ray.ang.extension.serializable
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.MessageUtil
import com.v2ray.ang.util.NotificationHelper
import com.v2ray.ang.enums.NotificationChannelType
import java.util.Collections
class CoreTestService : Service() {
@@ -68,7 +68,9 @@ class CoreTestService : Service() {
when (message.key) {
AppConfig.MSG_MEASURE_CONFIG_START -> handleMeasureStart(message, startId)
AppConfig.MSG_MEASURE_CONFIG_CANCEL -> handleMeasureCancel()
else -> { NotificationHelper.stopForeground(this); stopSelf(startId) }
else -> {
NotificationHelper.stopForeground(this); stopSelf(startId)
}
}
return START_NOT_STICKY
}
@@ -94,7 +96,7 @@ class CoreTestService : Service() {
worker = RealPingWorkerService(
context = this,
guids = guidsList,
onEvent = { event -> handleWorkerEvent(event) { activeWorkers.remove(worker) } }
onEvent = { event -> handleWorkerEvent(event) { activeWorkers.remove(worker) } }
)
activeWorkers.add(worker)
worker.start()
@@ -114,10 +116,12 @@ class CoreTestService : Service() {
)
MessageUtil.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_NOTIFY, event.text)
}
is RealPingEvent.Result -> {
MmkvManager.encodeServerTestDelayMillis(event.guid, event.delayMillis)
MessageUtil.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_SUCCESS, event.guid)
}
is RealPingEvent.Finish -> {
MessageUtil.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_FINISH, event.status)
onWorkerDone()
@@ -20,10 +20,10 @@ import com.v2ray.ang.AppConfig.LOOPBACK
import com.v2ray.ang.BuildConfig
import com.v2ray.ang.contracts.ServiceControl
import com.v2ray.ang.contracts.Tun2SocksControl
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.NotificationManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.MyContextWrapper
import com.v2ray.ang.util.Utils
@@ -23,14 +23,13 @@ import okio.ByteString.Companion.toByteString
import org.json.JSONArray
import org.json.JSONObject
import java.io.EOFException
import java.net.URI
import java.net.SocketException
import java.net.URI
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
import kotlin.io.DEFAULT_BUFFER_SIZE
// This class is responsible for forwarding xray's HTTP/WS requests through okhttp,
// so that its TLS and traffic characteristics are okhttp instead of golang/utls.
@@ -66,6 +65,7 @@ class DialerNativeService : IDialerService {
@Volatile
private var serviceJob = SupervisorJob()
@Volatile
private var scope = CoroutineScope(serviceJob + Dispatchers.IO)
private val running = AtomicBoolean(false)
@@ -97,7 +97,8 @@ class DialerNativeService : IDialerService {
loopJob = scope.launch {
val resolvedControlUrl = resolveControlWsUrl(dialerAddr, nativeClient)
if (resolvedControlUrl == null) {
debug("BrowserDialer: failed to resolve control url from dialer endpoint: $dialerAddr"
debug(
"BrowserDialer: failed to resolve control url from dialer endpoint: $dialerAddr"
)
running.set(false)
return@launch
@@ -276,14 +277,16 @@ class DialerNativeService : IDialerService {
val status = response?.code?.toString() ?: "no-http-response"
val stateText = "${poolState()} accepted=${taskAccepted.get()} closed=${closed.get()}"
if (isExpectedControlFailure(t, status)) {
debug("BrowserDialer: control socket closed socketId=$socketId url=$controlUrl status=$status cause=${t.javaClass.simpleName} $stateText"
debug(
"BrowserDialer: control socket closed socketId=$socketId url=$controlUrl status=$status cause=${t.javaClass.simpleName} $stateText"
)
debug(
"BrowserDialer: control socket failure detail socketId=$socketId url=$controlUrl status=$status $stateText",
t
)
} else {
debug("BrowserDialer: control socket failure socketId=$socketId url=$controlUrl status=$status $stateText",
debug(
"BrowserDialer: control socket failure socketId=$socketId url=$controlUrl status=$status $stateText",
t
)
}
@@ -386,7 +389,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send("ok")
} catch (e: Exception) {
debug("BrowserDialer: failed to send ok for WS task",
debug(
"BrowserDialer: failed to send ok for WS task",
e
)
webSocket.close(1000, "control failed")
@@ -397,7 +401,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send(text)
} catch (e: Exception) {
debug("BrowserDialer: control socket closed during WS message transfer socketId=$socketId",
debug(
"BrowserDialer: control socket closed during WS message transfer socketId=$socketId",
e
)
webSocket.close(1000, "control closed")
@@ -408,7 +413,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send(bytes)
} catch (e: Exception) {
debug("BrowserDialer: control socket closed during WS binary transfer socketId=$socketId",
debug(
"BrowserDialer: control socket closed during WS binary transfer socketId=$socketId",
e
)
webSocket.close(1000, "control closed")
@@ -432,7 +438,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send("fail")
} catch (e: Exception) {
debug("BrowserDialer: control socket send failed socketId=$socketId",
debug(
"BrowserDialer: control socket send failed socketId=$socketId",
e
)
}
@@ -440,7 +447,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.close(1011, "upstream failure")
} catch (_: Exception) {
debug("BrowserDialer: control socket already closed socketId=$socketId"
debug(
"BrowserDialer: control socket already closed socketId=$socketId"
)
}
}
@@ -450,7 +458,8 @@ class DialerNativeService : IDialerService {
try {
upstreamSocket?.send(message)
} catch (e: Exception) {
debug("BrowserDialer: upstream socket send failed socketId=$socketId",
debug(
"BrowserDialer: upstream socket send failed socketId=$socketId",
e
)
}
@@ -459,7 +468,8 @@ class DialerNativeService : IDialerService {
try {
upstreamSocket?.send(data.toByteString())
} catch (e: Exception) {
debug("BrowserDialer: upstream socket binary send failed socketId=$socketId",
debug(
"BrowserDialer: upstream socket binary send failed socketId=$socketId",
e
)
}
@@ -477,7 +487,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send("ok")
} catch (e: Exception) {
debug("BrowserDialer: failed to send ok for streaming GET socketId=$socketId",
debug(
"BrowserDialer: failed to send ok for streaming GET socketId=$socketId",
e
)
return
@@ -499,7 +510,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send(buffer.readByteString())
} catch (e: Exception) {
debug("BrowserDialer: WebSocket send failed during streaming, stopping stream socketId=$socketId",
debug(
"BrowserDialer: WebSocket send failed during streaming, stopping stream socketId=$socketId",
e
)
break
@@ -511,7 +523,8 @@ class DialerNativeService : IDialerService {
}
}
} catch (e: Exception) {
debug("BrowserDialer: streaming GET failed socketId=$socketId",
debug(
"BrowserDialer: streaming GET failed socketId=$socketId",
e
)
try {
@@ -524,7 +537,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.close(1000, "streaming done")
} catch (_: Exception) {
debug("BrowserDialer: WebSocket already closed socketId=$socketId"
debug(
"BrowserDialer: WebSocket already closed socketId=$socketId"
)
}
}
@@ -541,7 +555,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send("ok")
} catch (e: Exception) {
debug("BrowserDialer: failed to send ok for unary task socketId=$socketId",
debug(
"BrowserDialer: failed to send ok for unary task socketId=$socketId",
e
)
return
@@ -574,13 +589,15 @@ class DialerNativeService : IDialerService {
try {
controlSocket.send(if (response.isSuccessful) "ok" else "fail")
} catch (e: Exception) {
debug("BrowserDialer: WebSocket send failed for unary response socketId=$socketId",
debug(
"BrowserDialer: WebSocket send failed for unary response socketId=$socketId",
e
)
}
}
} catch (e: Exception) {
debug("BrowserDialer: unary request failed socketId=$socketId",
debug(
"BrowserDialer: unary request failed socketId=$socketId",
e
)
try {
@@ -593,7 +610,8 @@ class DialerNativeService : IDialerService {
try {
controlSocket.close(1000, "request done")
} catch (_: Exception) {
debug("BrowserDialer: WebSocket already closed socketId=$socketId"
debug(
"BrowserDialer: WebSocket already closed socketId=$socketId"
)
}
}
@@ -1,10 +1,10 @@
package com.v2ray.ang.service
import android.content.Context
import com.v2ray.ang.core.CoreConfigManager
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.dto.RealPingEvent
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.core.CoreConfigManager
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
@@ -4,8 +4,8 @@ import android.os.Bundle
import com.v2ray.ang.AppConfig
import com.v2ray.ang.BuildConfig
import com.v2ray.ang.R
import com.v2ray.ang.databinding.ActivityAboutBinding
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.databinding.ActivityAboutBinding
import com.v2ray.ang.util.Utils
class AboutActivity : BaseActivity() {
@@ -14,7 +14,6 @@ import com.v2ray.ang.databinding.ActivityAppPickerBinding
import com.v2ray.ang.dto.AppInfo
import com.v2ray.ang.util.AppManagerUtil
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.PackageUidResolver
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -6,6 +6,7 @@ import androidx.lifecycle.lifecycleScope
import com.v2ray.ang.AppConfig
import com.v2ray.ang.BuildConfig
import com.v2ray.ang.R
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.databinding.ActivityCheckUpdateBinding
import com.v2ray.ang.dto.CheckUpdateResult
import com.v2ray.ang.extension.toast
@@ -13,7 +14,6 @@ import com.v2ray.ang.extension.toastError
import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.UpdateCheckerManager
import com.v2ray.ang.core.CoreNativeManager
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.Utils
import kotlinx.coroutines.launch
@@ -5,13 +5,13 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.activity.result.contract.ActivityResultContracts
import com.v2ray.ang.AppConfig
import com.v2ray.ang.R
import com.v2ray.ang.contracts.MainAdapterListener
@@ -24,10 +24,10 @@ import com.v2ray.ang.extension.toastError
import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.handler.AngConfigManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.helper.SimpleItemTouchHelperCallback
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.viewmodel.MainViewModel
import com.v2ray.ang.handler.SettingsChangeManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -22,6 +22,7 @@ import com.google.android.material.navigation.NavigationView
import com.google.android.material.tabs.TabLayoutMediator
import com.v2ray.ang.AppConfig
import com.v2ray.ang.R
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.databinding.ActivityMainBinding
import com.v2ray.ang.enums.EConfigType
import com.v2ray.ang.enums.PermissionType
@@ -32,7 +33,6 @@ import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.handler.SubscriptionUpdater
import com.v2ray.ang.core.CoreServiceManager
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.Utils
import com.v2ray.ang.viewmodel.MainViewModel
@@ -29,9 +29,9 @@ import com.v2ray.ang.extension.toast
import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.handler.AngConfigManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.util.JsonUtil
import com.v2ray.ang.util.Utils
import com.v2ray.ang.handler.SettingsChangeManager
class ServerActivity : BaseActivity() {
@@ -598,8 +598,7 @@ class ServerActivity : BaseActivity() {
} else {
profileItem.browserDialerMode = null
}
}
else {
} else {
profileItem.browserDialerMode = null
}
}
@@ -17,9 +17,9 @@ import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.fmt.CustomFmt
import com.v2ray.ang.handler.AngConfigManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.util.LogUtil
import com.v2ray.ang.util.Utils
import com.v2ray.ang.handler.SettingsChangeManager
class ServerCustomConfigActivity : BaseActivity() {
private val binding by lazy { ActivityServerCustomConfigBinding.inflate(layoutInflater) }
@@ -14,8 +14,8 @@ import com.v2ray.ang.extension.isNotNullEmpty
import com.v2ray.ang.extension.toast
import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.util.Utils
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.util.Utils
class ServerGroupActivity : BaseActivity() {
private val binding by lazy { ActivityServerGroupBinding.inflate(layoutInflater) }
@@ -15,11 +15,11 @@ import com.v2ray.ang.dto.ProfileItem
import com.v2ray.ang.enums.EConfigType
import com.v2ray.ang.extension.toast
import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.helper.SimpleItemTouchHelperCallback
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.util.Utils
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.helper.SimpleItemTouchHelperCallback
import com.v2ray.ang.util.Utils
class ServerProxyChainActivity : BaseActivity() {
private val binding by lazy { ActivityServerProxyChainBinding.inflate(layoutInflater) }
@@ -1,10 +1,10 @@
package com.v2ray.ang.ui
import android.graphics.Color
import android.widget.ArrayAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.recyclerview.widget.RecyclerView
import com.v2ray.ang.contracts.BaseAdapterListener
import com.v2ray.ang.databinding.ItemRecyclerProxyChainMemberBinding
@@ -3,6 +3,9 @@ package com.v2ray.ang.util
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.LOOPBACK
import com.v2ray.ang.BuildConfig
import okhttp3.Credentials
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.File
import java.io.IOException
import java.net.IDN
@@ -14,9 +17,6 @@ import java.net.Proxy
import java.net.URI
import java.net.URL
import java.util.concurrent.TimeUnit
import okhttp3.Credentials
import okhttp3.OkHttpClient
import okhttp3.Request
object HttpUtil {
@@ -33,7 +33,7 @@ object PackageUidResolver {
private fun resolveUid(context: Context, packageName: String): String? {
// Special token for connections whose UID cannot be resolved (mapped to -1)
if (packageName == AppConfig.UNIDENTIFIED_PACKAGE) {
val uid = "-1"
val uid = "-1"
LogUtil.d(AppConfig.TAG, "Special package: $packageName -> UID: $uid")
return uid
}
@@ -19,7 +19,6 @@ import com.v2ray.ang.dto.SubscriptionCache
import com.v2ray.ang.dto.SubscriptionUpdateResult
import com.v2ray.ang.dto.TestServiceMessage
import com.v2ray.ang.extension.matchesPattern
import com.v2ray.ang.extension.serializable
import com.v2ray.ang.extension.toastError
import com.v2ray.ang.extension.toastSuccess
import com.v2ray.ang.handler.AngConfigManager
@@ -476,7 +475,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
AppConfig.MSG_MEASURE_CONFIG_SUCCESS -> {
val content = intent.getStringExtra("content")
updateListAction.value = getPosition(content?: "")
updateListAction.value = getPosition(content ?: "")
}
AppConfig.MSG_MEASURE_CONFIG_NOTIFY -> {