Skip to content

Commit

Permalink
feat: Support customize output apk signing levels
Browse files Browse the repository at this point in the history
  • Loading branch information
zjns committed Apr 18, 2024
1 parent 6558aaf commit cd01494
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/app/revanced/cli/command/PatchCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -328,6 +340,7 @@ internal object PatchCommand : Runnable {
keyStoreEntryAlias,
keyStoreEntryPassword,
),
signingLevels,
)
} else {
patchedApkFile.copyTo(outputFilePath, overwrite = true)
Expand Down Expand Up @@ -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()
}
}
}

0 comments on commit cd01494

Please sign in to comment.