From dea724ffb677c04efcdda616556b0aa409d0b609 Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 21 Feb 2018 20:27:53 -0800 Subject: [PATCH] Export debug information --- .../vpnhotspot/SettingsPreferenceFragment.kt | 30 ++++++++++++++----- .../java/be/mygod/vpnhotspot/net/Routing.kt | 12 ++++++++ mobile/src/main/res/values-zh-rCN/strings.xml | 4 +-- mobile/src/main/res/values/strings.xml | 4 +-- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt index d93e5d4b..245d26b7 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/SettingsPreferenceFragment.kt @@ -2,6 +2,7 @@ package be.mygod.vpnhotspot import android.content.Intent import android.net.Uri +import android.os.Build import android.os.Bundle import android.support.customtabs.CustomTabsIntent import android.support.v4.content.ContextCompat @@ -10,6 +11,8 @@ import android.widget.Toast import be.mygod.vpnhotspot.net.Routing import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers import java.io.IOException +import java.io.PrintWriter +import java.io.StringWriter class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() { private val customTabsIntent by lazy { @@ -24,16 +27,27 @@ class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() { true } findPreference("misc.logcat").setOnPreferenceClickListener { - try { - val intent = Intent(Intent.ACTION_SEND) - .setType("text/plain") - .putExtra(Intent.EXTRA_TEXT, Runtime.getRuntime().exec(arrayOf("logcat", "-d")) - .inputStream.bufferedReader().readText()) - startActivity(Intent.createChooser(intent, getString(R.string.abc_shareactionprovider_share_with))) - } catch (e: IOException) { + fun handle(e: IOException): String { Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show() - e.printStackTrace() + val writer = StringWriter() + e.printStackTrace(PrintWriter(writer)) + return writer.toString() } + val logcat = try { + Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.bufferedReader().readText() + } catch (e: IOException) { + handle(e) + } + val debug = try { + Routing.dump() + } catch (e: IOException) { + handle(e) + } + val intent = Intent(Intent.ACTION_SEND) + .setType("text/plain") + .putExtra(Intent.EXTRA_TEXT, + "${BuildConfig.VERSION_CODE} running on ${Build.VERSION.SDK_INT}\n$logcat\n$debug") + startActivity(Intent.createChooser(intent, getString(R.string.abc_shareactionprovider_share_with))) true } findPreference("misc.source").setOnPreferenceClickListener { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index 95196b5f..a89d33c9 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -4,6 +4,7 @@ import android.os.Build import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.debugLog +import be.mygod.vpnhotspot.loggerSu import be.mygod.vpnhotspot.noisySu import java.io.IOException import java.net.Inet4Address @@ -28,6 +29,17 @@ class Routing(val upstream: String?, val downstream: String, ownerAddress: InetA "$IPTABLES -F vpnhotspot_fwd", "$IPTABLES -X vpnhotspot_fwd", "quiet while ip rule del priority 17900; do done") + + fun dump() = loggerSu(""" + |echo iptables + |iptables-save + |echo + |echo iptables -t nat + |iptables-save -t nat + |echo + |echo ip rule + |ip rule + """.trimMargin()) } class InterfaceNotFoundException : IOException() { diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index 0f14650a..250db3c8 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -45,7 +45,7 @@ 备用 DNS 服务器[:端口] 清理/重新应用路由规则 杂项 - 导出日志 + 导出调试信息 这种非常有用哇 查看 GitHub 上的源码 Star, 提交 issues, 合作 @@ -63,5 +63,5 @@ 错误:未找到下游接口 似乎没有 root - 发生异常,详情请查看日志。 + 发生异常,详情请查看调试信息。 diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 5f4e1cfd..e3ccac09 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -47,7 +47,7 @@ Fallback DNS server[:port] Clean/reapply routing rules Misc - Export logcat + Export debug information Such useful very wow View on GitHub Star, submit issues and contribute @@ -67,5 +67,5 @@ Fatal: Downstream interface not found Root unavailable - Something went wrong, please check logcat. + Something went wrong, please check the debug information.