Skip to content

Commit 8452993

Browse files
author
Aunali321
committed
feat: Add patches, utils
1 parent 4270cc3 commit 8452993

47 files changed

Lines changed: 3427 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

local.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk.dir = /home/aun/Android/Sdk

patches/api/patches.api

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.

patches/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ patches {
1111
license = "GNU General Public License v3.0"
1212
}
1313
}
14+
15+
dependencies {
16+
compileOnly(project(":patches:stub"))
17+
}
18+
19+
kotlin {
20+
compilerOptions {
21+
freeCompilerArgs = listOf("-Xcontext-receivers")
22+
}
23+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package app.revanced.patches.all.misc.packagename
2+
3+
import app.revanced.patcher.patch.Option
4+
import app.revanced.patcher.patch.resourcePatch
5+
import app.revanced.patcher.patch.stringOption
6+
import org.w3c.dom.Element
7+
8+
lateinit var packageNameOption: Option<String>
9+
10+
/**
11+
* Set the package name to use.
12+
* If this is called multiple times, the first call will set the package name.
13+
*
14+
* @param fallbackPackageName The package name to use if the user has not already specified a package name.
15+
* @return The package name that was set.
16+
* @throws OptionException.ValueValidationException If the package name is invalid.
17+
*/
18+
fun setOrGetFallbackPackageName(fallbackPackageName: String): String {
19+
val packageName = packageNameOption.value!!
20+
21+
return if (packageName == packageNameOption.default) {
22+
fallbackPackageName.also { packageNameOption.value = it }
23+
} else {
24+
packageName
25+
}
26+
}
27+
28+
val changePackageNamePatch = resourcePatch(
29+
name = "Change package name",
30+
description = "Appends \".revanced\" to the package name by default. Changing the package name of the app can lead to unexpected issues.",
31+
use = false,
32+
) {
33+
packageNameOption = stringOption(
34+
key = "packageName",
35+
default = "Default",
36+
values = mapOf("Default" to "Default"),
37+
title = "Package name",
38+
description = "The name of the package to rename the app to.",
39+
required = true,
40+
) {
41+
it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$"))
42+
}
43+
44+
finalize {
45+
document("AndroidManifest.xml").use { document ->
46+
47+
val replacementPackageName = packageNameOption.value
48+
49+
val manifest = document.getElementsByTagName("manifest").item(0) as Element
50+
manifest.setAttribute(
51+
"package",
52+
if (replacementPackageName != packageNameOption.default) {
53+
replacementPackageName
54+
} else {
55+
"${manifest.getAttribute("package")}.revanced"
56+
},
57+
)
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)