Skip to content

Commit

Permalink
add report logcat button
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr328 committed Apr 23, 2020
1 parent 8a98eea commit 5983566
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/com/github/kr328/clash/SupportActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
}
}
}
21 changes: 19 additions & 2 deletions app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 5983566

Please sign in to comment.