diff --git a/api/android/revanced-library.api b/api/android/revanced-library.api index 9f89984..9233cad 100644 --- a/api/android/revanced-library.api +++ b/api/android/revanced-library.api @@ -104,13 +104,10 @@ public final class app/revanced/library/PatchUtils$Json { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch : app/revanced/library/PatchUtils$Json$JsonPatch { public static final field Companion Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$Companion; public final fun getCompatiblePackages ()Ljava/util/Set; - public final fun getDependencies ()Ljava/util/Set; public final fun getDescription ()Ljava/lang/String; public final fun getName ()Ljava/lang/String; public final fun getOptions ()Ljava/util/Map; - public final fun getRequiresIntegrations ()Z public final fun getUse ()Z - public final fun setRequiresIntegrations (Z)V } public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$Companion { @@ -124,12 +121,12 @@ public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPa public final fun getKey ()Ljava/lang/String; public final fun getRequired ()Z public final fun getTitle ()Ljava/lang/String; - public final fun getValueType ()Ljava/lang/String; + public final fun getType ()Lkotlin/reflect/KType; public final fun getValues ()Ljava/util/Map; } public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption$Companion { - public final fun fromPatchOption (Lapp/revanced/patcher/patch/options/PatchOption;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption; + public final fun fromPatchOption (Lapp/revanced/patcher/patch/Option;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption; } public abstract interface class app/revanced/library/PatchUtils$Json$JsonPatch { @@ -255,6 +252,10 @@ public final class app/revanced/library/installation/installer/AdbRootInstaller public synthetic fun (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V } +public final class app/revanced/library/installation/installer/DeviceNotFoundException : java/lang/Exception { + public fun ()V +} + public class app/revanced/library/installation/installer/Installation { public final fun getApkFilePath ()Ljava/lang/String; } diff --git a/api/jvm/revanced-library.api b/api/jvm/revanced-library.api index 5a525d9..739e443 100644 --- a/api/jvm/revanced-library.api +++ b/api/jvm/revanced-library.api @@ -104,13 +104,10 @@ public final class app/revanced/library/PatchUtils$Json { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch : app/revanced/library/PatchUtils$Json$JsonPatch { public static final field Companion Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$Companion; public final fun getCompatiblePackages ()Ljava/util/Set; - public final fun getDependencies ()Ljava/util/Set; public final fun getDescription ()Ljava/lang/String; public final fun getName ()Ljava/lang/String; public final fun getOptions ()Ljava/util/Map; - public final fun getRequiresIntegrations ()Z public final fun getUse ()Z - public final fun setRequiresIntegrations (Z)V } public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$Companion { @@ -124,12 +121,12 @@ public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPa public final fun getKey ()Ljava/lang/String; public final fun getRequired ()Z public final fun getTitle ()Ljava/lang/String; - public final fun getValueType ()Ljava/lang/String; + public final fun getType ()Lkotlin/reflect/KType; public final fun getValues ()Ljava/util/Map; } public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption$Companion { - public final fun fromPatchOption (Lapp/revanced/patcher/patch/options/PatchOption;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption; + public final fun fromPatchOption (Lapp/revanced/patcher/patch/Option;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption; } public abstract interface class app/revanced/library/PatchUtils$Json$JsonPatch { @@ -231,6 +228,10 @@ public final class app/revanced/library/installation/installer/AdbRootInstaller public synthetic fun (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V } +public final class app/revanced/library/installation/installer/DeviceNotFoundException : java/lang/Exception { + public fun ()V +} + public class app/revanced/library/installation/installer/Installation { public final fun getApkFilePath ()Ljava/lang/String; } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 03a7a0b..a7c7c9a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,11 @@ [versions] -jackson-module-kotlin = "2.15.0" +jackson-module-kotlin = "2.16.1" jadb = "1.2.1" -kotlin = "1.9.22" -revanced-patcher = "19.3.1" -binary-compatibility-validator = "0.14.0" -android = "8.3.0" -bcpkix-jdk15on = "1.70" -guava = "33.0.0-jre" +kotlin = "2.0.0" +kotlinx-coroutines = "1.8.1" +kotlinx-serialization = "1.7.1" libsu = "5.2.2" -core-ktx = "1.12.0" +revanced-patcher = "20.0.0" [libraries] jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" } diff --git a/src/commonMain/kotlin/app/revanced/library/Options.kt b/src/commonMain/kotlin/app/revanced/library/Options.kt index 2233d9e..98bd2f6 100644 --- a/src/commonMain/kotlin/app/revanced/library/Options.kt +++ b/src/commonMain/kotlin/app/revanced/library/Options.kt @@ -2,9 +2,8 @@ package app.revanced.library -import app.revanced.library.Options.Patch.Option -import app.revanced.patcher.PatchSet -import app.revanced.patcher.patch.options.PatchOptionException +import app.revanced.patcher.patch.OptionException +import app.revanced.patcher.patch.Patch import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import java.io.File import java.util.logging.Logger @@ -23,7 +22,7 @@ object Options { * @return The JSON string containing the options. */ fun serialize( - patches: PatchSet, + patches: Set>, prettyPrint: Boolean = false, ): String = patches @@ -35,12 +34,12 @@ object Options { val optionValue = try { option.value - } catch (e: PatchOptionException) { + } catch (e: OptionException) { logger.warning("Using default option value for the ${patch.name} patch: ${e.message}") option.default } - Option(option.key, optionValue) + Patch.Option(option.key, optionValue) }, ) } @@ -68,7 +67,7 @@ object Options { * * @param json The JSON string containing the options. */ - fun PatchSet.setOptions(json: String) { + fun Set>.setOptions(json: String) { filter { it.options.any() }.let { patches -> if (patches.isEmpty()) return @@ -82,7 +81,7 @@ object Options { jsonPatchOptions.forEach { (option, value) -> try { patch.options[option] = value - } catch (e: PatchOptionException) { + } catch (e: OptionException) { logger.warning("Could not set option value for the ${patch.name} patch: ${e.message}") } } @@ -97,7 +96,7 @@ object Options { * @param file The file containing the JSON string containing the options. * @see setOptions */ - fun PatchSet.setOptions(file: File) = setOptions(file.readText()) + fun Set>.setOptions(file: File) = setOptions(file.readText()) /** * Data class for a patch and its [Option]s. diff --git a/src/commonMain/kotlin/app/revanced/library/PatchUtils.kt b/src/commonMain/kotlin/app/revanced/library/PatchUtils.kt index fc26311..588620a 100644 --- a/src/commonMain/kotlin/app/revanced/library/PatchUtils.kt +++ b/src/commonMain/kotlin/app/revanced/library/PatchUtils.kt @@ -1,12 +1,12 @@ package app.revanced.library -import app.revanced.patcher.PatchSet +import app.revanced.patcher.patch.Option +import app.revanced.patcher.patch.Package import app.revanced.patcher.patch.Patch -import app.revanced.patcher.patch.options.PatchOption import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import java.io.InputStream import java.io.OutputStream -import kotlin.reflect.jvm.jvmName +import kotlin.reflect.KType typealias PackageName = String typealias Version = String @@ -29,31 +29,29 @@ object PatchUtils { * @return A map of package names to a map of versions to their count. */ fun getMostCommonCompatibleVersions( - patches: PatchSet, + patches: Set>, packageNames: Set? = null, countUnusedPatches: Boolean = false, ): PackageNameMap = buildMap { - fun filterWantedPackages(compatiblePackages: Iterable): Iterable { + fun filterWantedPackages(compatiblePackages: Iterable): Iterable { val wantedPackages = packageNames?.toHashSet() ?: return compatiblePackages - return compatiblePackages.filter { it.name in wantedPackages } + return compatiblePackages.filter { (name, _) -> name in wantedPackages } } patches .filter { it.use || countUnusedPatches } .flatMap { it.compatiblePackages ?: emptyList() } .let(::filterWantedPackages) - .forEach { compatiblePackage -> - if (compatiblePackage.versions?.isEmpty() == true) { + .forEach { (name, versions) -> + if (versions?.isEmpty() == true) { return@forEach } - val versionMap = getOrPut(compatiblePackage.name) { linkedMapOf() } + val versionMap = getOrPut(name) { linkedMapOf() } - compatiblePackage.versions?.let { versions -> - versions.forEach { version -> - versionMap[version] = versionMap.getOrDefault(version, 0) + 1 - } + versions?.forEach { version -> + versionMap[version] = versionMap.getOrDefault(version, 0) + 1 } } @@ -79,7 +77,7 @@ object PatchUtils { * @param outputStream The output stream to write the JSON to. */ fun serialize( - patches: PatchSet, + patches: Set>, transform: (Patch<*>) -> JsonPatch = { patch -> FullJsonPatch.fromPatch(patch) }, prettyPrint: Boolean = false, outputStream: OutputStream, @@ -119,10 +117,10 @@ object PatchUtils { class FullJsonPatch internal constructor( val name: String?, val description: String?, - val compatiblePackages: Set?, - val dependencies: Set?, + val compatiblePackages: Set?, + // Cannot serialize dependencies, because they are references to other patches and patch names are nullable. + // val dependencies: Set, val use: Boolean, - var requiresIntegrations: Boolean, val options: Map>, ) : JsonPatch { companion object { @@ -131,16 +129,15 @@ object PatchUtils { patch.name, patch.description, patch.compatiblePackages, - buildSet { patch.dependencies?.forEach { add(it.jvmName) } }, + // buildSet { patch.dependencies.forEach { add(it.name) } }, patch.use, - patch.requiresIntegrations, patch.options.mapValues { FullJsonPatchOption.fromPatchOption(it.value) }, ) } /** - * A JSON representation of a [PatchOption]. - * @see PatchOption + * A JSON representation of a [Option]. + * @see Option */ class FullJsonPatchOption internal constructor( val key: String, @@ -149,10 +146,10 @@ object PatchUtils { val title: String?, val description: String?, val required: Boolean, - val valueType: String, + val type: KType, ) { companion object { - fun fromPatchOption(option: PatchOption<*>) = + fun fromPatchOption(option: Option<*>) = FullJsonPatchOption( option.key, option.default, @@ -160,7 +157,7 @@ object PatchUtils { option.title, option.description, option.required, - option.valueType, + option.type, ) } } diff --git a/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt b/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt index df60d1b..aec0aa7 100644 --- a/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt +++ b/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt @@ -1,6 +1,6 @@ package app.revanced.library.installation.command -import app.revanced.library.installation.installer.Utils +import app.revanced.library.installation.installer.getDevice import se.vidstige.jadb.JadbDevice import se.vidstige.jadb.RemoteFile import java.io.File @@ -29,7 +29,7 @@ class AdbShellCommandRunner : ShellCommandRunner { * @param deviceSerial deviceSerial The device serial. If null, the first connected device will be used. */ internal constructor(deviceSerial: String?) { - device = Utils.getDevice(deviceSerial, logger) + device = getDevice(deviceSerial, logger) } override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process -> diff --git a/src/commonMain/kotlin/app/revanced/library/installation/installer/AdbInstaller.kt b/src/commonMain/kotlin/app/revanced/library/installation/installer/AdbInstaller.kt index 4358e64..c8e389c 100644 --- a/src/commonMain/kotlin/app/revanced/library/installation/installer/AdbInstaller.kt +++ b/src/commonMain/kotlin/app/revanced/library/installation/installer/AdbInstaller.kt @@ -17,7 +17,7 @@ import se.vidstige.jadb.managers.PackageManager class AdbInstaller( deviceSerial: String? = null, ) : Installer() { - private val device = Utils.getDevice(deviceSerial, logger) + private val device = getDevice(deviceSerial, logger) private val adbShellCommandRunner = AdbShellCommandRunner(device) private val packageManager = PackageManager(device) diff --git a/src/commonMain/kotlin/app/revanced/library/installation/installer/Utils.kt b/src/commonMain/kotlin/app/revanced/library/installation/installer/Utils.kt index 2082e95..3d0e890 100644 --- a/src/commonMain/kotlin/app/revanced/library/installation/installer/Utils.kt +++ b/src/commonMain/kotlin/app/revanced/library/installation/installer/Utils.kt @@ -4,37 +4,31 @@ import se.vidstige.jadb.JadbConnection import java.util.logging.Logger /** - * Utility functions for [Installer]. + * Gets the device with the given serial. * - * @see Installer + * @param deviceSerial The device serial. If null, the first connected device will be used. + * @param logger The logger. + * @return The device. + * @throws DeviceNotFoundException If no device with the given serial is found. */ -internal object Utils { - /** - * Gets the device with the given serial. - * - * @param deviceSerial The device serial. If null, the first connected device will be used. - * @param logger The logger. - * @return The device. - * @throws DeviceNotFoundException If no device with the given serial is found. - */ - internal fun getDevice( - deviceSerial: String? = null, - logger: Logger, - ) = with(JadbConnection().devices) { - if (isEmpty()) throw DeviceNotFoundException() +internal fun getDevice( + deviceSerial: String? = null, + logger: Logger, +) = with(JadbConnection().devices) { + if (isEmpty()) throw DeviceNotFoundException() - deviceSerial?.let { - firstOrNull { it.serial == deviceSerial } ?: throw DeviceNotFoundException( - deviceSerial, - ) - } ?: first().also { - logger.warning("No device serial supplied. Using device with serial ${it.serial}") - } - }!! + deviceSerial?.let { + firstOrNull { it.serial == deviceSerial } ?: throw DeviceNotFoundException( + deviceSerial, + ) + } ?: first().also { + logger.warning("No device serial supplied. Using device with serial ${it.serial}") + } +}!! - class DeviceNotFoundException internal constructor(deviceSerial: String? = null) : Exception( +class DeviceNotFoundException internal constructor(deviceSerial: String? = null) : + Exception( deviceSerial?.let { "The device with the ADB device serial \"$deviceSerial\" can not be found" } ?: "No ADB device found", ) -}