|
|
@ -38,29 +38,25 @@ open class AndroidBugReporter @Inject constructor(@AppContext private val contex
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Throws(IOException::class)
|
|
|
|
@Throws(IOException::class)
|
|
|
|
fun getBugReport(): String {
|
|
|
|
fun getBugReport(): String {
|
|
|
|
val logcat = logcat
|
|
|
|
|
|
|
|
val deviceInfo = getDeviceInfo()
|
|
|
|
|
|
|
|
var log = "---------- BUG REPORT BEGINS ----------\n"
|
|
|
|
var log = "---------- BUG REPORT BEGINS ----------\n"
|
|
|
|
log += """
|
|
|
|
log += "${getLogcat()}\n"
|
|
|
|
$deviceInfo
|
|
|
|
log += "${getDeviceInfo()}\n"
|
|
|
|
$logcat
|
|
|
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
log += "---------- BUG REPORT ENDS ------------\n"
|
|
|
|
log += "---------- BUG REPORT ENDS ------------\n"
|
|
|
|
return log
|
|
|
|
return log
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@get:Throws(IOException::class)
|
|
|
|
@Throws(IOException::class)
|
|
|
|
val logcat: String
|
|
|
|
fun getLogcat(): String {
|
|
|
|
get() {
|
|
|
|
|
|
|
|
val maxLineCount = 250
|
|
|
|
val maxLineCount = 250
|
|
|
|
val builder = StringBuilder()
|
|
|
|
val builder = StringBuilder()
|
|
|
|
val command = arrayOf("logcat", "-d")
|
|
|
|
val process = Runtime.getRuntime().exec(arrayOf("logcat", "-d"))
|
|
|
|
val process = Runtime.getRuntime().exec(command)
|
|
|
|
|
|
|
|
val inputReader = InputStreamReader(process.inputStream)
|
|
|
|
val inputReader = InputStreamReader(process.inputStream)
|
|
|
|
val bufferedReader = BufferedReader(inputReader)
|
|
|
|
val bufferedReader = BufferedReader(inputReader)
|
|
|
|
val log = LinkedList<String>()
|
|
|
|
val log = LinkedList<String>()
|
|
|
|
var line: String
|
|
|
|
var line: String?
|
|
|
|
while (bufferedReader.readLine().also { line = it } != null) {
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
line = bufferedReader.readLine()
|
|
|
|
|
|
|
|
if (line == null) break;
|
|
|
|
log.addLast(line)
|
|
|
|
log.addLast(line)
|
|
|
|
if (log.size > maxLineCount) log.removeFirst()
|
|
|
|
if (log.size > maxLineCount) log.removeFirst()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,17 +69,15 @@ open class AndroidBugReporter @Inject constructor(@AppContext private val contex
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Captures a bug report and saves it to a file in the SD card.
|
|
|
|
* Captures a bug report and saves it to a file in the SD card.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The contents of the file are generated by the method [ ][.getBugReport]. The file is saved
|
|
|
|
* The contents of the file are generated by the method [ ][.getBugReport]. The file is saved in the apps's external private
|
|
|
|
* in the apps's external private storage.
|
|
|
|
* storage.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return the generated file.
|
|
|
|
* @return the generated file.
|
|
|
|
* @throws IOException when I/O errors occur.
|
|
|
|
* @throws IOException when I/O errors occur.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
fun dumpBugReportToFile() {
|
|
|
|
fun dumpBugReportToFile() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
val date = SimpleDateFormat("yyyy-MM-dd HHmmss", Locale.US).format(
|
|
|
|
val date = SimpleDateFormat("yyyy-MM-dd HHmmss", Locale.US).format(Date())
|
|
|
|
Date())
|
|
|
|
|
|
|
|
val dir = AndroidDirFinder(context).getFilesDir("Logs")
|
|
|
|
val dir = AndroidDirFinder(context).getFilesDir("Logs")
|
|
|
|
?: throw IOException("log dir should not be null")
|
|
|
|
?: throw IOException("log dir should not be null")
|
|
|
|
val logFile = File(String.format("%s/Log %s.txt", dir.path, date))
|
|
|
|
val logFile = File(String.format("%s/Log %s.txt", dir.path, date))
|
|
|
|