Simplify exporting debug info
This commit is contained in:
@@ -58,15 +58,14 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
val logFile = File.createTempFile("vpnhotspot-", ".log", logDir)
|
val logFile = File.createTempFile("vpnhotspot-", ".log", logDir)
|
||||||
logFile.outputStream().use { out ->
|
logFile.outputStream().use { out ->
|
||||||
PrintWriter(out.bufferedWriter()).use { writer ->
|
PrintWriter(out.bufferedWriter()).use { writer ->
|
||||||
writer.write("${BuildConfig.VERSION_CODE} is running on API ${Build.VERSION.SDK_INT}\n\n")
|
writer.println("${BuildConfig.VERSION_CODE} is running on API ${Build.VERSION.SDK_INT}\n")
|
||||||
writer.flush()
|
writer.flush()
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.use { it.copyTo(out) }
|
Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.use { it.copyTo(out) }
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
}
|
}
|
||||||
writer.write("\n")
|
writer.println()
|
||||||
writer.flush()
|
|
||||||
val commands = StringBuilder()
|
val commands = StringBuilder()
|
||||||
// https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34
|
// https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34
|
||||||
val iptablesSave = if (Build.VERSION.SDK_INT >= 24) "iptables-save" else
|
val iptablesSave = if (Build.VERSION.SDK_INT >= 24) "iptables-save" else
|
||||||
@@ -99,15 +98,9 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
|logcat -d
|
|logcat -d
|
||||||
""".trimMargin())
|
""".trimMargin())
|
||||||
try {
|
try {
|
||||||
RootSession.use {
|
RootSession.use { it.execQuiet(commands.toString(), true).out.forEach(writer::println) }
|
||||||
for (line in it.execQuiet(commands.toString(), true).out) {
|
|
||||||
out.write(line.toByteArray())
|
|
||||||
out.write(10) // line break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace(writer)
|
e.printStackTrace(writer)
|
||||||
writer.flush()
|
|
||||||
Timber.i(e)
|
Timber.i(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user