feat(Change package name): Add options to change provider and permission package names to handle installation conflicts

Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
1fexd 2024-12-09 06:53:05 +00:00 committed by GitHub
parent 02edf0ca9e
commit 75c740c6ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,8 @@
package app.revanced.patches.all.misc.packagename package app.revanced.patches.all.misc.packagename
import app.revanced.patcher.patch.Option import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.resourcePatch import app.revanced.util.asSequence
import app.revanced.patcher.patch.stringOption import app.revanced.util.getNode
import org.w3c.dom.Element import org.w3c.dom.Element
import java.util.logging.Logger import java.util.logging.Logger
@ -28,7 +28,8 @@ fun setOrGetFallbackPackageName(fallbackPackageName: String): String {
val changePackageNamePatch = resourcePatch( val changePackageNamePatch = resourcePatch(
name = "Change package name", name = "Change package name",
description = "Appends \".revanced\" to the package name by default. Changing the package name of the app can lead to unexpected issues.", description = "Appends \".revanced\" to the package name by default. " +
"Changing the package name of the app can lead to unexpected issues.",
use = false, use = false,
) { ) {
packageNameOption = stringOption( packageNameOption = stringOption(
@ -42,40 +43,81 @@ val changePackageNamePatch = resourcePatch(
it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$")) it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$"))
} }
/** val updatePermissions by booleanOption(
* Apps that are confirmed to not work correctly with this patch. key = "updatePermissions",
* This is not an exhaustive list, and is only the apps with default = false,
* ReVanced specific patches and are confirmed incompatible with this patch. title = "Update permissions",
*/ description = "Update compatibility receiver permissions. " +
val incompatibleAppPackages = setOf( "Enabling this can fix installation errors, but this can also break features in certain apps.",
// Cannot login, settings menu is broken. )
"com.reddit.frontpage",
// Patches and installs but crashes on launch. val updateProviders by booleanOption(
"com.duolingo", key = "updateProviders",
"com.twitter.android", default = false,
"tv.twitch.android.app", title = "Update providers",
description = "Update provider names declared by the app. " +
"Enabling this can fix installation errors, but this can also break features in certain apps.",
) )
finalize { finalize {
document("AndroidManifest.xml").use { document -> /**
val manifest = document.getElementsByTagName("manifest").item(0) as Element * Apps that are confirmed to not work correctly with this patch.
val originalPackageName = manifest.getAttribute("package") * 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 log in, settings menu is broken.
"com.reddit.frontpage",
if (incompatibleAppPackages.contains(originalPackageName)) { // Patches and installs but crashes on launch.
"com.duolingo",
"com.twitter.android",
"tv.twitch.android.app",
)
document("AndroidManifest.xml").use { document ->
val manifest = document.getNode("manifest") as Element
val packageName = manifest.getAttribute("package")
if (incompatibleAppPackages.contains(packageName)) {
return@finalize Logger.getLogger(this::class.java.name).severe( return@finalize Logger.getLogger(this::class.java.name).severe(
"'$originalPackageName' does not work correctly with \"Change package name\"") "'$packageName' does not work correctly with \"Change package name\"",
)
} }
val replacementPackageName = packageNameOption.value val replacementPackageName = packageNameOption.value
manifest.setAttribute( val newPackageName = if (replacementPackageName != packageNameOption.default) {
"package", replacementPackageName!!
if (replacementPackageName != packageNameOption.default) { } else {
replacementPackageName "$packageName.revanced"
} else { }
"${originalPackageName}.revanced"
}, manifest.setAttribute("package", newPackageName)
)
if (updatePermissions == true) {
val permissions = manifest.getElementsByTagName("permission").asSequence()
val usesPermissions = manifest.getElementsByTagName("uses-permission").asSequence()
val receiverNotExported = "DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION"
(permissions + usesPermissions)
.map { it as Element }
.filter { it.getAttribute("android:name") == "$packageName.$receiverNotExported" }
.forEach { it.setAttribute("android:name", "$newPackageName.$receiverNotExported") }
}
if (updateProviders == true) {
val providers = manifest.getElementsByTagName("provider").asSequence()
for (node in providers) {
val provider = node as Element
val authorities = provider.getAttribute("android:authorities")
if (!authorities.startsWith("$packageName.")) continue
provider.setAttribute("android:authorities", authorities.replace(packageName, newPackageName))
}
}
} }
} }
} }