Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2dc1c0c7 authored by Romain Hunault's avatar Romain Hunault 💻
Browse files

Merge branch 'release-5.905' into import_update_5.9051

parents 91737b16 a5fa2ddc
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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
@@ -32,5 +33,6 @@ val coreModules = listOf(
    helperModule,
    preferencesModule,
    connectivityModule,
    powerModule
    powerModule,
    loggingModule
)
+1 −3
Original line number Diff line number Diff line
@@ -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() {
+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()) }
}
+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)
            }
        }
    }
}
+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