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.devtools)
alias(libs.plugins.about.libraries) alias(libs.plugins.about.libraries)
id("kotlin-parcelize") id("kotlin-parcelize")
kotlin("plugin.serialization") version "1.8.22" kotlin("plugin.serialization") version "1.9.0"
} }
android { android {

View File

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

View File

@ -1,7 +1,6 @@
package app.revanced.manager.patcher.patch package app.revanced.manager.patcher.patch
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import app.revanced.manager.patcher.PatchClass
import app.revanced.patcher.annotation.Package import app.revanced.patcher.annotation.Package
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.dependencies 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.include
import app.revanced.patcher.extensions.PatchExtensions.options import app.revanced.patcher.extensions.PatchExtensions.options
import app.revanced.patcher.extensions.PatchExtensions.patchName import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.patch.PatchClass
import app.revanced.patcher.patch.PatchOption import app.revanced.patcher.patch.PatchOption
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList 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.Session
import app.revanced.manager.patcher.aapt.Aapt import app.revanced.manager.patcher.aapt.Aapt
import app.revanced.manager.ui.model.SelectedApp 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.Options
import app.revanced.manager.util.PM import app.revanced.manager.util.PM
import app.revanced.manager.util.PatchesSelection import app.revanced.manager.util.PatchesSelection
@ -57,7 +58,7 @@ class PatcherWorker(
val packageName: String, val packageName: String,
val packageVersion: String, val packageVersion: String,
val progress: MutableStateFlow<ImmutableList<Step>>, val progress: MutableStateFlow<ImmutableList<Step>>,
val logger: Logger val logger: ManagerLogger
) )
companion object { 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.PM
import app.revanced.manager.util.tag import app.revanced.manager.util.tag
import app.revanced.manager.util.toast import app.revanced.manager.util.toast
import app.revanced.patcher.logging.Logger
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -45,6 +44,8 @@ import org.koin.core.component.inject
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
import java.util.UUID import java.util.UUID
import java.util.logging.Level
import java.util.logging.LogRecord
@Stable @Stable
class InstallerViewModel(input: Destination.Installer) : ViewModel(), KoinComponent { 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 val logs = mutableListOf<Pair<LogLevel, String>>()
private fun log(level: LogLevel, msg: String) { private fun log(level: LogLevel, msg: String) {
level.androidLog(msg) level.androidLog(msg)
@ -218,10 +220,25 @@ private class ManagerLogger : Logger {
fun export() = fun export() =
logs.asSequence().map { (level, msg) -> "[${level.name}]: $msg" }.joinToString("\n") logs.asSequence().map { (level, msg) -> "[${level.name}]: $msg" }.joinToString("\n")
override fun trace(msg: String) = log(LogLevel.TRACE, msg) fun trace(msg: String) = log(LogLevel.TRACE, msg)
override fun info(msg: String) = log(LogLevel.INFO, msg) fun info(msg: String) = log(LogLevel.INFO, msg)
override fun warn(msg: String) = log(LogLevel.WARN, msg) fun warn(msg: String) = log(LogLevel.WARN, msg)
override fun error(msg: String) = log(LogLevel.ERROR, 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 { enum class LogLevel {

View File

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