Loading app/core/src/main/java/com/fsck/k9/CoreKoinModules.kt +3 −1 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import com.fsck.k9.controller.push.controllerPushModule import com.fsck.k9.crypto.openPgpModule import com.fsck.k9.helper.helperModule import com.fsck.k9.job.jobModule import com.fsck.k9.logging.loggingModule import com.fsck.k9.mailstore.mailStoreModule import com.fsck.k9.message.extractors.extractorModule import com.fsck.k9.message.html.htmlModule Loading @@ -32,5 +33,6 @@ val coreModules = listOf( helperModule, preferencesModule, connectivityModule, powerModule powerModule, loggingModule ) app/core/src/main/java/com/fsck/k9/controller/ProgressBodyFactory.java +1 −3 Original line number Diff line number Diff line Loading @@ -21,10 +21,8 @@ class ProgressBodyFactory extends DefaultBodyFactory { @Override protected void copyData(InputStream inputStream, OutputStream outputStream) throws IOException { final CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream); Timer timer = new Timer(); try { try (CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream)) { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Loading app/core/src/main/java/com/fsck/k9/logging/KoinModule.kt 0 → 100644 +8 −0 Original line number Diff line number Diff line package com.fsck.k9.logging import org.koin.dsl.module val loggingModule = module { factory<ProcessExecutor> { RealProcessExecutor() } factory<LogFileWriter> { LogcatLogFileWriter(contentResolver = get(), processExecutor = get()) } } app/core/src/main/java/com/fsck/k9/logging/LogFileWriter.kt 0 → 100644 +38 −0 Original line number Diff line number Diff line package com.fsck.k9.logging import android.content.ContentResolver import android.net.Uri import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.commons.io.IOUtils import timber.log.Timber interface LogFileWriter { suspend fun writeLogTo(contentUri: Uri) } class LogcatLogFileWriter( private val contentResolver: ContentResolver, private val processExecutor: ProcessExecutor, private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO ) : LogFileWriter { override suspend fun writeLogTo(contentUri: Uri) { return withContext(coroutineDispatcher) { writeLogBlocking(contentUri) } } private fun writeLogBlocking(contentUri: Uri) { Timber.v("Writing logcat output to content URI: %s", contentUri) val outputStream = contentResolver.openOutputStream(contentUri) ?: error("Error opening contentUri for writing") outputStream.use { processExecutor.exec("logcat -d").use { inputStream -> IOUtils.copy(inputStream, outputStream) } } } } app/core/src/main/java/com/fsck/k9/logging/ProcessExecutor.kt 0 → 100644 +14 −0 Original line number Diff line number Diff line package com.fsck.k9.logging import java.io.InputStream interface ProcessExecutor { fun exec(command: String): InputStream } class RealProcessExecutor : ProcessExecutor { override fun exec(command: String): InputStream { val process = Runtime.getRuntime().exec(command) return process.inputStream } } Loading
app/core/src/main/java/com/fsck/k9/CoreKoinModules.kt +3 −1 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import com.fsck.k9.controller.push.controllerPushModule import com.fsck.k9.crypto.openPgpModule import com.fsck.k9.helper.helperModule import com.fsck.k9.job.jobModule import com.fsck.k9.logging.loggingModule import com.fsck.k9.mailstore.mailStoreModule import com.fsck.k9.message.extractors.extractorModule import com.fsck.k9.message.html.htmlModule Loading @@ -32,5 +33,6 @@ val coreModules = listOf( helperModule, preferencesModule, connectivityModule, powerModule powerModule, loggingModule )
app/core/src/main/java/com/fsck/k9/controller/ProgressBodyFactory.java +1 −3 Original line number Diff line number Diff line Loading @@ -21,10 +21,8 @@ class ProgressBodyFactory extends DefaultBodyFactory { @Override protected void copyData(InputStream inputStream, OutputStream outputStream) throws IOException { final CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream); Timer timer = new Timer(); try { try (CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream)) { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Loading
app/core/src/main/java/com/fsck/k9/logging/KoinModule.kt 0 → 100644 +8 −0 Original line number Diff line number Diff line package com.fsck.k9.logging import org.koin.dsl.module val loggingModule = module { factory<ProcessExecutor> { RealProcessExecutor() } factory<LogFileWriter> { LogcatLogFileWriter(contentResolver = get(), processExecutor = get()) } }
app/core/src/main/java/com/fsck/k9/logging/LogFileWriter.kt 0 → 100644 +38 −0 Original line number Diff line number Diff line package com.fsck.k9.logging import android.content.ContentResolver import android.net.Uri import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.commons.io.IOUtils import timber.log.Timber interface LogFileWriter { suspend fun writeLogTo(contentUri: Uri) } class LogcatLogFileWriter( private val contentResolver: ContentResolver, private val processExecutor: ProcessExecutor, private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO ) : LogFileWriter { override suspend fun writeLogTo(contentUri: Uri) { return withContext(coroutineDispatcher) { writeLogBlocking(contentUri) } } private fun writeLogBlocking(contentUri: Uri) { Timber.v("Writing logcat output to content URI: %s", contentUri) val outputStream = contentResolver.openOutputStream(contentUri) ?: error("Error opening contentUri for writing") outputStream.use { processExecutor.exec("logcat -d").use { inputStream -> IOUtils.copy(inputStream, outputStream) } } } }
app/core/src/main/java/com/fsck/k9/logging/ProcessExecutor.kt 0 → 100644 +14 −0 Original line number Diff line number Diff line package com.fsck.k9.logging import java.io.InputStream interface ProcessExecutor { fun exec(command: String): InputStream } class RealProcessExecutor : ProcessExecutor { override fun exec(command: String): InputStream { val process = Runtime.getRuntime().exec(command) return process.inputStream } }