feat: Support customize output apk signing levels

This commit is contained in:
Kofua 2024-04-19 00:56:00 +08:00
parent 6558aafbf1
commit cd01494874
No known key found for this signature in database
GPG Key ID: 0E62608F7E5CAD81

View File

@ -12,6 +12,7 @@ import app.revanced.patcher.PatcherConfig
import kotlinx.coroutines.runBlocking
import picocli.CommandLine
import picocli.CommandLine.Help.Visibility.ALWAYS
import picocli.CommandLine.ITypeConverter
import picocli.CommandLine.Model.CommandSpec
import picocli.CommandLine.Spec
import java.io.File
@ -228,6 +229,14 @@ internal object PatchCommand : Runnable {
this.aaptBinaryPath = aaptBinaryPath
}
@CommandLine.Option(
names = ["--signing-levels"],
description = ["Output apk signing levels, eg. \"1,2,3\", empty as default."],
converter = [SigningLevelsConverter::class],
arity = "0..1",
)
private var signingLevels = setOf<Int>()
override fun run() {
// region Setup
@ -318,6 +327,9 @@ internal object PatchCommand : Runnable {
patcherResult.applyTo(this)
}.let { patchedApkFile ->
if (!mount) {
val signingLevels = signingLevels.ifEmpty {
ApkUtils.readSigningLevels(apk)
}
ApkUtils.signApk(
patchedApkFile,
outputFilePath,
@ -328,6 +340,7 @@ internal object PatchCommand : Runnable {
keyStoreEntryAlias,
keyStoreEntryPassword,
),
signingLevels,
)
} else {
patchedApkFile.copyTo(outputFilePath, overwrite = true)
@ -418,4 +431,10 @@ internal object PatchCommand : Runnable {
}
logger.info(result)
}
private class SigningLevelsConverter : ITypeConverter<Set<Int>> {
override fun convert(value: String): Set<Int> {
return value.split(',').map { it.trim().toInt() }.toSet()
}
}
}