diff --git a/app/src/main/java/com/github/kr328/clash/MainApplication.kt b/app/src/main/java/com/github/kr328/clash/MainApplication.kt index 275cd2b..614e6d3 100644 --- a/app/src/main/java/com/github/kr328/clash/MainApplication.kt +++ b/app/src/main/java/com/github/kr328/clash/MainApplication.kt @@ -42,7 +42,7 @@ class MainApplication : Application() { if (!report.stackTrace.contains("DeadObjectException")) return mutableListOf() - val logcat = LogcatDumper.dump() + val logcat = LogcatDumper.dumpCrash() return mutableListOf( ErrorAttachmentLog.attachmentWithText(logcat, "logcat.txt") diff --git a/app/src/main/java/com/github/kr328/clash/SupportActivity.kt b/app/src/main/java/com/github/kr328/clash/SupportActivity.kt index ecb9a1e..6adf03c 100644 --- a/app/src/main/java/com/github/kr328/clash/SupportActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/SupportActivity.kt @@ -4,9 +4,18 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.text.Html +import androidx.appcompat.app.AlertDialog +import com.github.kr328.clash.dump.LogcatDumper +import com.microsoft.appcenter.crashes.Crashes +import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog import kotlinx.android.synthetic.main.activity_support.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class SupportActivity : BaseActivity() { + class UserRequestTrackException: Exception() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -46,6 +55,20 @@ class SupportActivity : BaseActivity() { category(text = getString(R.string.feedback)) + option( + title = getString(R.string.upload_logcat), + summary = getString(R.string.upload_logcat_summary) + ) { + onClick { + AlertDialog.Builder(this@SupportActivity) + .setTitle(R.string.upload_logcat) + .setMessage(R.string.upload_logcat_warn) + .setNegativeButton(R.string.cancel) {_, _ -> } + .setPositiveButton(R.string.ok) {_, _ -> upload() } + .show() + } + } + option( title = getString(R.string.github_issues), summary = getString(R.string.github_issues_url) @@ -77,4 +100,15 @@ class SupportActivity : BaseActivity() { } } } + + private fun upload() { + launch { + withContext(Dispatchers.IO) { + val attachment = ErrorAttachmentLog + .attachmentWithText(LogcatDumper.dumpAll(), "logcat.txt") + + Crashes.trackError(UserRequestTrackException(), null, listOf(attachment)) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt b/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt index 8db2809..3654d51 100644 --- a/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt +++ b/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt @@ -1,10 +1,27 @@ package com.github.kr328.clash.dump object LogcatDumper { - fun dump(): String { + fun dumpCrash(): String { return try { val process = - Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-s", "-v", "raw", "Go", "AndroidRuntime", "DEBUG")) + Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-s", "Go", "AndroidRuntime", "DEBUG")) + + val result = process.inputStream.use { + it.reader().readText() + } + + process.waitFor() + + result + } catch (e: Exception) { + "" + } + } + + fun dumpAll(): String { + return try { + val process = + Runtime.getRuntime().exec(arrayOf("logcat", "-d")) val result = process.inputStream.use { it.reader().readText() diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index dd95094..734020b 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -131,4 +131,7 @@ 免费开源的项目
我们不提供任何代理服务
请务必不要反馈非应用自身引起的问题]]>
捐赠 复制配置 + 上传日志 + 上传日志以帮助我们侦测问题 + 请注意, 上传的日志可能包含个人敏感信息, 仍要继续吗? \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d7dc23..c74a637 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -173,4 +173,8 @@ Missing VPN Components Profile not found + + Upload Logcat + Upload logcat to help us detect issues + Please note that the uploaded logs may contain personally sensitive information, do you still want to continue?