Skip to content

Commit 3cfe745

Browse files
1fexdoSumAtrIX
andauthored
feat: Add Change version code patch (#3338)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 550ac09 commit 3cfe745

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

api/revanced-patches.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ public final class app/revanced/patches/all/misc/transformation/IMethodCall$Defa
105105
public static fun replaceInvokeVirtualWithIntegrations (Lapp/revanced/patches/all/misc/transformation/IMethodCall;Ljava/lang/String;Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Lcom/android/tools/smali/dexlib2/iface/instruction/formats/Instruction35c;I)V
106106
}
107107

108+
public final class app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch : app/revanced/patcher/patch/ResourcePatch {
109+
public static final field INSTANCE Lapp/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch;
110+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
111+
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
112+
}
113+
108114
public final class app/revanced/patches/all/screencapture/removerestriction/RemoveCaptureRestrictionPatch : app/revanced/patches/all/misc/transformation/BaseTransformInstructionsPatch {
109115
public static final field INSTANCE Lapp/revanced/patches/all/screencapture/removerestriction/RemoveCaptureRestrictionPatch;
110116
public synthetic fun filterMap (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;I)Ljava/lang/Object;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package app.revanced.patches.all.misc.versioncode
2+
3+
import app.revanced.patcher.data.ResourceContext
4+
import app.revanced.patcher.patch.ResourcePatch
5+
import app.revanced.patcher.patch.annotation.Patch
6+
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.intPatchOption
7+
import app.revanced.util.getNode
8+
import org.w3c.dom.Element
9+
10+
@Patch(
11+
name = "Change version code",
12+
description = "Changes the version code of the app. By default the highest version code is set. " +
13+
"This allows older versions of an app to be installed " +
14+
"if their version code is set to the same or a higher value and can stop app stores to update the app.",
15+
use = false,
16+
)
17+
@Suppress("unused")
18+
object ChangeVersionCodePatch : ResourcePatch() {
19+
private val versionCode by intPatchOption(
20+
key = "versionCode",
21+
default = Int.MAX_VALUE,
22+
values = mapOf(
23+
"Lowest" to 1,
24+
"Highest" to Int.MAX_VALUE,
25+
),
26+
title = "Version code",
27+
description = "The version code to use",
28+
required = true,
29+
) {
30+
it!! >= 1
31+
}
32+
33+
override fun execute(context: ResourceContext) {
34+
context.document["AndroidManifest.xml"].use { document ->
35+
val manifestElement = document.getNode("manifest") as Element
36+
manifestElement.setAttribute("android:versionCode", "$versionCode")
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)