chore: bump kotlinx.serialization plugin and patcher

This commit is contained in:
Ax333l 2023-09-01 10:50:13 +02:00
parent c0badbe96b
commit eeae46a415
7 changed files with 62 additions and 42 deletions

View file

@ -4,7 +4,7 @@ plugins {
alias(libs.plugins.devtools)
alias(libs.plugins.about.libraries)
id("kotlin-parcelize")
kotlin("plugin.serialization") version "1.8.22"
kotlin("plugin.serialization") version "1.9.0"
}
android {

View file

@ -1,25 +1,25 @@
package app.revanced.manager.patcher
import app.revanced.manager.ui.viewmodel.ManagerLogger
import app.revanced.patcher.Patcher
import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.data.Context
import app.revanced.patcher.logging.Logger
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.PatchClass
import app.revanced.patcher.patch.PatchResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.Closeable
import java.io.File
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.util.logging.Logger
internal typealias PatchClass = Class<out Patch<Context>>
internal typealias PatchList = List<PatchClass>
class Session(
cacheDir: String,
frameworkDir: String,
aaptPath: String,
private val logger: Logger,
private val logger: ManagerLogger,
private val input: File,
private val onStepSucceeded: suspend () -> Unit
) : Closeable {
@ -27,35 +27,39 @@ class Session(
private val patcher = Patcher(
PatcherOptions(
inputFile = input,
resourceCacheDirectory = temporary.resolve("aapt-resources").path,
frameworkDirectory = frameworkDir,
aaptPath = aaptPath,
logger = logger,
resourceCachePath = temporary.resolve("aapt-resources"),
frameworkFileDirectory = frameworkDir,
aaptBinaryPath = aaptPath
)
)
private suspend fun Patcher.applyPatchesVerbose() {
this.executePatches(true).forEach { (patch, result) ->
if (result.isSuccess) {
this.apply(true).collect { (patch, exception) ->
if (exception == null) {
logger.info("$patch succeeded")
onStepSucceeded()
return@forEach
return@collect
}
logger.error("$patch failed:")
result.exceptionOrNull()!!.let {
logger.error(result.exceptionOrNull()!!.stackTraceToString())
throw it
}
logger.error(exception.stackTraceToString())
throw exception
}
}
suspend fun run(output: File, selectedPatches: PatchList, integrations: List<File>) {
onStepSucceeded() // Unpacking
Logger.getLogger("").apply {
handlers.forEach {
it.close()
removeHandler(it)
}
addHandler(logger)
}
with(patcher) {
logger.info("Merging integrations")
addIntegrations(integrations) {}
addPatches(selectedPatches)
acceptIntegrations(integrations)
acceptPatches(selectedPatches)
onStepSucceeded() // Merging
logger.info("Applying patches...")
@ -63,7 +67,7 @@ class Session(
}
logger.info("Writing patched files...")
val result = patcher.save()
val result = patcher.get()
val aligned = temporary.resolve("aligned.apk").also { Aligning.align(result, input, it) }
@ -77,5 +81,11 @@ class Session(
override fun close() {
temporary.delete()
patcher.close()
}
companion object {
operator fun PatchResult.component1() = patchName
operator fun PatchResult.component2() = exception
}
}

View file

@ -1,24 +1,16 @@
package app.revanced.manager.patcher.patch
import android.util.Log
import app.revanced.manager.patcher.PatchClass
import app.revanced.manager.util.tag
import app.revanced.patcher.Patcher
import app.revanced.patcher.PatchBundleLoader
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.util.patch.PatchBundle
import dalvik.system.PathClassLoader
import app.revanced.patcher.patch.PatchClass
import java.io.File
class PatchBundle(private val loader: Iterable<PatchClass>, val integrations: File?) {
constructor(bundleJar: File, integrations: File?) : this(
object : Iterable<PatchClass> {
private fun load(): List<PatchClass> {
val path = bundleJar.absolutePath
return PatchBundle.Dex(
path,
PathClassLoader(path, Patcher::class.java.classLoader)
).loadPatches()
}
private fun load(): List<PatchClass> = PatchBundleLoader.Dex(bundleJar)
override fun iterator() = load().iterator()
},

View file

@ -1,7 +1,6 @@
package app.revanced.manager.patcher.patch
import androidx.compose.runtime.Immutable
import app.revanced.manager.patcher.PatchClass
import app.revanced.patcher.annotation.Package
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.dependencies
@ -9,6 +8,7 @@ import app.revanced.patcher.extensions.PatchExtensions.description
import app.revanced.patcher.extensions.PatchExtensions.include
import app.revanced.patcher.extensions.PatchExtensions.options
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.patch.PatchClass
import app.revanced.patcher.patch.PatchOption
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

View file

@ -22,6 +22,7 @@ import app.revanced.manager.domain.worker.WorkerRepository
import app.revanced.manager.patcher.Session
import app.revanced.manager.patcher.aapt.Aapt
import app.revanced.manager.ui.model.SelectedApp
import app.revanced.manager.ui.viewmodel.ManagerLogger
import app.revanced.manager.util.Options
import app.revanced.manager.util.PM
import app.revanced.manager.util.PatchesSelection
@ -57,7 +58,7 @@ class PatcherWorker(
val packageName: String,
val packageVersion: String,
val progress: MutableStateFlow<ImmutableList<Step>>,
val logger: Logger
val logger: ManagerLogger
)
companion object {

View file

@ -32,7 +32,6 @@ import app.revanced.manager.ui.destination.Destination
import app.revanced.manager.util.PM
import app.revanced.manager.util.tag
import app.revanced.manager.util.toast
import app.revanced.patcher.logging.Logger
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers
@ -45,6 +44,8 @@ import org.koin.core.component.inject
import java.io.File
import java.nio.file.Files
import java.util.UUID
import java.util.logging.Level
import java.util.logging.LogRecord
@Stable
class InstallerViewModel(input: Destination.Installer) : ViewModel(), KoinComponent {
@ -207,7 +208,8 @@ class InstallerViewModel(input: Destination.Installer) : ViewModel(), KoinCompon
}
}
private class ManagerLogger : Logger {
// TODO: move this to a better place
class ManagerLogger : java.util.logging.Handler() {
private val logs = mutableListOf<Pair<LogLevel, String>>()
private fun log(level: LogLevel, msg: String) {
level.androidLog(msg)
@ -218,10 +220,25 @@ private class ManagerLogger : Logger {
fun export() =
logs.asSequence().map { (level, msg) -> "[${level.name}]: $msg" }.joinToString("\n")
override fun trace(msg: String) = log(LogLevel.TRACE, msg)
override fun info(msg: String) = log(LogLevel.INFO, msg)
override fun warn(msg: String) = log(LogLevel.WARN, msg)
override fun error(msg: String) = log(LogLevel.ERROR, msg)
fun trace(msg: String) = log(LogLevel.TRACE, msg)
fun info(msg: String) = log(LogLevel.INFO, msg)
fun warn(msg: String) = log(LogLevel.WARN, msg)
fun error(msg: String) = log(LogLevel.ERROR, msg)
override fun publish(record: LogRecord) {
val msg = record.message
val fn = when (record.level) {
Level.INFO -> ::info
Level.SEVERE -> ::error
Level.WARNING -> ::warn
else -> ::trace
}
fn(msg)
}
override fun flush() = Unit
override fun close() = Unit
}
enum class LogLevel {

View file

@ -11,7 +11,7 @@ accompanist = "0.30.1"
serialization = "1.6.0"
collection = "0.3.5"
room-version = "2.5.2"
patcher = "12.1.1"
patcher = "14.2.1"
apksign = "8.1.1"
bcpkix-jdk18on = "1.76"
koin-version = "3.4.2"
@ -19,7 +19,7 @@ koin-version-compose = "3.4.5"
reimagined-navigation = "1.4.0"
ktor = "2.3.2"
markdown = "0.4.1"
androidGradlePlugin = "8.1.1"
androidGradlePlugin = "8.0.2"
kotlinGradlePlugin = "1.9.0"
devToolsGradlePlugin = "1.9.0-1.0.12"
aboutLibrariesGradlePlugin = "10.8.2"