Skip to content

Commit

Permalink
fix(Change package name): Prevent applying the patch to known incompa…
Browse files Browse the repository at this point in the history
…tible apps (#3943)
  • Loading branch information
LisoUseInAIKyrios authored Dec 9, 2024
1 parent fbc6ab6 commit 44936e7
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import app.revanced.patcher.patch.Option
import app.revanced.patcher.patch.resourcePatch
import app.revanced.patcher.patch.stringOption
import org.w3c.dom.Element
import java.util.logging.Logger

lateinit var packageNameOption: Option<String>

Expand Down Expand Up @@ -41,18 +42,38 @@ val changePackageNamePatch = resourcePatch(
it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$"))
}

/**
* Apps that are confirmed to not work correctly with this patch.
* This is not an exhaustive list, and is only the apps with
* ReVanced specific patches and are confirmed incompatible with this patch.
*/
val incompatibleAppPackages = setOf(
// Cannot login, settings menu is broken.
"com.reddit.frontpage",

// Patches and installs but crashes on launch.
"com.duolingo",
"com.twitter.android",
"tv.twitch.android.app",
)

finalize {
document("AndroidManifest.xml").use { document ->
val manifest = document.getElementsByTagName("manifest").item(0) as Element
val originalPackageName = manifest.getAttribute("package")

val replacementPackageName = packageNameOption.value
if (incompatibleAppPackages.contains(originalPackageName)) {
return@finalize Logger.getLogger(this::class.java.name).severe(
"'$originalPackageName' does not work correctly with \"Change package name\"")
}

val manifest = document.getElementsByTagName("manifest").item(0) as Element
val replacementPackageName = packageNameOption.value
manifest.setAttribute(
"package",
if (replacementPackageName != packageNameOption.default) {
replacementPackageName
} else {
"${manifest.getAttribute("package")}.revanced"
"${originalPackageName}.revanced"
},
)
}
Expand Down

0 comments on commit 44936e7

Please sign in to comment.