diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/AppConfig.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/AppConfig.kt index 8f18da40..7613c318 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/AppConfig.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/AppConfig.kt @@ -5,6 +5,7 @@ object AppConfig { /** The application's package name. */ const val ANG_PACKAGE = BuildConfig.APPLICATION_ID + const val TAG = BuildConfig.APPLICATION_ID /** Directory names used in the app's file system. */ const val DIR_ASSETS = "assets" diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/ShadowsocksFmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/ShadowsocksFmt.kt index d32eeef7..fb383d25 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/ShadowsocksFmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/ShadowsocksFmt.kt @@ -1,5 +1,7 @@ package com.v2ray.ang.fmt +import android.util.Log +import com.v2ray.ang.AppConfig import com.v2ray.ang.dto.EConfigType import com.v2ray.ang.dto.NetworkType import com.v2ray.ang.dto.ProfileItem @@ -82,7 +84,7 @@ object ShadowsocksFmt : FmtBase() { config.remarks = Utils.urlDecode(result.substring(indexSplit + 1, result.length)) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to decode remarks in SS legacy URL", e) } result = result.substring(0, indexSplit) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt index b1a51979..c5ec4b12 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt @@ -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.ANG_PACKAGE, "R.string.toast_decoding_failed") + Log.d(AppConfig.TAG, "R.string.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.ANG_PACKAGE, "R.string.toast_incorrect_protocol") + Log.d(AppConfig.TAG, "R.string.toast_incorrect_protocol") return null } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt index 13bba449..2d520dde 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/AngConfigManager.kt @@ -42,7 +42,7 @@ object AngConfigManager { Utils.setClipboard(context, conf) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to share config to clipboard", e) return -1 } return 0 @@ -71,7 +71,7 @@ object AngConfigManager { } return sb.lines().count() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to share non-custom configs to clipboard", e) return -1 } } @@ -91,7 +91,7 @@ object AngConfigManager { return QRCodeDecoder.createQRCode(conf) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to share config as QR code", e) return null } } @@ -120,7 +120,7 @@ object AngConfigManager { return -1 } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to share full content to clipboard", e) return -1 } return 0 @@ -148,7 +148,7 @@ object AngConfigManager { EConfigType.HYSTERIA2 -> Hysteria2Fmt.toUri(config) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to share config for GUID: $guid", e) return "" } } @@ -203,7 +203,7 @@ object AngConfigManager { } return count } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse batch subscription", e) } return 0 } @@ -251,7 +251,7 @@ object AngConfigManager { } return count } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse batch config", e) } return 0 } @@ -287,7 +287,7 @@ object AngConfigManager { return count } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse custom config server JSON array", e) } try { @@ -298,7 +298,7 @@ object AngConfigManager { MmkvManager.encodeServerRaw(key, server) return 1 } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse custom config server as single config", e) } return 0 } else if (server.startsWith("[Interface]") && server.contains("[Peer]")) { @@ -308,7 +308,7 @@ object AngConfigManager { MmkvManager.encodeServerRaw(key, server) return 1 } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse WireGuard config file", e) } return 0 } else { @@ -372,7 +372,7 @@ object AngConfigManager { MmkvManager.setSelectServer(guid) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse config", e) return -1 } return 0 @@ -390,7 +390,7 @@ object AngConfigManager { count += updateConfigViaSub(it) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to update config via all subscriptions", e) return 0 } return count @@ -417,21 +417,20 @@ object AngConfigManager { if (!Utils.isValidUrl(url)) { return 0 } - Log.d(AppConfig.ANG_PACKAGE, url) + Log.d(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.printStackTrace() + Log.e(AppConfig.ANG_PACKAGE, "Update subscription: proxy not ready or other error, try……", e) "" } if (configText.isEmpty()) { configText = try { HttpUtil.getUrlContentWithUserAgent(url) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to get URL content with user agent", e) "" } } @@ -440,7 +439,7 @@ object AngConfigManager { } return parseConfigViaSub(configText, it.first, false) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to update config via subscription", e) return 0 } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MigrateManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MigrateManager.kt index ce1f2534..5687c8c9 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MigrateManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MigrateManager.kt @@ -3,7 +3,6 @@ package com.v2ray.ang.handler import android.util.Log import com.tencent.mmkv.MMKV import com.v2ray.ang.AppConfig -import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.dto.EConfigType import com.v2ray.ang.dto.NetworkType import com.v2ray.ang.dto.ProfileItem @@ -26,7 +25,7 @@ object MigrateManager { return false } val serverList = serverStorage.allKeys() ?: return false - Log.d(ANG_PACKAGE, "migrateServerConfig2Profile-" + serverList.count()) + Log.d(AppConfig.TAG, "migrateServerConfig2Profile-" + serverList.count()) for (guid in serverList) { var configOld = decodeServerConfigOld(guid) ?: continue @@ -43,9 +42,9 @@ object MigrateManager { //check and remove old decodeServerConfig(guid) ?: continue serverStorage.remove(guid) - Log.d(ANG_PACKAGE, "migrateServerConfig2Profile-" + config.remarks) + Log.d(AppConfig.TAG, "migrateServerConfig2Profile-" + config.remarks) } - Log.d(ANG_PACKAGE, "migrateServerConfig2Profile-end") + Log.d(AppConfig.TAG, "migrateServerConfig2Profile-end") return true } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt index 3c489ddc..9b589dd0 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt @@ -571,7 +571,7 @@ object MmkvManager { * @param startOnBoot Whether to start on boot. */ fun encodeStartOnBoot(startOnBoot: Boolean) { - MmkvManager.encodeSettings(PREF_IS_BOOTED, startOnBoot) + encodeSettings(PREF_IS_BOOTED, startOnBoot) } /** diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SettingsManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SettingsManager.kt index cb9256a0..ebcdd718 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SettingsManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SettingsManager.kt @@ -84,7 +84,7 @@ object SettingsManager { resetRoutingRulesetsCommon(rulesetList) return true } catch (e: Exception) { - e.printStackTrace() + Log.e(ANG_PACKAGE, "Failed to reset routing rulesets", e) return false } } @@ -167,11 +167,11 @@ object SettingsManager { } val guid = MmkvManager.getSelectServer() ?: return false - val config = MmkvManager.decodeServerConfig(guid) ?: return false + val config = decodeServerConfig(guid) ?: return false if (config.configType == EConfigType.CUSTOM) { val raw = MmkvManager.decodeServerRaw(guid) ?: return false val v2rayConfig = JsonUtil.fromJson(raw, V2rayConfig::class.java) - val exist = v2rayConfig.routing.rules.filter { it.outboundTag == TAG_DIRECT }?.any { + val exist = v2rayConfig.routing.rules.filter { it.outboundTag == TAG_DIRECT }.any { it.domain?.contains(GEOSITE_PRIVATE) == true || it.ip?.contains(GEOIP_PRIVATE) == true } return exist == true @@ -265,10 +265,7 @@ object SettingsManager { input.copyTo(output) } } - Log.i( - ANG_PACKAGE, - "Copied from apk assets folder to ${target.absolutePath}" - ) + Log.d(AppConfig.TAG, "Copied from apk assets folder to ${target.absolutePath}") } } catch (e: Exception) { Log.e(ANG_PACKAGE, "asset copy failed", e) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SpeedtestManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SpeedtestManager.kt index d607f0e5..dd85950f 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SpeedtestManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SpeedtestManager.kt @@ -51,7 +51,7 @@ object SpeedtestManager { return try { Libv2ray.measureOutboundDelay(config, SettingsManager.getDelayTestUrl()) } catch (e: Exception) { - Log.d(AppConfig.ANG_PACKAGE, "realPing: $e") + Log.d(AppConfig.TAG, "realPing: $e") -1L } } @@ -76,7 +76,7 @@ object SpeedtestManager { } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to ping URL: $url", e) } return "-1ms" } @@ -103,11 +103,11 @@ object SpeedtestManager { socket.close() return time } catch (e: UnknownHostException) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Unknown host: $url", e) } catch (e: IOException) { - Log.d(AppConfig.ANG_PACKAGE, "socketConnectTime IOException: $e") + Log.d(AppConfig.TAG, "socketConnectTime IOException: $e") } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to establish socket connection to $url:$port", e) } return -1 } @@ -152,13 +152,13 @@ object SpeedtestManager { ) } } catch (e: IOException) { - Log.d(AppConfig.ANG_PACKAGE, "testConnection IOException: " + Log.getStackTraceString(e)) + Log.d(AppConfig.TAG, "testConnection IOException: " + Log.getStackTraceString(e)) result = context.getString(R.string.connection_test_error, e.message) } catch (e: Exception) { - Log.d(AppConfig.ANG_PACKAGE, "testConnection Exception: " + Log.getStackTraceString(e)) + Log.d(AppConfig.TAG, "testConnection Exception: " + Log.getStackTraceString(e)) result = context.getString(R.string.connection_test_error, e.message) } finally { - conn?.disconnect() + conn.disconnect() } return Pair(elapsed, result) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt index f4818584..c808515f 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/V2rayConfigManager.kt @@ -4,7 +4,6 @@ import android.content.Context import android.text.TextUtils import android.util.Log import com.v2ray.ang.AppConfig -import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.AppConfig.DEFAULT_NETWORK import com.v2ray.ang.AppConfig.DNS_ALIDNS_ADDRESSES import com.v2ray.ang.AppConfig.DNS_ALIDNS_DOMAIN @@ -70,7 +69,7 @@ object V2rayConfigManager { getV2rayNormalConfig(context, guid, config) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to get V2ray config", e) return ConfigResult(false) } } @@ -91,7 +90,7 @@ object V2rayConfigManager { getV2rayNormalConfig4Speedtest(context, guid, config) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to get V2ray config for speedtest", e) return ConfigResult(false) } } @@ -123,7 +122,7 @@ object V2rayConfigManager { val address = config.server ?: return result if (!Utils.isIpAddress(address)) { if (!Utils.isValidUrl(address)) { - Log.d(ANG_PACKAGE, "$address is an invalid ip or domain") + Log.d(AppConfig.TAG, "$address is an invalid ip or domain") return result } } @@ -173,7 +172,7 @@ object V2rayConfigManager { val address = config.server ?: return result if (!Utils.isIpAddress(address)) { if (!Utils.isValidUrl(address)) { - Log.d(ANG_PACKAGE, "$address is an invalid ip or domain") + Log.d(AppConfig.TAG, "$address is an invalid ip or domain") return result } } @@ -256,7 +255,7 @@ object V2rayConfigManager { } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to configure inbounds", e) return false } return true @@ -319,7 +318,7 @@ object V2rayConfigManager { routingUserRule(key, v2rayConfig) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to configure routing", e) return false } return true @@ -336,7 +335,7 @@ object V2rayConfigManager { v2rayConfig.routing.rules.add(rule) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to apply routing user rule", e) } } @@ -422,7 +421,7 @@ object V2rayConfigManager { ) ) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to configure custom local DNS", e) return false } return true @@ -486,7 +485,7 @@ object V2rayConfigManager { if (userHostsMap != null) hosts.putAll(userHostsMap) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to configure user DNS hosts", e) } //block dns @@ -525,7 +524,7 @@ object V2rayConfigManager { ) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to configure DNS", e) return false } return true @@ -596,7 +595,7 @@ object V2rayConfigManager { } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to update outbound with global settings", e) return false } return true @@ -662,7 +661,7 @@ object V2rayConfigManager { dialerProxy = TAG_FRAGMENT ) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to update outbound fragment", e) return false } return true @@ -725,7 +724,7 @@ object V2rayConfigManager { } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to configure more outbounds", e) return returnPair } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/receiver/TaskerReceiver.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/receiver/TaskerReceiver.kt index eece9c3e..bdb7bf9a 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/receiver/TaskerReceiver.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/receiver/TaskerReceiver.kt @@ -35,7 +35,7 @@ class TaskerReceiver : BroadcastReceiver() { V2RayServiceManager.stopVService(context) } } catch (e: Exception) { - e.printStackTrace() + android.util.Log.e(AppConfig.TAG, "Error processing Tasker broadcast", e) } } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/ProcessService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/ProcessService.kt index fb8daa99..3db56134 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/ProcessService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/ProcessService.kt @@ -2,7 +2,7 @@ package com.v2ray.ang.service import android.content.Context import android.util.Log -import com.v2ray.ang.AppConfig.ANG_PACKAGE +import com.v2ray.ang.AppConfig import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -16,7 +16,7 @@ class ProcessService { * @param cmd The command to run. */ fun runProcess(context: Context, cmd: MutableList) { - Log.d(ANG_PACKAGE, cmd.toString()) + Log.d(AppConfig.TAG, cmd.toString()) try { val proBuilder = ProcessBuilder(cmd) @@ -27,14 +27,14 @@ class ProcessService { CoroutineScope(Dispatchers.IO).launch { Thread.sleep(50L) - Log.d(ANG_PACKAGE, "runProcess check") + Log.d(AppConfig.TAG, "runProcess check") process?.waitFor() - Log.d(ANG_PACKAGE, "runProcess exited") + Log.d(AppConfig.TAG, "runProcess exited") } - Log.d(ANG_PACKAGE, process.toString()) + Log.d(AppConfig.TAG, process.toString()) } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } } @@ -43,10 +43,10 @@ class ProcessService { */ fun stopProcess() { try { - Log.d(ANG_PACKAGE, "runProcess destroy") + Log.d(AppConfig.TAG, "runProcess destroy") process?.destroy() } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.e(AppConfig.TAG, "Failed to destroy process", e) } } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt index 02acd461..db12287d 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt @@ -8,6 +8,7 @@ import android.graphics.drawable.Icon import android.os.Build import android.service.quicksettings.Tile import android.service.quicksettings.TileService +import android.util.Log import androidx.annotation.RequiresApi import androidx.core.content.ContextCompat import com.v2ray.ang.AppConfig @@ -61,7 +62,7 @@ class QSTileService : TileService() { applicationContext.unregisterReceiver(mMsgReceive) mMsgReceive = null } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to unregister receiver", e) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdater.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdater.kt index 0c6ed03e..3afdbc19 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdater.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdater.kt @@ -38,7 +38,7 @@ object SubscriptionUpdater { */ @SuppressLint("MissingPermission") override suspend fun doWork(): Result { - Log.d(AppConfig.ANG_PACKAGE, "subscription automatic update starting") + Log.d(AppConfig.TAG, "subscription automatic update starting") val subs = MmkvManager.decodeSubscriptions().filter { it.second.autoUpdate } @@ -56,10 +56,7 @@ object SubscriptionUpdater { notificationManager.createNotificationChannel(channel) } notificationManager.notify(3, notification.build()) - Log.d( - AppConfig.ANG_PACKAGE, - "subscription automatic update: ---${subItem.remarks}" - ) + Log.d(AppConfig.TAG, "subscription automatic update: ---${subItem.remarks}") updateConfigViaSub(Pair(sub.first, subItem)) notification.setContentText("Updating ${subItem.remarks}") } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayServiceManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayServiceManager.kt index 48fef837..52d364c0 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayServiceManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayServiceManager.kt @@ -9,7 +9,6 @@ import android.os.Build import android.util.Log import androidx.core.content.ContextCompat import com.v2ray.ang.AppConfig -import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.R import com.v2ray.ang.dto.EConfigType import com.v2ray.ang.dto.ProfileItem @@ -144,7 +143,7 @@ object V2RayServiceManager { mFilter.addAction(Intent.ACTION_USER_PRESENT) ContextCompat.registerReceiver(service, mMsgReceive, mFilter, Utils.receiverFlags()) } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } v2rayPoint.configureFileContent = result.content @@ -154,7 +153,7 @@ object V2RayServiceManager { try { v2rayPoint.runLoop(MmkvManager.decodeSettingsBool(AppConfig.PREF_PREFER_IPV6)) } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } if (v2rayPoint.isRunning) { @@ -179,7 +178,7 @@ object V2RayServiceManager { try { v2rayPoint.stopLoop() } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } } } @@ -190,7 +189,7 @@ object V2RayServiceManager { try { service.unregisterReceiver(mMsgReceive) } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } PluginUtil.stopPlugin() } @@ -217,14 +216,14 @@ object V2RayServiceManager { try { time = v2rayPoint.measureDelay(SettingsManager.getDelayTestUrl()) } catch (e: Exception) { - Log.d(ANG_PACKAGE, "measureV2rayDelay: $e") + Log.d(AppConfig.TAG, "measureV2rayDelay: $e") errstr = e.message?.substringAfter("\":") ?: "empty message" } if (time == -1L) { try { time = v2rayPoint.measureDelay(SettingsManager.getDelayTestUrl(true)) } catch (e: Exception) { - Log.d(ANG_PACKAGE, "measureV2rayDelay: $e") + Log.d(AppConfig.TAG, "measureV2rayDelay: $e") errstr = e.message?.substringAfter("\":") ?: "empty message" } } @@ -255,7 +254,7 @@ object V2RayServiceManager { serviceControl.stopService() 0 } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) -1 } } @@ -291,7 +290,7 @@ object V2RayServiceManager { NotificationService.startSpeedNotification(currentConfig) 0 } catch (e: Exception) { - Log.d(ANG_PACKAGE, e.toString()) + Log.d(AppConfig.TAG, e.toString()) -1 } } @@ -323,12 +322,12 @@ object V2RayServiceManager { } AppConfig.MSG_STATE_STOP -> { - Log.d(ANG_PACKAGE, "Stop Service") + Log.d(AppConfig.TAG, "Stop Service") serviceControl.stopService() } AppConfig.MSG_STATE_RESTART -> { - Log.d(ANG_PACKAGE, "Restart Service") + Log.d(AppConfig.TAG, "Restart Service") serviceControl.stopService() Thread.sleep(500L) startVService(serviceControl.getService()) @@ -341,12 +340,12 @@ object V2RayServiceManager { when (intent?.action) { Intent.ACTION_SCREEN_OFF -> { - Log.d(ANG_PACKAGE, "SCREEN_OFF, stop querying stats") + Log.d(AppConfig.TAG, "SCREEN_OFF, stop querying stats") NotificationService.stopSpeedNotification(currentConfig) } Intent.ACTION_SCREEN_ON -> { - Log.d(ANG_PACKAGE, "SCREEN_ON, start querying stats") + Log.d(AppConfig.TAG, "SCREEN_ON, start querying stats") NotificationService.startSpeedNotification(currentConfig) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayVpnService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayVpnService.kt index 69c1adb6..b78fb8ea 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayVpnService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/V2RayVpnService.kt @@ -18,7 +18,6 @@ import android.os.StrictMode import android.util.Log import androidx.annotation.RequiresApi 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 @@ -40,6 +39,7 @@ class V2RayVpnService : VpnService(), ServiceControl { private const val PRIVATE_VLAN6_CLIENT = "fc00::10:10:14:1" private const val PRIVATE_VLAN6_ROUTER = "fc00::10:10:14:2" private const val TUN2SOCKS = "libtun2socks.so" + } private lateinit var mInterface: ParcelFileDescriptor @@ -209,7 +209,7 @@ class V2RayVpnService : VpnService(), ServiceControl { else builder.addAllowedApplication(it) } catch (e: PackageManager.NameNotFoundException) { - Log.d(ANG_PACKAGE, "setup error : --${e.localizedMessage}") + Log.d(AppConfig.TAG, "setup error : --${e.localizedMessage}") } } } else { @@ -227,7 +227,7 @@ class V2RayVpnService : VpnService(), ServiceControl { try { connectivity.requestNetwork(defaultNetworkRequest, defaultNetworkCallback) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to request default network", e) } } @@ -245,7 +245,7 @@ class V2RayVpnService : VpnService(), ServiceControl { return true } catch (e: Exception) { // non-nullable lateinit var - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to establish VPN interface", e) stopV2Ray() } return false @@ -277,7 +277,7 @@ class V2RayVpnService : VpnService(), ServiceControl { cmd.add("--dnsgw") cmd.add("$LOOPBACK:${localDnsPort}") } - Log.d(packageName, cmd.toString()) + Log.d(AppConfig.TAG, cmd.toString()) try { val proBuilder = ProcessBuilder(cmd) @@ -286,19 +286,19 @@ class V2RayVpnService : VpnService(), ServiceControl { .directory(applicationContext.filesDir) .start() Thread { - Log.d(packageName, "$TUN2SOCKS check") + Log.d(AppConfig.TAG, "$TUN2SOCKS check") process.waitFor() - Log.d(packageName, "$TUN2SOCKS exited") + Log.d(AppConfig.TAG, "$TUN2SOCKS exited") if (isRunning) { - Log.d(packageName, "$TUN2SOCKS restart") + Log.d(AppConfig.TAG, "$TUN2SOCKS restart") runTun2socks() } }.start() - Log.d(packageName, process.toString()) + Log.d(AppConfig.TAG, process.toString()) sendFd() } catch (e: Exception) { - Log.d(packageName, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } } @@ -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(packageName, path) + Log.d(AppConfig.TAG, path) CoroutineScope(Dispatchers.IO).launch { var tries = 0 while (true) try { Thread.sleep(50L shl tries) - Log.d(packageName, "sendFd tries: $tries") + Log.d(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(packageName, e.toString()) + Log.d(AppConfig.TAG, e.toString()) if (tries > 5) break tries += 1 } @@ -349,10 +349,10 @@ class V2RayVpnService : VpnService(), ServiceControl { } try { - Log.d(packageName, "tun2socks destroy") + Log.d(AppConfig.TAG, "tun2socks destroy") process.destroy() } catch (e: Exception) { - Log.d(packageName, e.toString()) + Log.d(AppConfig.TAG, e.toString()) } V2RayServiceManager.stopV2rayPoint() diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt index 18362be0..648996bc 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt @@ -34,7 +34,7 @@ class AboutActivity : BaseActivity() { try { showFileChooser() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to show file chooser", e) } } else { toast(R.string.toast_permission_denied) @@ -90,7 +90,7 @@ class AboutActivity : BaseActivity() { try { showFileChooser() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to show file chooser", e) } } else { requestPermissionLauncher.launch(permission) @@ -106,7 +106,7 @@ class AboutActivity : BaseActivity() { } binding.layoutOssLicenses.setOnClickListener { - val webView = android.webkit.WebView(this); + val webView = android.webkit.WebView(this) webView.loadUrl("file:///android_asset/open_source_licenses.html") android.app.AlertDialog.Builder(this) .setTitle("Open source licenses") @@ -169,7 +169,7 @@ class AboutActivity : BaseActivity() { try { chooseFile.launch(Intent.createChooser(intent, getString(R.string.title_file_chooser))) } catch (ex: android.content.ActivityNotFoundException) { - Log.e(AppConfig.ANG_PACKAGE, "File chooser activity not found: ${ex.message}", ex) + Log.e(AppConfig.TAG, "File chooser activity not found", ex) toast(R.string.toast_require_file_manager) } } @@ -192,7 +192,7 @@ class AboutActivity : BaseActivity() { toastError(R.string.toast_failure) } } catch (e: Exception) { - Log.e(AppConfig.ANG_PACKAGE, "Error during file restore: ${e.message}", e) + Log.e(AppConfig.TAG, "Error during file restore", e) toastError(R.string.toast_failure) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt index 331ee169..436f5913 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt @@ -2,12 +2,14 @@ package com.v2ray.ang.ui import android.annotation.SuppressLint import android.os.Bundle +import android.util.Log import android.view.Menu import android.view.MenuItem import androidx.appcompat.widget.SearchView import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import com.v2ray.ang.AppConfig import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.R import com.v2ray.ang.databinding.ActivityLogcatBinding @@ -68,7 +70,7 @@ class LogcatActivity : BaseActivity(), SwipeRefreshLayout.OnRefreshListener { } } } catch (e: IOException) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to get logcat", e) } } @@ -89,7 +91,7 @@ class LogcatActivity : BaseActivity(), SwipeRefreshLayout.OnRefreshListener { } } } catch (e: IOException) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to clear logcat", e) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatRecyclerAdapter.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatRecyclerAdapter.kt index 7f16634d..9883647d 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatRecyclerAdapter.kt @@ -1,13 +1,16 @@ package com.v2ray.ang.ui +import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView +import com.v2ray.ang.AppConfig import com.v2ray.ang.databinding.ItemRecyclerLogcatBinding class LogcatRecyclerAdapter(val activity: LogcatActivity) : RecyclerView.Adapter() { private var mActivity: LogcatActivity = activity + override fun getItemCount() = mActivity.logsets.size override fun onBindViewHolder(holder: MainViewHolder, position: Int) { @@ -22,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) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Error binding log data", e) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt index 71c528c0..0bb6315e 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt @@ -9,6 +9,7 @@ import android.net.Uri import android.net.VpnService import android.os.Build import android.os.Bundle +import android.util.Log import android.view.KeyEvent import android.view.Menu import android.view.MenuItem @@ -485,7 +486,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList val clipboard = Utils.getClipboard(this) importBatchConfig(clipboard) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to import config from clipboard", e) return false } return true @@ -515,7 +516,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList toastError(R.string.toast_failure) binding.pbWaiting.hide() } - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to import batch config", e) } } } @@ -524,7 +525,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList try { showFileChooser() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to import config from local file", e) return false } return true @@ -744,7 +745,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList importBatchConfig(input?.bufferedReader()?.readText()) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to read content from URI", e) } } else { requestPermissionLauncher.launch(permission) @@ -807,6 +808,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList Intent(this, SettingsActivity::class.java) .putExtra("isRunning", mainViewModel.isRunning.value == true) ) + R.id.promotion -> Utils.openUri(this, "${Utils.decode(AppConfig.PromotionUrl)}?t=${System.currentTimeMillis()}") R.id.logcat -> startActivity(Intent(this, LogcatActivity::class.java)) R.id.about -> startActivity(Intent(this, AboutActivity::class.java)) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt index 8729355f..5c7af440 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainRecyclerAdapter.kt @@ -3,6 +3,7 @@ package com.v2ray.ang.ui import android.content.Intent import android.graphics.Color import android.text.TextUtils +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -187,7 +188,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter mActivity.toast("else") } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Error occurred while sharing server information", e) } }.show() } @@ -299,7 +300,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter? = null @@ -164,7 +165,7 @@ class PerAppProxyActivity : BaseActivity() { content = HttpUtil.getUrlContent(url, 5000, httpPort) ?: "" } launch(Dispatchers.Main) { - Log.d(ANG_PACKAGE, content) + Log.d(AppConfig.TAG, content) selectProxyApp(content, true) toastSuccess(R.string.toast_success) binding.pbWaiting.hide() @@ -205,7 +206,7 @@ class PerAppProxyActivity : BaseActivity() { adapter?.let { it -> it.apps.forEach block@{ val packageName = it.packageName - Log.d(ANG_PACKAGE, packageName) + Log.d(AppConfig.TAG, packageName) if (!inProxyApps(proxyApps, packageName, force)) { adapter?.blacklist?.add(packageName) println(packageName) @@ -218,7 +219,7 @@ class PerAppProxyActivity : BaseActivity() { adapter?.let { it -> it.apps.forEach block@{ val packageName = it.packageName - Log.d(ANG_PACKAGE, packageName) + Log.d(AppConfig.TAG, packageName) if (inProxyApps(proxyApps, packageName, force)) { adapter?.blacklist?.add(packageName) println(packageName) @@ -229,7 +230,7 @@ class PerAppProxyActivity : BaseActivity() { } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Error selecting proxy app", e) return false } return true diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/RoutingSettingActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/RoutingSettingActivity.kt index ddaf4a02..104e5049 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/RoutingSettingActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/RoutingSettingActivity.kt @@ -4,6 +4,7 @@ import android.Manifest import android.annotation.SuppressLint import android.content.Intent import android.os.Bundle +import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View @@ -110,7 +111,7 @@ class RoutingSettingActivity : BaseActivity() { } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to import predefined ruleset", e) } } .setNegativeButton(android.R.string.cancel) { _, _ -> @@ -126,7 +127,7 @@ class RoutingSettingActivity : BaseActivity() { val clipboard = try { Utils.getClipboard(this) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to get clipboard content", e) toastError(R.string.toast_failure) return@setPositiveButton } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt index 6702cdc1..2a971ac0 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt @@ -6,6 +6,7 @@ import android.content.pm.PackageManager import android.graphics.BitmapFactory import android.os.Build import android.os.Bundle +import android.util.Log import android.view.Menu import android.view.MenuItem import androidx.activity.result.contract.ActivityResultContracts @@ -21,6 +22,7 @@ import io.github.g00fy2.quickie.config.ScannerConfig class ScannerActivity : BaseActivity() { + private val scanQrCode = registerForActivityResult(ScanCustomCode(), ::handleResult) private val chooseFile = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { val uri = it.data?.data @@ -37,7 +39,7 @@ class ScannerActivity : BaseActivity() { finished(text) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to decode QR code from file", e) toast(R.string.toast_decoding_failed) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt index 9e88a7bd..53cfbdc2 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt @@ -14,7 +14,6 @@ import android.widget.Spinner import android.widget.TextView import androidx.appcompat.app.AlertDialog import com.v2ray.ang.AppConfig -import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.AppConfig.DEFAULT_PORT import com.v2ray.ang.AppConfig.PREF_ALLOW_INSECURE import com.v2ray.ang.AppConfig.REALITY @@ -481,7 +480,7 @@ class ServerActivity : BaseActivity() { if (config.subscriptionId.isEmpty() && !subscriptionId.isNullOrEmpty()) { config.subscriptionId = subscriptionId.orEmpty() } - Log.d(ANG_PACKAGE, JsonUtil.toJsonPretty(config) ?: "") + //Log.d(AppConfig.TAG, JsonUtil.toJsonPretty(config) ?: "") MmkvManager.encodeServerConfig(editGuid, config) toastSuccess(R.string.toast_success) finish() diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerCustomConfigActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerCustomConfigActivity.kt index 903ec410..44e0b32b 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerCustomConfigActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerCustomConfigActivity.kt @@ -2,11 +2,13 @@ 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.blacksquircle.ui.editorkit.utils.EditorTheme import com.blacksquircle.ui.language.json.JsonLanguage +import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.databinding.ActivityServerCustomConfigBinding import com.v2ray.ang.dto.EConfigType @@ -76,7 +78,7 @@ class ServerCustomConfigActivity : BaseActivity() { val profileItem = try { CustomFmt.parse(binding.editor.text.toString()) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse custom configuration", e) toast("${getString(R.string.toast_malformed_josn)} ${e.cause?.message}") return false } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/SubSettingRecyclerAdapter.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/SubSettingRecyclerAdapter.kt index cec25272..bb364c1b 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/SubSettingRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/SubSettingRecyclerAdapter.kt @@ -3,11 +3,13 @@ package com.v2ray.ang.ui import android.content.Intent import android.graphics.Color import android.text.TextUtils +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.recyclerview.widget.RecyclerView +import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.databinding.ItemQrcodeBinding import com.v2ray.ang.databinding.ItemRecyclerSubSettingBinding @@ -81,7 +83,7 @@ class SubSettingRecyclerAdapter(val activity: SubSettingActivity) : RecyclerView else -> mActivity.toast("else") } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Share subscription failed", e) } }.show() } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/TaskerActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/TaskerActivity.kt index 7c5f7ee5..8600a4ee 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/TaskerActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/TaskerActivity.kt @@ -3,6 +3,7 @@ package com.v2ray.ang.ui import android.content.Intent import android.os.Bundle import android.text.TextUtils +import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View @@ -60,7 +61,7 @@ class TaskerActivity : BaseActivity() { } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to initialize Tasker settings", e) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UrlSchemeActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UrlSchemeActivity.kt index 264e19dc..66771be4 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UrlSchemeActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UrlSchemeActivity.kt @@ -5,6 +5,7 @@ import android.net.Uri import android.os.Bundle import android.util.Log import androidx.lifecycle.lifecycleScope +import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.databinding.ActivityLogcatBinding import com.v2ray.ang.extension.toast @@ -54,7 +55,7 @@ class UrlSchemeActivity : BaseActivity() { startActivity(Intent(this, MainActivity::class.java)) finish() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Error processing URL scheme", e) } } @@ -62,7 +63,7 @@ class UrlSchemeActivity : BaseActivity() { if (uriString.isNullOrEmpty()) { return } - Log.d("UrlScheme", uriString) + Log.d(AppConfig.TAG, uriString) var decodedUrl = URLDecoder.decode(uriString, "UTF-8") val uri = Uri.parse(decodedUrl) @@ -70,7 +71,7 @@ class UrlSchemeActivity : BaseActivity() { if (uri.fragment.isNullOrEmpty() && !fragment.isNullOrEmpty()) { decodedUrl += "#${fragment}" } - Log.d("UrlScheme-decodedUrl", decodedUrl) + Log.d(AppConfig.TAG, decodedUrl) lifecycleScope.launch(Dispatchers.IO) { val (count, countSub) = AngConfigManager.importBatchConfig(decodedUrl, "", false) withContext(Dispatchers.Main) { diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UserAssetActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UserAssetActivity.kt index 387ea3e8..d08bc7d5 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UserAssetActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/UserAssetActivity.kt @@ -44,6 +44,7 @@ import java.util.Date class UserAssetActivity : BaseActivity() { private val binding by lazy { ActivitySubSettingBinding.inflate(layoutInflater) } + val extDir by lazy { File(Utils.userAssetPath(this)) } val builtInGeoFiles = arrayOf("geosite.dat", "geoip.dat") @@ -163,7 +164,7 @@ class UserAssetActivity : BaseActivity() { }.also { cursor.close() } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to get cursor name", e) null } @@ -190,7 +191,7 @@ class UserAssetActivity : BaseActivity() { .putExtra(UserAssetUrlActivity.ASSET_URL_QRCODE, url) ) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to import asset", e) return false } return true @@ -229,7 +230,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.ANG_PACKAGE, url) + //Log.d(AppConfig.TAG, url) val conn = HttpUtil.createProxyConnection(item.url, httpPort, timeout, timeout, needStream = true) ?: return false try { @@ -244,10 +245,10 @@ class UserAssetActivity : BaseActivity() { } return true } catch (e: Exception) { - Log.e(AppConfig.ANG_PACKAGE, Log.getStackTraceString(e)) + Log.e(AppConfig.TAG, "Failed to download geo file", e) return false } finally { - conn?.disconnect() + conn.disconnect() } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/HttpUtil.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/HttpUtil.kt index b8472167..b2a64777 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/HttpUtil.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/HttpUtil.kt @@ -1,5 +1,7 @@ package com.v2ray.ang.util +import android.util.Log +import com.v2ray.ang.AppConfig import com.v2ray.ang.AppConfig.LOOPBACK import com.v2ray.ang.BuildConfig import com.v2ray.ang.util.Utils.encode @@ -10,6 +12,7 @@ import java.util.* object HttpUtil { + /** * Converts a URL string to its ASCII representation. * @@ -142,7 +145,7 @@ object HttpUtil { ) } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to create proxy connection", e) // If an exception occurs, close the connection and return null conn?.disconnect() return null diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/JsonUtil.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/JsonUtil.kt index 04e0e167..80a40fbf 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/JsonUtil.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/JsonUtil.kt @@ -1,5 +1,6 @@ package com.v2ray.ang.util +import android.util.Log import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.JsonObject @@ -8,6 +9,7 @@ import com.google.gson.JsonPrimitive import com.google.gson.JsonSerializationContext import com.google.gson.JsonSerializer import com.google.gson.reflect.TypeToken +import com.v2ray.ang.AppConfig import java.lang.reflect.Type object JsonUtil { @@ -70,7 +72,7 @@ object JsonUtil { try { return JsonParser.parseString(src).getAsJsonObject() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to parse JSON string", e) return null } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt index 079e9138..eae9f5c6 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt @@ -3,12 +3,14 @@ package com.v2ray.ang.util import android.content.ComponentName import android.content.Context import android.content.Intent +import android.util.Log import com.v2ray.ang.AppConfig import com.v2ray.ang.service.V2RayTestService import java.io.Serializable object MessageUtil { + /** * Sends a message to the service. * @@ -46,7 +48,7 @@ object MessageUtil { intent.putExtra("content", content) ctx.startService(intent) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to send message to test service", e) } } @@ -67,7 +69,7 @@ object MessageUtil { intent.putExtra("content", content) ctx.sendBroadcast(intent) } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to send broadcast message", e) } } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/PluginUtil.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/PluginUtil.kt index a4d62a7b..d531c03c 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/PluginUtil.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/PluginUtil.kt @@ -3,7 +3,7 @@ package com.v2ray.ang.util import android.content.Context import android.os.SystemClock import android.util.Log -import com.v2ray.ang.AppConfig.ANG_PACKAGE +import com.v2ray.ang.AppConfig import com.v2ray.ang.dto.EConfigType import com.v2ray.ang.dto.ProfileItem import com.v2ray.ang.fmt.Hysteria2Fmt @@ -13,7 +13,7 @@ import java.io.File object PluginUtil { private const val HYSTERIA2 = "libhysteria2.so" - private const val TAG = ANG_PACKAGE + private val procService: ProcessService by lazy { ProcessService() } @@ -26,7 +26,7 @@ object PluginUtil { * @param domainPort The domain and port information. */ fun runPlugin(context: Context, config: ProfileItem?, domainPort: String?) { - Log.d(TAG, "runPlugin") + Log.d(AppConfig.TAG, "runPlugin") if (config?.configType?.equals(EConfigType.HYSTERIA2) == true) { val configFile = genConfigHy2(context, config, domainPort) ?: return @@ -51,7 +51,7 @@ object PluginUtil { * @return The ping delay in milliseconds, or -1 if it fails. */ fun realPingHy2(context: Context, config: ProfileItem?): Long { - Log.d(TAG, "realPingHy2") + Log.d(AppConfig.TAG, "realPingHy2") val retFailure = -1L if (config?.configType?.equals(EConfigType.HYSTERIA2) == true) { @@ -79,18 +79,18 @@ object PluginUtil { * @return The generated configuration file. */ private fun genConfigHy2(context: Context, config: ProfileItem, domainPort: String?): File? { - Log.d(TAG, "runPlugin $HYSTERIA2") + Log.d(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(TAG, "runPlugin ${configFile.absolutePath}") + Log.d(AppConfig.TAG, "runPlugin ${configFile.absolutePath}") configFile.parentFile?.mkdirs() configFile.writeText(JsonUtil.toJson(hy2Config)) - Log.d(TAG, JsonUtil.toJson(hy2Config)) + Log.d(AppConfig.TAG, JsonUtil.toJson(hy2Config)) return configFile } @@ -119,10 +119,10 @@ object PluginUtil { */ private fun stopHy2() { try { - Log.d(TAG, "$HYSTERIA2 destroy") + Log.d(AppConfig.TAG, "$HYSTERIA2 destroy") procService?.stopProcess() } catch (e: Exception) { - Log.d(TAG, e.toString()) + Log.e(AppConfig.TAG, "Failed to stop Hysteria2 process", e) } } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/Utils.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/Utils.kt index 25cd1594..d83a9989 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/Utils.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/Utils.kt @@ -118,12 +118,12 @@ object Utils { try { return Base64.decode(text, Base64.NO_WRAP).toString(Charsets.UTF_8) } catch (e: Exception) { - Log.w(AppConfig.TAG, "Failed to decode standard base64", e) + Log.e(AppConfig.TAG, "Failed to decode standard base64", e) } try { return Base64.decode(text, Base64.NO_WRAP.or(Base64.URL_SAFE)).toString(Charsets.UTF_8) } catch (e: Exception) { - Log.w(AppConfig.TAG, "Failed to decode URL-safe base64", e) + Log.e(AppConfig.TAG, "Failed to decode URL-safe base64", e) } return null } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/ZipUtil.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/ZipUtil.kt index 62677c5d..9d9dce62 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/ZipUtil.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/ZipUtil.kt @@ -1,5 +1,7 @@ package com.v2ray.ang.util +import android.util.Log +import com.v2ray.ang.AppConfig import java.io.BufferedOutputStream import java.io.File import java.io.FileInputStream @@ -61,7 +63,7 @@ object ZipUtil { zos.closeEntry() zos.close() } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to zip folder", e) return false } return true @@ -97,7 +99,7 @@ object ZipUtil { } } } catch (e: Exception) { - e.printStackTrace() + Log.e(AppConfig.TAG, "Failed to unzip file", e) return false } return true diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt index ebdc37a2..665acb55 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt @@ -13,7 +13,6 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.v2ray.ang.AngApplication import com.v2ray.ang.AppConfig -import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.R import com.v2ray.ang.dto.ProfileItem import com.v2ray.ang.dto.ServersCache @@ -63,7 +62,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { getApplication().unregisterReceiver(mMsgReceiver) tcpingTestScope.coroutineContext[Job]?.cancelChildren() SpeedtestManager.closeAllTcpSockets() - Log.i(ANG_PACKAGE, "Main ViewModel is cleared") + Log.d(AppConfig.TAG, "Main ViewModel is cleared") super.onCleared() } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/SettingsViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/SettingsViewModel.kt index 995573d1..115f811c 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/SettingsViewModel.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/SettingsViewModel.kt @@ -26,7 +26,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application override fun onCleared() { PreferenceManager.getDefaultSharedPreferences(getApplication()) .unregisterOnSharedPreferenceChangeListener(this) - Log.i(AppConfig.ANG_PACKAGE, "Settings ViewModel is cleared") + Log.d(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.ANG_PACKAGE, "Observe settings changed: $key") + Log.d(AppConfig.TAG, "Observe settings changed: $key") when (key) { AppConfig.PREF_MODE, AppConfig.PREF_VPN_DNS,