mirror of
https://github.com/revanced/revanced-patches
synced 2025-01-07 11:05:54 +01:00
feat(YouTube Music - Vanced MicroG support): Allow changing package name
This commit is contained in:
parent
fb373bc9a0
commit
ede2d67b92
@ -4,7 +4,9 @@ import app.revanced.patcher.data.ResourceContext
|
|||||||
import app.revanced.patcher.patch.ResourcePatch
|
import app.revanced.patcher.patch.ResourcePatch
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
import app.revanced.patcher.patch.annotation.Patch
|
||||||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
|
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
|
||||||
|
import app.revanced.patcher.patch.options.PatchOptionException
|
||||||
import org.w3c.dom.Element
|
import org.w3c.dom.Element
|
||||||
|
import java.io.Closeable
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Change package name",
|
name = "Change package name",
|
||||||
@ -12,13 +14,11 @@ import org.w3c.dom.Element
|
|||||||
use = false
|
use = false
|
||||||
)
|
)
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object ChangePackageNamePatch : ResourcePatch() {
|
object ChangePackageNamePatch : ResourcePatch(), Closeable {
|
||||||
private const val DEFAULT_PACKAGE_NAME_OPTION = "Default"
|
private val packageNameOption = stringPatchOption(
|
||||||
|
|
||||||
private var packageName by stringPatchOption(
|
|
||||||
key = "packageName",
|
key = "packageName",
|
||||||
default = DEFAULT_PACKAGE_NAME_OPTION,
|
default = "Default",
|
||||||
values = mapOf("Default" to DEFAULT_PACKAGE_NAME_OPTION),
|
values = mapOf("Default" to "Default"),
|
||||||
title = "Package name",
|
title = "Package name",
|
||||||
description = "The name of the package to rename the app to.",
|
description = "The name of the package to rename the app to.",
|
||||||
required = true
|
required = true
|
||||||
@ -26,19 +26,37 @@ object ChangePackageNamePatch : ResourcePatch() {
|
|||||||
it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$"))
|
it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private lateinit var context: ResourceContext
|
||||||
|
|
||||||
override fun execute(context: ResourceContext) {
|
override fun execute(context: ResourceContext) {
|
||||||
fun getOriginalPackageName(context: ResourceContext): String {
|
this.context = context
|
||||||
context.xmlEditor["AndroidManifest.xml"].use { editor ->
|
}
|
||||||
val manifest = editor.file.getElementsByTagName("manifest").item(0) as Element
|
|
||||||
return manifest.getAttribute("package")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val originalPackageName = getOriginalPackageName(context)
|
/**
|
||||||
if (packageName == DEFAULT_PACKAGE_NAME_OPTION) packageName = "$originalPackageName.revanced"
|
* Set the package name to use.
|
||||||
|
* If this is called multiple times, the first call will set the package name.
|
||||||
|
*
|
||||||
|
* @param fallbackPackageName The package name to use if the user has not already specified a package name.
|
||||||
|
* @return The package name that was set.
|
||||||
|
* @throws PatchOptionException.ValueValidationException If the package name is invalid.
|
||||||
|
*/
|
||||||
|
fun setOrGetFallbackPackageName(fallbackPackageName: String): String {
|
||||||
|
val packageName = this.packageNameOption.value!!
|
||||||
|
|
||||||
context["AndroidManifest.xml"].apply {
|
return if (packageName == this.packageNameOption.default)
|
||||||
readText().replace(originalPackageName, packageName!!).let(::writeText)
|
fallbackPackageName.also { this.packageNameOption.value = it }
|
||||||
}
|
else
|
||||||
|
packageName
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() = context.xmlEditor["AndroidManifest.xml"].use { editor ->
|
||||||
|
val manifest = editor.file.getElementsByTagName("manifest").item(0) as Element
|
||||||
|
val originalPackageName = manifest.getAttribute("package")
|
||||||
|
|
||||||
|
var replacementPackageName = this.packageNameOption.value
|
||||||
|
if (replacementPackageName == this.packageNameOption.default)
|
||||||
|
replacementPackageName = "$originalPackageName.revanced"
|
||||||
|
|
||||||
|
manifest.setAttribute("package", replacementPackageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,18 +4,25 @@ import app.revanced.patcher.data.BytecodeContext
|
|||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
import app.revanced.patcher.patch.annotation.Patch
|
||||||
|
import app.revanced.patches.all.misc.packagename.ChangePackageNamePatch
|
||||||
import app.revanced.patches.music.misc.microg.fingerprints.*
|
import app.revanced.patches.music.misc.microg.fingerprints.*
|
||||||
import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAME
|
import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAME
|
||||||
import app.revanced.patches.music.misc.microg.shared.Constants.REVANCED_MUSIC_PACKAGE_NAME
|
import app.revanced.patches.music.misc.microg.shared.Constants.REVANCED_MUSIC_PACKAGE_NAME
|
||||||
import app.revanced.patches.youtube.misc.microg.shared.Constants
|
|
||||||
import app.revanced.util.microg.MicroGBytecodeHelper
|
import app.revanced.util.microg.MicroGBytecodeHelper
|
||||||
|
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Vanced MicroG support",
|
name = "Vanced MicroG support",
|
||||||
description = "Allows YouTube Music to run without root and under a different package name.",
|
description = "Allows YouTube Music to run without root and under a different package name.",
|
||||||
dependencies = [MicroGResourcePatch::class],
|
dependencies = [
|
||||||
compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")]
|
ChangePackageNamePatch::class,
|
||||||
|
MicroGResourcePatch::class,
|
||||||
|
],
|
||||||
|
compatiblePackages = [
|
||||||
|
CompatiblePackage(
|
||||||
|
"com.google.android.apps.youtube.music"
|
||||||
|
)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object MicroGBytecodePatch : BytecodePatch(
|
object MicroGBytecodePatch : BytecodePatch(
|
||||||
@ -35,25 +42,29 @@ object MicroGBytecodePatch : BytecodePatch(
|
|||||||
// - "com.google.android.gms.phenotype.PACKAGE_NAME",
|
// - "com.google.android.gms.phenotype.PACKAGE_NAME",
|
||||||
// - "com.google.android.gms.phenotype.UPDATE",
|
// - "com.google.android.gms.phenotype.UPDATE",
|
||||||
// - "com.google.android.gms.phenotype",
|
// - "com.google.android.gms.phenotype",
|
||||||
override fun execute(context: BytecodeContext) = MicroGBytecodeHelper.patchBytecode(
|
override fun execute(context: BytecodeContext) {
|
||||||
context,
|
val packageName = ChangePackageNamePatch.setOrGetFallbackPackageName(REVANCED_MUSIC_PACKAGE_NAME)
|
||||||
arrayOf(
|
|
||||||
MicroGBytecodeHelper.packageNameTransform(
|
MicroGBytecodeHelper.patchBytecode(
|
||||||
Constants.PACKAGE_NAME,
|
context,
|
||||||
Constants.REVANCED_PACKAGE_NAME
|
arrayOf(
|
||||||
|
MicroGBytecodeHelper.packageNameTransform(
|
||||||
|
MUSIC_PACKAGE_NAME,
|
||||||
|
packageName
|
||||||
|
)
|
||||||
|
),
|
||||||
|
MicroGBytecodeHelper.PrimeMethodTransformationData(
|
||||||
|
PrimeFingerprint,
|
||||||
|
MUSIC_PACKAGE_NAME,
|
||||||
|
packageName
|
||||||
|
),
|
||||||
|
listOf(
|
||||||
|
ServiceCheckFingerprint,
|
||||||
|
GooglePlayUtilityFingerprint,
|
||||||
|
CastDynamiteModuleFingerprint,
|
||||||
|
CastDynamiteModuleV2Fingerprint,
|
||||||
|
CastContextFetchFingerprint
|
||||||
)
|
)
|
||||||
),
|
|
||||||
MicroGBytecodeHelper.PrimeMethodTransformationData(
|
|
||||||
PrimeFingerprint,
|
|
||||||
MUSIC_PACKAGE_NAME,
|
|
||||||
REVANCED_MUSIC_PACKAGE_NAME
|
|
||||||
),
|
|
||||||
listOf(
|
|
||||||
ServiceCheckFingerprint,
|
|
||||||
GooglePlayUtilityFingerprint,
|
|
||||||
CastDynamiteModuleFingerprint,
|
|
||||||
CastDynamiteModuleV2Fingerprint,
|
|
||||||
CastContextFetchFingerprint
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package app.revanced.patches.music.misc.microg
|
|||||||
import app.revanced.patcher.data.ResourceContext
|
import app.revanced.patcher.data.ResourceContext
|
||||||
import app.revanced.patcher.patch.ResourcePatch
|
import app.revanced.patcher.patch.ResourcePatch
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
import app.revanced.patcher.patch.annotation.Patch
|
||||||
|
import app.revanced.patches.all.misc.packagename.ChangePackageNamePatch
|
||||||
import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAME
|
import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAME
|
||||||
import app.revanced.patches.music.misc.microg.shared.Constants.REVANCED_MUSIC_APP_NAME
|
import app.revanced.patches.music.misc.microg.shared.Constants.REVANCED_MUSIC_APP_NAME
|
||||||
import app.revanced.patches.music.misc.microg.shared.Constants.REVANCED_MUSIC_PACKAGE_NAME
|
import app.revanced.patches.music.misc.microg.shared.Constants.REVANCED_MUSIC_PACKAGE_NAME
|
||||||
@ -14,15 +15,18 @@ import app.revanced.util.microg.MicroGResourceHelper
|
|||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
description = "Resource patch to allow YouTube Music ReVanced to run without root " +
|
description = "Resource patch to allow YouTube Music ReVanced to run without root " +
|
||||||
"and under a different package name."
|
"and under a different package name.",
|
||||||
|
dependencies = [ChangePackageNamePatch::class]
|
||||||
)
|
)
|
||||||
object MicroGResourcePatch : ResourcePatch() {
|
object MicroGResourcePatch : ResourcePatch() {
|
||||||
override fun execute(context: ResourceContext) {
|
override fun execute(context: ResourceContext) {
|
||||||
|
val packageName = ChangePackageNamePatch.setOrGetFallbackPackageName(REVANCED_MUSIC_PACKAGE_NAME)
|
||||||
|
|
||||||
// update manifest
|
// update manifest
|
||||||
MicroGResourceHelper.patchManifest(
|
MicroGResourceHelper.patchManifest(
|
||||||
context,
|
context,
|
||||||
MUSIC_PACKAGE_NAME,
|
MUSIC_PACKAGE_NAME,
|
||||||
REVANCED_MUSIC_PACKAGE_NAME,
|
packageName,
|
||||||
REVANCED_MUSIC_APP_NAME
|
REVANCED_MUSIC_APP_NAME
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user