Collect both STDOUT and STDERR for logs
This commit is contained in:
parent
4496f82d5b
commit
a2a3c7f438
@ -24,6 +24,8 @@ import com.topjohnwu.magisk.utils.*
|
|||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import me.tatarka.bindingcollectionadapter2.ItemBinding
|
import me.tatarka.bindingcollectionadapter2.ItemBinding
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.Collections
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class FlashViewModel(
|
class FlashViewModel(
|
||||||
action: String,
|
action: String,
|
||||||
@ -42,30 +44,36 @@ class FlashViewModel(
|
|||||||
itemBinding.bindExtra(BR.viewModel, this@FlashViewModel)
|
itemBinding.bindExtra(BR.viewModel, this@FlashViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val rawItems = ObservableArrayList<String>()
|
private val outItems = object : ObservableArrayList<String>() {
|
||||||
private val logItems = ObservableArrayList<String>()
|
override fun add(element: String?): Boolean {
|
||||||
|
if (element != null)
|
||||||
|
logItems.add(element)
|
||||||
|
return super.add(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private val logItems = Collections.synchronizedList(ArrayList<String>())
|
||||||
|
|
||||||
init {
|
init {
|
||||||
rawItems.sendUpdatesTo(items) { it.map { ConsoleRvItem(it) } }
|
outItems.sendUpdatesTo(items) { it.map { ConsoleRvItem(it) } }
|
||||||
|
|
||||||
state = State.LOADING
|
state = State.LOADING
|
||||||
|
|
||||||
val uri = uri ?: Uri.EMPTY
|
val uri = uri ?: Uri.EMPTY
|
||||||
when (action) {
|
when (action) {
|
||||||
Const.Value.FLASH_ZIP -> Flashing
|
Const.Value.FLASH_ZIP -> Flashing
|
||||||
.Install(uri, rawItems, logItems, this)
|
.Install(uri, outItems, logItems, this)
|
||||||
.exec()
|
.exec()
|
||||||
Const.Value.UNINSTALL -> Flashing
|
Const.Value.UNINSTALL -> Flashing
|
||||||
.Uninstall(uri, rawItems, logItems, this)
|
.Uninstall(uri, outItems, logItems, this)
|
||||||
.exec()
|
.exec()
|
||||||
Const.Value.FLASH_MAGISK -> Patching
|
Const.Value.FLASH_MAGISK -> Patching
|
||||||
.Direct(rawItems, logItems, this)
|
.Direct(outItems, logItems, this)
|
||||||
.exec()
|
.exec()
|
||||||
Const.Value.FLASH_INACTIVE_SLOT -> Patching
|
Const.Value.FLASH_INACTIVE_SLOT -> Patching
|
||||||
.SecondSlot(rawItems, logItems, this)
|
.SecondSlot(outItems, logItems, this)
|
||||||
.exec()
|
.exec()
|
||||||
Const.Value.PATCH_FILE -> Patching
|
Const.Value.PATCH_FILE -> Patching
|
||||||
.File(uri, rawItems, logItems, this)
|
.File(uri, outItems, logItems, this)
|
||||||
.exec()
|
.exec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,16 +98,12 @@ class FlashViewModel(
|
|||||||
.map { Const.MAGISK_INSTALL_LOG_FILENAME.format(it) }
|
.map { Const.MAGISK_INSTALL_LOG_FILENAME.format(it) }
|
||||||
.map { File(Const.EXTERNAL_PATH, it) }
|
.map { File(Const.EXTERNAL_PATH, it) }
|
||||||
.map { file ->
|
.map { file ->
|
||||||
val log = items.filterIsInstance<ConsoleRvItem>()
|
file.bufferedWriter().use { writer ->
|
||||||
.joinToString("\n") { it.item }
|
logItems.forEach {
|
||||||
file.writeText(log)
|
writer.write(it)
|
||||||
|
writer.newLine()
|
||||||
val rawLog = logItems.toList().joinToString("\n")
|
}
|
||||||
if (rawLog.isNotBlank()) {
|
|
||||||
file.appendText("\n=== LOG ===\n")
|
|
||||||
file.appendText(rawLog)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file.path
|
file.path
|
||||||
}
|
}
|
||||||
.subscribeK { SnackbarEvent(it).publish() }
|
.subscribeK { SnackbarEvent(it).publish() }
|
||||||
|
Loading…
Reference in New Issue
Block a user