From a996482423c7d25cde27a5d8d9545a0052faccdc Mon Sep 17 00:00:00 2001 From: laur Date: Sat, 19 Apr 2025 19:00:42 +0200 Subject: [PATCH 1/4] feat: make patch cmd --mount opt dependent on -i - make using --mount option in 'patch' command require the inclusion of -i/--install option. - as it stands, if -i is not provided, then --mount flag is really not toggling the installation and user is left oblivious whether the patched apk is being installed or not --- .../app/revanced/cli/command/PatchCommand.kt | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index efbc7552..6471711e 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -90,6 +90,28 @@ internal object PatchCommand : Runnable { } } + @ArgGroup(exclusive = false, multiplicity = "0..1") + internal var install: InstallType? = null + + internal class InstallType { + @CommandLine.Option( + names = ["-i", "--install"], + required = true, + description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."], + fallbackValue = "", // empty string to indicate that the first connected device should be used. + arity = "0..1", + ) + internal var deviceSerial: String? = null + + @CommandLine.Option( + names = ["--mount"], + required = false, + description = ["Install the patched APK file by mounting."], + showDefaultValue = ALWAYS, + ) + internal var mount: Boolean = false + } + @CommandLine.Option( names = ["--exclusive"], description = ["Disable all patches except the ones enabled."], @@ -115,22 +137,6 @@ internal object PatchCommand : Runnable { this.outputFilePath = outputFilePath?.absoluteFile } - @CommandLine.Option( - names = ["-i", "--install"], - description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."], - // Empty string to indicate that the first connected device should be used. - fallbackValue = "", - arity = "0..1", - ) - private var deviceSerial: String? = null - - @CommandLine.Option( - names = ["--mount"], - description = ["Install the patched APK file by mounting."], - showDefaultValue = ALWAYS, - ) - private var mount: Boolean = false - @CommandLine.Option( names = ["--keystore"], description = [ @@ -245,11 +251,11 @@ internal object PatchCommand : Runnable { keyStoreFilePath ?: outputFilePath.parentFile .resolve("${outputFilePath.nameWithoutExtension}.keystore") - val installer = if (deviceSerial != null) { - val deviceSerial = deviceSerial!!.ifEmpty { null } + val installer = if (install?.deviceSerial != null) { + val deviceSerial = install?.deviceSerial!!.ifEmpty { null } try { - if (mount) { + if (install?.mount ?: false) { AdbRootInstaller(deviceSerial) } else { AdbInstaller(deviceSerial) @@ -332,7 +338,7 @@ internal object PatchCommand : Runnable { apk.copyTo(temporaryFilesPath.resolve(apk.name), overwrite = true).apply { patcherResult.applyTo(this) }.let { patchedApkFile -> - if (!mount) { + if (!(install?.mount ?: false)) { ApkUtils.signApk( patchedApkFile, outputFilePath, @@ -355,7 +361,7 @@ internal object PatchCommand : Runnable { // region Install. - deviceSerial?.let { + install?.deviceSerial?.let { runBlocking { when (val result = installer!!.install(Installer.Apk(outputFilePath, packageName))) { RootInstallerResult.FAILURE -> logger.severe("Failed to mount the patched APK file") From 68b431b09c0394bd393fda8603e2b7e4672527ae Mon Sep 17 00:00:00 2001 From: laur Date: Sun, 20 Apr 2025 23:30:12 +0200 Subject: [PATCH 2/4] address review --- .../app/revanced/cli/command/PatchCommand.kt | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index 6471711e..28516f6b 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -90,28 +90,6 @@ internal object PatchCommand : Runnable { } } - @ArgGroup(exclusive = false, multiplicity = "0..1") - internal var install: InstallType? = null - - internal class InstallType { - @CommandLine.Option( - names = ["-i", "--install"], - required = true, - description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."], - fallbackValue = "", // empty string to indicate that the first connected device should be used. - arity = "0..1", - ) - internal var deviceSerial: String? = null - - @CommandLine.Option( - names = ["--mount"], - required = false, - description = ["Install the patched APK file by mounting."], - showDefaultValue = ALWAYS, - ) - internal var mount: Boolean = false - } - @CommandLine.Option( names = ["--exclusive"], description = ["Disable all patches except the ones enabled."], @@ -137,6 +115,28 @@ internal object PatchCommand : Runnable { this.outputFilePath = outputFilePath?.absoluteFile } + @ArgGroup(exclusive = false, multiplicity = "0..1") + internal var installation: Installation? = null + + internal class Installation { + @CommandLine.Option( + names = ["-i", "--install"], + required = true, + description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."], + fallbackValue = "", // Empty string to indicate that the first connected device should be used. + arity = "0..1", + ) + internal var deviceSerial: String? = null + + @CommandLine.Option( + names = ["--mount"], + required = false, + description = ["Install the patched APK file by mounting."], + showDefaultValue = ALWAYS, + ) + internal var mount: Boolean = false + } + @CommandLine.Option( names = ["--keystore"], description = [ @@ -251,11 +251,11 @@ internal object PatchCommand : Runnable { keyStoreFilePath ?: outputFilePath.parentFile .resolve("${outputFilePath.nameWithoutExtension}.keystore") - val installer = if (install?.deviceSerial != null) { - val deviceSerial = install?.deviceSerial!!.ifEmpty { null } + val installer = if (installation?.deviceSerial != null) { + val deviceSerial = installation?.deviceSerial!!.ifEmpty { null } try { - if (install?.mount ?: false) { + if (installation?.mount ?: false) { AdbRootInstaller(deviceSerial) } else { AdbInstaller(deviceSerial) @@ -338,7 +338,7 @@ internal object PatchCommand : Runnable { apk.copyTo(temporaryFilesPath.resolve(apk.name), overwrite = true).apply { patcherResult.applyTo(this) }.let { patchedApkFile -> - if (!(install?.mount ?: false)) { + if (installation?.mount != true) { ApkUtils.signApk( patchedApkFile, outputFilePath, @@ -361,7 +361,7 @@ internal object PatchCommand : Runnable { // region Install. - install?.deviceSerial?.let { + installation?.deviceSerial?.let { runBlocking { when (val result = installer!!.install(Installer.Apk(outputFilePath, packageName))) { RootInstallerResult.FAILURE -> logger.severe("Failed to mount the patched APK file") From 683bb5f1be7659f11244694efa1eecb1097297fc Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 21 Apr 2025 01:05:38 +0200 Subject: [PATCH 3/4] Apply suggestions from code review --- src/main/kotlin/app/revanced/cli/command/PatchCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index 28516f6b..f51c29b8 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -255,7 +255,7 @@ internal object PatchCommand : Runnable { val deviceSerial = installation?.deviceSerial!!.ifEmpty { null } try { - if (installation?.mount ?: false) { + if (installation?.mount == true) { AdbRootInstaller(deviceSerial) } else { AdbInstaller(deviceSerial) From 5c7688f3e01f4e9bc0d5f740b9dccfbbc2d74206 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 21 Apr 2025 01:06:42 +0200 Subject: [PATCH 4/4] Apply suggestions from code review --- src/main/kotlin/app/revanced/cli/command/PatchCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index f51c29b8..ba6b0440 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -123,7 +123,7 @@ internal object PatchCommand : Runnable { names = ["-i", "--install"], required = true, description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."], - fallbackValue = "", // Empty string to indicate that the first connected device should be used. + fallbackValue = "", // Empty string is used to select the first of connected devices. arity = "0..1", ) internal var deviceSerial: String? = null