add report logcat button

This commit is contained in:
Kr328 committed 2020-04-23 19:04:51 +08:00
1 parent 8a98eea8fa
commit 59835667aa
5 files changed
+61 -3

No files matched your search

@@ -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")
@@ -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))
}
}
}
}
@@ -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()
+3
View File
@@ -131,4 +131,7 @@
<string name="tips_support"><![CDATA[Clash for Android 是一个<strong>免费开源</strong>的项目<br /> 我们<strong>不提供</strong>任何代理服务<br />请务必<strong>不要</strong>反馈非应用自身引起的问题]]></string>
<string name="donate">捐赠</string>
<string name="clone_profile">复制配置</string>
<string name="upload_logcat">上传日志</string>
<string name="upload_logcat_summary">上传日志以帮助我们侦测问题</string>
<string name="upload_logcat_warn">请注意, 上传的日志可能包含个人敏感信息, 仍要继续吗?</string>
</resources>
+4
View File
@@ -173,4 +173,8 @@
<string name="missing_vpn_component">Missing VPN Components</string>
<string name="profile_not_found">Profile not found</string>
<string name="upload_logcat">Upload Logcat</string>
<string name="upload_logcat_summary">Upload logcat to help us detect issues</string>
<string name="upload_logcat_warn">Please note that the uploaded logs may contain personally sensitive information, do you still want to continue?</string>
</resources>