Optimize and improve Log
This commit is contained in:
@@ -33,7 +33,7 @@ object VmessFmt : FmtBase() {
|
||||
var result = str.replace(EConfigType.VMESS.protocolScheme, "")
|
||||
result = Utils.decode(result)
|
||||
if (TextUtils.isEmpty(result)) {
|
||||
Log.d(AppConfig.TAG, "R.string.toast_decoding_failed")
|
||||
Log.w(AppConfig.TAG, "Toast decoding failed")
|
||||
return null
|
||||
}
|
||||
val vmessQRCode = JsonUtil.fromJson(result, VmessQRCode::class.java)
|
||||
@@ -43,7 +43,7 @@ object VmessFmt : FmtBase() {
|
||||
|| TextUtils.isEmpty(vmessQRCode.id)
|
||||
|| TextUtils.isEmpty(vmessQRCode.net)
|
||||
) {
|
||||
Log.d(AppConfig.TAG, "R.string.toast_incorrect_protocol")
|
||||
Log.w(AppConfig.TAG, "Toast incorrect protocol")
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -417,13 +417,13 @@ object AngConfigManager {
|
||||
if (!Utils.isValidUrl(url)) {
|
||||
return 0
|
||||
}
|
||||
Log.d(AppConfig.TAG, url)
|
||||
Log.i(AppConfig.TAG, url)
|
||||
|
||||
var configText = try {
|
||||
val httpPort = SettingsManager.getHttpPort()
|
||||
HttpUtil.getUrlContentWithUserAgent(url, 15000, httpPort)
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.ANG_PACKAGE, "Update subscription: proxy not ready or other error, try……", e)
|
||||
Log.e(AppConfig.ANG_PACKAGE, "Update subscription: proxy not ready or other error", e)
|
||||
""
|
||||
}
|
||||
if (configText.isEmpty()) {
|
||||
|
||||
@@ -25,7 +25,7 @@ object MigrateManager {
|
||||
return false
|
||||
}
|
||||
val serverList = serverStorage.allKeys() ?: return false
|
||||
Log.d(AppConfig.TAG, "migrateServerConfig2Profile-" + serverList.count())
|
||||
Log.i(AppConfig.TAG, "migrateServerConfig2Profile-" + serverList.count())
|
||||
|
||||
for (guid in serverList) {
|
||||
var configOld = decodeServerConfigOld(guid) ?: continue
|
||||
@@ -42,9 +42,9 @@ object MigrateManager {
|
||||
//check and remove old
|
||||
decodeServerConfig(guid) ?: continue
|
||||
serverStorage.remove(guid)
|
||||
Log.d(AppConfig.TAG, "migrateServerConfig2Profile-" + config.remarks)
|
||||
Log.i(AppConfig.TAG, "migrateServerConfig2Profile-" + config.remarks)
|
||||
}
|
||||
Log.d(AppConfig.TAG, "migrateServerConfig2Profile-end")
|
||||
Log.i(AppConfig.TAG, "migrateServerConfig2Profile-end")
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ object SettingsManager {
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
Log.d(AppConfig.TAG, "Copied from apk assets folder to ${target.absolutePath}")
|
||||
Log.i(AppConfig.TAG, "Copied from apk assets folder to ${target.absolutePath}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(ANG_PACKAGE, "asset copy failed", e)
|
||||
|
||||
@@ -51,7 +51,7 @@ object SpeedtestManager {
|
||||
return try {
|
||||
Libv2ray.measureOutboundDelay(config, SettingsManager.getDelayTestUrl())
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, "realPing: $e")
|
||||
Log.e(AppConfig.TAG, "Failed to measure outbound delay", e)
|
||||
-1L
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ object SpeedtestManager {
|
||||
} catch (e: UnknownHostException) {
|
||||
Log.e(AppConfig.TAG, "Unknown host: $url", e)
|
||||
} catch (e: IOException) {
|
||||
Log.d(AppConfig.TAG, "socketConnectTime IOException: $e")
|
||||
Log.e(AppConfig.TAG, "socketConnectTime IOException: $e")
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to establish socket connection to $url:$port", e)
|
||||
}
|
||||
@@ -152,10 +152,10 @@ object SpeedtestManager {
|
||||
)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.d(AppConfig.TAG, "testConnection IOException: " + Log.getStackTraceString(e))
|
||||
Log.e(AppConfig.TAG, "Connection test IOException", e)
|
||||
result = context.getString(R.string.connection_test_error, e.message)
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, "testConnection Exception: " + Log.getStackTraceString(e))
|
||||
Log.e(AppConfig.TAG, "Connection test Exception", e)
|
||||
result = context.getString(R.string.connection_test_error, e.message)
|
||||
} finally {
|
||||
conn.disconnect()
|
||||
|
||||
@@ -122,7 +122,7 @@ object V2rayConfigManager {
|
||||
val address = config.server ?: return result
|
||||
if (!Utils.isIpAddress(address)) {
|
||||
if (!Utils.isValidUrl(address)) {
|
||||
Log.d(AppConfig.TAG, "$address is an invalid ip or domain")
|
||||
Log.w(AppConfig.TAG, "$address is an invalid ip or domain")
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ object V2rayConfigManager {
|
||||
val address = config.server ?: return result
|
||||
if (!Utils.isIpAddress(address)) {
|
||||
if (!Utils.isValidUrl(address)) {
|
||||
Log.d(AppConfig.TAG, "$address is an invalid ip or domain")
|
||||
Log.w(AppConfig.TAG, "$address is an invalid ip or domain")
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class ProcessService {
|
||||
* @param cmd The command to run.
|
||||
*/
|
||||
fun runProcess(context: Context, cmd: MutableList<String>) {
|
||||
Log.d(AppConfig.TAG, cmd.toString())
|
||||
Log.i(AppConfig.TAG, cmd.toString())
|
||||
|
||||
try {
|
||||
val proBuilder = ProcessBuilder(cmd)
|
||||
@@ -27,14 +27,14 @@ class ProcessService {
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
Thread.sleep(50L)
|
||||
Log.d(AppConfig.TAG, "runProcess check")
|
||||
Log.i(AppConfig.TAG, "runProcess check")
|
||||
process?.waitFor()
|
||||
Log.d(AppConfig.TAG, "runProcess exited")
|
||||
Log.i(AppConfig.TAG, "runProcess exited")
|
||||
}
|
||||
Log.d(AppConfig.TAG, process.toString())
|
||||
Log.i(AppConfig.TAG, process.toString())
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, e.toString(), e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class ProcessService {
|
||||
*/
|
||||
fun stopProcess() {
|
||||
try {
|
||||
Log.d(AppConfig.TAG, "runProcess destroy")
|
||||
Log.i(AppConfig.TAG, "runProcess destroy")
|
||||
process?.destroy()
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to destroy process", e)
|
||||
|
||||
@@ -38,7 +38,7 @@ object SubscriptionUpdater {
|
||||
*/
|
||||
@SuppressLint("MissingPermission")
|
||||
override suspend fun doWork(): Result {
|
||||
Log.d(AppConfig.TAG, "subscription automatic update starting")
|
||||
Log.i(AppConfig.TAG, "subscription automatic update starting")
|
||||
|
||||
val subs = MmkvManager.decodeSubscriptions().filter { it.second.autoUpdate }
|
||||
|
||||
@@ -56,7 +56,7 @@ object SubscriptionUpdater {
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
notificationManager.notify(3, notification.build())
|
||||
Log.d(AppConfig.TAG, "subscription automatic update: ---${subItem.remarks}")
|
||||
Log.i(AppConfig.TAG, "subscription automatic update: ---${subItem.remarks}")
|
||||
updateConfigViaSub(Pair(sub.first, subItem))
|
||||
notification.setContentText("Updating ${subItem.remarks}")
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ object V2RayServiceManager {
|
||||
mFilter.addAction(Intent.ACTION_USER_PRESENT)
|
||||
ContextCompat.registerReceiver(service, mMsgReceive, mFilter, Utils.receiverFlags())
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to register broadcast receiver", e)
|
||||
}
|
||||
|
||||
v2rayPoint.configureFileContent = result.content
|
||||
@@ -153,7 +153,7 @@ object V2RayServiceManager {
|
||||
try {
|
||||
v2rayPoint.runLoop(MmkvManager.decodeSettingsBool(AppConfig.PREF_PREFER_IPV6))
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to start V2Ray loop", e)
|
||||
}
|
||||
|
||||
if (v2rayPoint.isRunning) {
|
||||
@@ -178,7 +178,7 @@ object V2RayServiceManager {
|
||||
try {
|
||||
v2rayPoint.stopLoop()
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to stop V2Ray loop", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ object V2RayServiceManager {
|
||||
try {
|
||||
service.unregisterReceiver(mMsgReceive)
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to unregister broadcast receiver", e)
|
||||
}
|
||||
PluginUtil.stopPlugin()
|
||||
}
|
||||
@@ -216,14 +216,14 @@ object V2RayServiceManager {
|
||||
try {
|
||||
time = v2rayPoint.measureDelay(SettingsManager.getDelayTestUrl())
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, "measureV2rayDelay: $e")
|
||||
Log.e(AppConfig.TAG, "Failed to measure delay with primary URL", e)
|
||||
errstr = e.message?.substringAfter("\":") ?: "empty message"
|
||||
}
|
||||
if (time == -1L) {
|
||||
try {
|
||||
time = v2rayPoint.measureDelay(SettingsManager.getDelayTestUrl(true))
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, "measureV2rayDelay: $e")
|
||||
Log.e(AppConfig.TAG, "Failed to measure delay with alternative URL", e)
|
||||
errstr = e.message?.substringAfter("\":") ?: "empty message"
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ object V2RayServiceManager {
|
||||
serviceControl.stopService()
|
||||
0
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to stop service in callback", e)
|
||||
-1
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ object V2RayServiceManager {
|
||||
NotificationService.startSpeedNotification(currentConfig)
|
||||
0
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to setup service in callback", e)
|
||||
-1
|
||||
}
|
||||
}
|
||||
@@ -322,12 +322,12 @@ object V2RayServiceManager {
|
||||
}
|
||||
|
||||
AppConfig.MSG_STATE_STOP -> {
|
||||
Log.d(AppConfig.TAG, "Stop Service")
|
||||
Log.i(AppConfig.TAG, "Stop Service")
|
||||
serviceControl.stopService()
|
||||
}
|
||||
|
||||
AppConfig.MSG_STATE_RESTART -> {
|
||||
Log.d(AppConfig.TAG, "Restart Service")
|
||||
Log.i(AppConfig.TAG, "Restart Service")
|
||||
serviceControl.stopService()
|
||||
Thread.sleep(500L)
|
||||
startVService(serviceControl.getService())
|
||||
@@ -340,12 +340,12 @@ object V2RayServiceManager {
|
||||
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_SCREEN_OFF -> {
|
||||
Log.d(AppConfig.TAG, "SCREEN_OFF, stop querying stats")
|
||||
Log.i(AppConfig.TAG, "SCREEN_OFF, stop querying stats")
|
||||
NotificationService.stopSpeedNotification(currentConfig)
|
||||
}
|
||||
|
||||
Intent.ACTION_SCREEN_ON -> {
|
||||
Log.d(AppConfig.TAG, "SCREEN_ON, start querying stats")
|
||||
Log.i(AppConfig.TAG, "SCREEN_ON, start querying stats")
|
||||
NotificationService.startSpeedNotification(currentConfig)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
else
|
||||
builder.addAllowedApplication(it)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
Log.d(AppConfig.TAG, "setup error : --${e.localizedMessage}")
|
||||
Log.e(AppConfig.TAG, "Failed to configure app in VPN: ${e.localizedMessage}", e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -277,7 +277,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
cmd.add("--dnsgw")
|
||||
cmd.add("$LOOPBACK:${localDnsPort}")
|
||||
}
|
||||
Log.d(AppConfig.TAG, cmd.toString())
|
||||
Log.i(AppConfig.TAG, cmd.toString())
|
||||
|
||||
try {
|
||||
val proBuilder = ProcessBuilder(cmd)
|
||||
@@ -286,19 +286,19 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
.directory(applicationContext.filesDir)
|
||||
.start()
|
||||
Thread {
|
||||
Log.d(AppConfig.TAG, "$TUN2SOCKS check")
|
||||
Log.i(AppConfig.TAG, "$TUN2SOCKS check")
|
||||
process.waitFor()
|
||||
Log.d(AppConfig.TAG, "$TUN2SOCKS exited")
|
||||
Log.i(AppConfig.TAG, "$TUN2SOCKS exited")
|
||||
if (isRunning) {
|
||||
Log.d(AppConfig.TAG, "$TUN2SOCKS restart")
|
||||
Log.i(AppConfig.TAG, "$TUN2SOCKS restart")
|
||||
runTun2socks()
|
||||
}
|
||||
}.start()
|
||||
Log.d(AppConfig.TAG, process.toString())
|
||||
Log.i(AppConfig.TAG, process.toString())
|
||||
|
||||
sendFd()
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to start tun2socks process", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,13 +309,13 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
private fun sendFd() {
|
||||
val fd = mInterface.fileDescriptor
|
||||
val path = File(applicationContext.filesDir, "sock_path").absolutePath
|
||||
Log.d(AppConfig.TAG, path)
|
||||
Log.i(AppConfig.TAG, path)
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
var tries = 0
|
||||
while (true) try {
|
||||
Thread.sleep(50L shl tries)
|
||||
Log.d(AppConfig.TAG, "sendFd tries: $tries")
|
||||
Log.i(AppConfig.TAG, "sendFd tries: $tries")
|
||||
LocalSocket().use { localSocket ->
|
||||
localSocket.connect(LocalSocketAddress(path, LocalSocketAddress.Namespace.FILESYSTEM))
|
||||
localSocket.setFileDescriptorsForSend(arrayOf(fd))
|
||||
@@ -323,7 +323,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
}
|
||||
break
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to send file descriptor, try: $tries", e)
|
||||
if (tries > 5) break
|
||||
tries += 1
|
||||
}
|
||||
@@ -349,10 +349,10 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
}
|
||||
|
||||
try {
|
||||
Log.d(AppConfig.TAG, "tun2socks destroy")
|
||||
Log.i(AppConfig.TAG, "tun2socks destroy")
|
||||
process.destroy()
|
||||
} catch (e: Exception) {
|
||||
Log.d(AppConfig.TAG, e.toString())
|
||||
Log.e(AppConfig.TAG, "Failed to destroy tun2socks process", e)
|
||||
}
|
||||
|
||||
V2RayServiceManager.stopV2rayPoint()
|
||||
@@ -367,8 +367,8 @@ class V2RayVpnService : VpnService(), ServiceControl {
|
||||
|
||||
try {
|
||||
mInterface.close()
|
||||
} catch (ignored: Exception) {
|
||||
// ignored
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to close VPN interface", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class LogcatRecyclerAdapter(val activity: LogcatActivity) : RecyclerView.Adapter
|
||||
holder.itemSubSettingBinding.logContent.text = if (content.count() > 1) content.last().trim() else ""
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Error binding log data", e)
|
||||
Log.e(AppConfig.TAG, "Error binding log view data", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -521,6 +521,9 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* import config from local config file
|
||||
*/
|
||||
private fun importConfigLocal(): Boolean {
|
||||
try {
|
||||
showFileChooser()
|
||||
|
||||
@@ -188,7 +188,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter<Mai
|
||||
else -> mActivity.toast("else")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Error occurred while sharing server information", e)
|
||||
Log.e(AppConfig.TAG, "Error when sharing server", e)
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
content = HttpUtil.getUrlContent(url, 5000, httpPort) ?: ""
|
||||
}
|
||||
launch(Dispatchers.Main) {
|
||||
Log.d(AppConfig.TAG, content)
|
||||
Log.i(AppConfig.TAG, content)
|
||||
selectProxyApp(content, true)
|
||||
toastSuccess(R.string.toast_success)
|
||||
binding.pbWaiting.hide()
|
||||
@@ -206,7 +206,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
adapter?.let { it ->
|
||||
it.apps.forEach block@{
|
||||
val packageName = it.packageName
|
||||
Log.d(AppConfig.TAG, packageName)
|
||||
Log.i(AppConfig.TAG, packageName)
|
||||
if (!inProxyApps(proxyApps, packageName, force)) {
|
||||
adapter?.blacklist?.add(packageName)
|
||||
println(packageName)
|
||||
@@ -219,7 +219,7 @@ class PerAppProxyActivity : BaseActivity() {
|
||||
adapter?.let { it ->
|
||||
it.apps.forEach block@{
|
||||
val packageName = it.packageName
|
||||
Log.d(AppConfig.TAG, packageName)
|
||||
Log.i(AppConfig.TAG, packageName)
|
||||
if (inProxyApps(proxyApps, packageName, force)) {
|
||||
adapter?.blacklist?.add(packageName)
|
||||
println(packageName)
|
||||
|
||||
@@ -480,7 +480,7 @@ class ServerActivity : BaseActivity() {
|
||||
if (config.subscriptionId.isEmpty() && !subscriptionId.isNullOrEmpty()) {
|
||||
config.subscriptionId = subscriptionId.orEmpty()
|
||||
}
|
||||
//Log.d(AppConfig.TAG, JsonUtil.toJsonPretty(config) ?: "")
|
||||
//Log.i(AppConfig.TAG, JsonUtil.toJsonPretty(config) ?: "")
|
||||
MmkvManager.encodeServerConfig(editGuid, config)
|
||||
toastSuccess(R.string.toast_success)
|
||||
finish()
|
||||
|
||||
@@ -63,7 +63,7 @@ class UrlSchemeActivity : BaseActivity() {
|
||||
if (uriString.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
Log.d(AppConfig.TAG, uriString)
|
||||
Log.i(AppConfig.TAG, uriString)
|
||||
|
||||
var decodedUrl = URLDecoder.decode(uriString, "UTF-8")
|
||||
val uri = Uri.parse(decodedUrl)
|
||||
@@ -71,7 +71,7 @@ class UrlSchemeActivity : BaseActivity() {
|
||||
if (uri.fragment.isNullOrEmpty() && !fragment.isNullOrEmpty()) {
|
||||
decodedUrl += "#${fragment}"
|
||||
}
|
||||
Log.d(AppConfig.TAG, decodedUrl)
|
||||
Log.i(AppConfig.TAG, decodedUrl)
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val (count, countSub) = AngConfigManager.importBatchConfig(decodedUrl, "", false)
|
||||
withContext(Dispatchers.Main) {
|
||||
|
||||
@@ -191,7 +191,7 @@ class UserAssetActivity : BaseActivity() {
|
||||
.putExtra(UserAssetUrlActivity.ASSET_URL_QRCODE, url)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to import asset", e)
|
||||
Log.e(AppConfig.TAG, "Failed to import asset from URL", e)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -208,12 +208,16 @@ class UserAssetActivity : BaseActivity() {
|
||||
var resultCount = 0
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
assets.forEach {
|
||||
var result = downloadGeo(it.second, 15000, httpPort)
|
||||
if (!result) {
|
||||
result = downloadGeo(it.second, 15000, 0)
|
||||
try {
|
||||
var result = downloadGeo(it.second, 15000, httpPort)
|
||||
if (!result) {
|
||||
result = downloadGeo(it.second, 15000, 0)
|
||||
}
|
||||
if (result)
|
||||
resultCount++
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to download geo file: ${it.second.remarks}", e)
|
||||
}
|
||||
if (result)
|
||||
resultCount++
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
if (resultCount > 0) {
|
||||
@@ -230,7 +234,7 @@ class UserAssetActivity : BaseActivity() {
|
||||
private fun downloadGeo(item: AssetUrlItem, timeout: Int, httpPort: Int): Boolean {
|
||||
val targetTemp = File(extDir, item.remarks + "_temp")
|
||||
val target = File(extDir, item.remarks)
|
||||
//Log.d(AppConfig.TAG, url)
|
||||
Log.i(AppConfig.TAG, "Downloading geo file: ${item.remarks} from ${item.url}")
|
||||
|
||||
val conn = HttpUtil.createProxyConnection(item.url, httpPort, timeout, timeout, needStream = true) ?: return false
|
||||
try {
|
||||
@@ -245,7 +249,7 @@ class UserAssetActivity : BaseActivity() {
|
||||
}
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to download geo file", e)
|
||||
Log.e(AppConfig.TAG, "Failed to download geo file: ${item.remarks}", e)
|
||||
return false
|
||||
} finally {
|
||||
conn.disconnect()
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.v2ray.ang.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.v2ray.ang.AppConfig
|
||||
import com.v2ray.ang.R
|
||||
import com.v2ray.ang.databinding.ActivityUserAssetUrlBinding
|
||||
import com.v2ray.ang.dto.AssetUrlItem
|
||||
@@ -75,7 +77,11 @@ class UserAssetUrlActivity : BaseActivity() {
|
||||
// remove file associated with the asset
|
||||
val file = extDir.resolve(assetItem.remarks)
|
||||
if (file.exists()) {
|
||||
file.delete()
|
||||
try {
|
||||
file.delete()
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to delete asset file: ${file.path}", e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assetId = Utils.getUuid()
|
||||
|
||||
@@ -69,7 +69,7 @@ object MessageUtil {
|
||||
intent.putExtra("content", content)
|
||||
ctx.sendBroadcast(intent)
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to send broadcast message", e)
|
||||
Log.e(AppConfig.TAG, "Failed to send message with action: $action", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,13 +26,23 @@ object PluginUtil {
|
||||
* @param domainPort The domain and port information.
|
||||
*/
|
||||
fun runPlugin(context: Context, config: ProfileItem?, domainPort: String?) {
|
||||
Log.d(AppConfig.TAG, "runPlugin")
|
||||
Log.i(AppConfig.TAG, "Starting plugin execution")
|
||||
|
||||
if (config?.configType?.equals(EConfigType.HYSTERIA2) == true) {
|
||||
val configFile = genConfigHy2(context, config, domainPort) ?: return
|
||||
val cmd = genCmdHy2(context, configFile)
|
||||
if (config == null) {
|
||||
Log.w(AppConfig.TAG, "Cannot run plugin: config is null")
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (config.configType == EConfigType.HYSTERIA2) {
|
||||
Log.i(AppConfig.TAG, "Running Hysteria2 plugin")
|
||||
val configFile = genConfigHy2(context, config, domainPort) ?: return
|
||||
val cmd = genCmdHy2(context, configFile)
|
||||
|
||||
procService.runProcess(context, cmd)
|
||||
procService.runProcess(context, cmd)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Error running plugin", e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +61,7 @@ object PluginUtil {
|
||||
* @return The ping delay in milliseconds, or -1 if it fails.
|
||||
*/
|
||||
fun realPingHy2(context: Context, config: ProfileItem?): Long {
|
||||
Log.d(AppConfig.TAG, "realPingHy2")
|
||||
Log.i(AppConfig.TAG, "realPingHy2")
|
||||
val retFailure = -1L
|
||||
|
||||
if (config?.configType?.equals(EConfigType.HYSTERIA2) == true) {
|
||||
@@ -79,18 +89,18 @@ object PluginUtil {
|
||||
* @return The generated configuration file.
|
||||
*/
|
||||
private fun genConfigHy2(context: Context, config: ProfileItem, domainPort: String?): File? {
|
||||
Log.d(AppConfig.TAG, "runPlugin $HYSTERIA2")
|
||||
Log.i(AppConfig.TAG, "runPlugin $HYSTERIA2")
|
||||
|
||||
val socksPort = domainPort?.split(":")?.last()
|
||||
.let { if (it.isNullOrEmpty()) return null else it.toInt() }
|
||||
val hy2Config = Hysteria2Fmt.toNativeConfig(config, socksPort) ?: return null
|
||||
|
||||
val configFile = File(context.noBackupFilesDir, "hy2_${SystemClock.elapsedRealtime()}.json")
|
||||
Log.d(AppConfig.TAG, "runPlugin ${configFile.absolutePath}")
|
||||
Log.i(AppConfig.TAG, "runPlugin ${configFile.absolutePath}")
|
||||
|
||||
configFile.parentFile?.mkdirs()
|
||||
configFile.writeText(JsonUtil.toJson(hy2Config))
|
||||
Log.d(AppConfig.TAG, JsonUtil.toJson(hy2Config))
|
||||
Log.i(AppConfig.TAG, JsonUtil.toJson(hy2Config))
|
||||
|
||||
return configFile
|
||||
}
|
||||
@@ -119,7 +129,7 @@ object PluginUtil {
|
||||
*/
|
||||
private fun stopHy2() {
|
||||
try {
|
||||
Log.d(AppConfig.TAG, "$HYSTERIA2 destroy")
|
||||
Log.i(AppConfig.TAG, "$HYSTERIA2 destroy")
|
||||
procService?.stopProcess()
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to stop Hysteria2 process", e)
|
||||
|
||||
@@ -62,7 +62,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
getApplication<AngApplication>().unregisterReceiver(mMsgReceiver)
|
||||
tcpingTestScope.coroutineContext[Job]?.cancelChildren()
|
||||
SpeedtestManager.closeAllTcpSockets()
|
||||
Log.d(AppConfig.TAG, "Main ViewModel is cleared")
|
||||
Log.i(AppConfig.TAG, "Main ViewModel is cleared")
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
||||
override fun onCleared() {
|
||||
PreferenceManager.getDefaultSharedPreferences(getApplication())
|
||||
.unregisterOnSharedPreferenceChangeListener(this)
|
||||
Log.d(AppConfig.TAG, "Settings ViewModel is cleared")
|
||||
Log.i(AppConfig.TAG, "Settings ViewModel is cleared")
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
||||
* @param key The key of the changed preference.
|
||||
*/
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
|
||||
Log.d(AppConfig.TAG, "Observe settings changed: $key")
|
||||
Log.i(AppConfig.TAG, "Observe settings changed: $key")
|
||||
when (key) {
|
||||
AppConfig.PREF_MODE,
|
||||
AppConfig.PREF_VPN_DNS,
|
||||
|
||||
Reference in New Issue
Block a user