From d32ccc817a4cc91f36be5605ff32733920f54297 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 12 Jun 2021 23:38:31 -0400 Subject: [PATCH] Log with consistent tag --- .../v2ray/ang/service/V2RayServiceManager.kt | 30 +++++++++++-------- .../kotlin/com/v2ray/ang/ui/LogcatActivity.kt | 3 +- .../kotlin/com/v2ray/ang/ui/MainActivity.kt | 3 +- .../com/v2ray/ang/ui/PerAppProxyActivity.kt | 7 +++-- .../com/v2ray/ang/util/V2rayConfigUtil.kt | 5 ++-- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt index 1387439f..61acaafb 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt @@ -15,6 +15,7 @@ import android.support.v4.app.NotificationCompat 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.AppConfig.TAG_DIRECT import com.v2ray.ang.R import com.v2ray.ang.dto.ServerConfig @@ -26,6 +27,9 @@ import com.v2ray.ang.util.MmkvManager import com.v2ray.ang.util.Utils import com.v2ray.ang.util.V2rayConfigUtil import go.Seq +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import libv2ray.Libv2ray import libv2ray.V2RayPoint import libv2ray.V2RayVPNServiceSupportsSet @@ -89,7 +93,7 @@ object V2RayServiceManager { serviceControl.stopService() 0 } catch (e: Exception) { - Log.d(serviceControl.getService().packageName, e.toString()) + Log.d(ANG_PACKAGE, e.toString()) -1 } } @@ -117,7 +121,7 @@ object V2RayServiceManager { startSpeedNotification() 0 } catch (e: Exception) { - Log.d(serviceControl.getService().packageName, e.toString()) + Log.d(ANG_PACKAGE, e.toString()) -1 } } @@ -140,7 +144,7 @@ object V2RayServiceManager { mFilter.addAction(Intent.ACTION_USER_PRESENT) service.registerReceiver(mMsgReceive, mFilter) } catch (e: Exception) { - Log.d(service.packageName, e.toString()) + Log.d(ANG_PACKAGE, e.toString()) } v2rayPoint.configureFileContent = result.content @@ -153,7 +157,7 @@ object V2RayServiceManager { try { v2rayPoint.runLoop() } catch (e: Exception) { - Log.d(service.packageName, e.toString()) + Log.d(ANG_PACKAGE, e.toString()) } if (v2rayPoint.isRunning) { @@ -170,10 +174,12 @@ object V2RayServiceManager { val service = serviceControl?.get()?.getService() ?: return if (v2rayPoint.isRunning) { - try { - v2rayPoint.stopLoop() - } catch (e: Exception) { - Log.d(service.packageName, e.toString()) + GlobalScope.launch(Dispatchers.Default) { + try { + v2rayPoint.stopLoop() + } catch (e: Exception) { + Log.d(ANG_PACKAGE, e.toString()) + } } } @@ -183,7 +189,7 @@ object V2RayServiceManager { try { service.unregisterReceiver(mMsgReceive) } catch (e: Exception) { - Log.d(service.packageName, e.toString()) + Log.d(ANG_PACKAGE, e.toString()) } } @@ -215,11 +221,11 @@ object V2RayServiceManager { when (intent?.action) { Intent.ACTION_SCREEN_OFF -> { - Log.d(AppConfig.ANG_PACKAGE, "SCREEN_OFF, stop querying stats") + Log.d(ANG_PACKAGE, "SCREEN_OFF, stop querying stats") stopSpeedNotification() } Intent.ACTION_SCREEN_ON -> { - Log.d(AppConfig.ANG_PACKAGE, "SCREEN_ON, start querying stats") + Log.d(ANG_PACKAGE, "SCREEN_ON, start querying stats") startSpeedNotification() } } @@ -234,7 +240,7 @@ object V2RayServiceManager { PendingIntent.FLAG_UPDATE_CURRENT) val stopV2RayIntent = Intent(AppConfig.BROADCAST_ACTION_SERVICE) - stopV2RayIntent.`package` = AppConfig.ANG_PACKAGE + stopV2RayIntent.`package` = ANG_PACKAGE stopV2RayIntent.putExtra("key", AppConfig.MSG_STATE_STOP) val stopV2RayPendingIntent = PendingIntent.getBroadcast(service, diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/LogcatActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/LogcatActivity.kt index 620ab3a1..8b4895d7 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/LogcatActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/LogcatActivity.kt @@ -7,6 +7,7 @@ import android.text.method.ScrollingMovementMethod import android.view.Menu import android.view.MenuItem import android.view.View +import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.R import com.v2ray.ang.extension.toast import com.v2ray.ang.util.Utils @@ -48,7 +49,7 @@ class LogcatActivity : BaseActivity() { lst.add("-v") lst.add("time") lst.add("-s") - lst.add("GoLog,tun2socks,com.v2ray.ang") + lst.add("GoLog,tun2socks,${ANG_PACKAGE},AndroidRuntime,System.err") val process = Runtime.getRuntime().exec(lst.toTypedArray()) // val bufferedReader = BufferedReader( // InputStreamReader(process.inputStream)) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt index fba5096e..a8630779 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt @@ -20,6 +20,7 @@ import android.widget.Toast import com.tbruyelle.rxpermissions.RxPermissions import com.tencent.mmkv.MMKV import com.v2ray.ang.AppConfig +import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.BuildConfig import com.v2ray.ang.R import com.v2ray.ang.dto.EConfigType @@ -410,7 +411,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList if (!Utils.isValidUrl(url)) { return@forEach } - Log.d("Main", url) + Log.d(ANG_PACKAGE, url) GlobalScope.launch(Dispatchers.IO) { val configText = try { URL(url).readText() diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/PerAppProxyActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/PerAppProxyActivity.kt index 55f8a9af..26a49520 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/PerAppProxyActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/PerAppProxyActivity.kt @@ -25,6 +25,7 @@ import java.util.* import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import com.v2ray.ang.AppConfig +import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.dto.AppInfo import com.v2ray.ang.extension.toast import com.v2ray.ang.extension.v2RayApplication @@ -226,7 +227,7 @@ class PerAppProxyActivity : BaseActivity() { "" } launch(Dispatchers.Main) { - Log.d("selectProxyApp", content) + Log.d(ANG_PACKAGE, content) selectProxyApp(content) toast(R.string.toast_success) } @@ -250,7 +251,7 @@ class PerAppProxyActivity : BaseActivity() { adapter?.let { it.apps.forEach block@{ val packageName = it.packageName - Log.d("selectProxyApp2", packageName) + Log.d(ANG_PACKAGE, packageName) if (proxyApps.indexOf(packageName) < 0) { adapter?.blacklist!!.add(packageName) println(packageName) @@ -263,7 +264,7 @@ class PerAppProxyActivity : BaseActivity() { adapter?.let { it.apps.forEach block@{ val packageName = it.packageName - Log.d("selectProxyApp3", packageName) + Log.d(ANG_PACKAGE, packageName) if (proxyApps.indexOf(packageName) >= 0) { adapter?.blacklist!!.add(packageName) println(packageName) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt index adbd356e..8de0f558 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt @@ -6,6 +6,7 @@ import android.util.Log import com.google.gson.* import com.tencent.mmkv.MMKV import com.v2ray.ang.AppConfig +import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.dto.V2rayConfig import com.v2ray.ang.dto.EConfigType import com.v2ray.ang.dto.V2rayConfig.Companion.DEFAULT_NETWORK @@ -30,12 +31,12 @@ object V2rayConfigUtil { } else { raw } - Log.d("V2rayConfigUtilGoLog", customConfig) + Log.d(ANG_PACKAGE, customConfig) return Result(true, customConfig) } val outbound = config.getProxyOutbound() ?: return Result(false, "") val result = getV2rayNonCustomConfig(context, outbound) - Log.d("V2rayConfigUtilGoLog", result.content) + Log.d(ANG_PACKAGE, result.content) return result } catch (e: Exception) { e.printStackTrace()