Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support customize output apk signing levels #329

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
}
Loading