fix(GmsCore support): Rename MicroG GmsCore specific strings as well and rename app specific strings correctly

This commit is contained in:
oSumAtrIX 2026-02-16 02:08:19 +01:00
parent 450454019d
commit c2ac1f04a0
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4

View file

@ -55,7 +55,7 @@ fun gmsCoreSupportPatch(
) = bytecodePatch(
name = "GmsCore support",
description = "Allows the app to work without root by using a different package name when patched " +
"using a GmsCore instead of Google Play Services.",
"using a GmsCore instead of Google Play Services.",
) {
val gmsCoreVendorGroupIdOption = stringOption(
key = "gmsCoreVendorGroupId",
@ -88,8 +88,9 @@ fun gmsCoreSupportPatch(
}
implementation.instructions.forEachIndexed insnLoop@{ index, instruction ->
val string = ((instruction as? Instruction21c)?.reference as? StringReference)?.string
?: return@insnLoop
val string =
((instruction as? Instruction21c)?.reference as? StringReference)?.string
?: return@insnLoop
// Apply transformation.
val transformedString = transform(string) ?: return@insnLoop
@ -111,7 +112,7 @@ fun gmsCoreSupportPatch(
"com.google.android.gms",
in GMS_PERMISSIONS,
in GMS_AUTHORITIES,
-> if (string.startsWith("com.google")) {
-> if (string.startsWith("com.google")) {
string.replace("com.google", gmsCoreVendorGroupId)
} else {
"$gmsCoreVendorGroupId.$string"
@ -119,7 +120,7 @@ fun gmsCoreSupportPatch(
in APP_PERMISSIONS,
in APP_AUTHORITIES,
-> "$toPackageName.$string"
-> "$toPackageName.$string"
else -> null
}
@ -191,7 +192,7 @@ fun gmsCoreSupportPatch(
mainActivityOnCreateFingerprint.method.addInstruction(
0,
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->" +
"checkGmsCore(Landroid/app/Activity;)V",
"checkGmsCore(Landroid/app/Activity;)V",
)
// Change the vendor of GmsCore in the extension.
@ -232,35 +233,39 @@ fun gmsCoreSupportResourcePatch(
execute {
addResources("shared", "misc.gms.gmsCoreSupportResourcePatch")
val toPackageName = setOrGetFallbackPackageName(toPackageName)
document("AndroidManifest.xml").use { document ->
document.getElementsByTagName("permission").asSequence().forEach { node ->
val nameElement = node.attributes.getNamedItem("android:name")
nameElement.textContent = toPackageName + nameElement.textContent
node.attributes.getNamedItem("android:name").apply {
APP_PERMISSIONS += textContent
textContent = "$toPackageName.$textContent"
}
}
document.getElementsByTagName("uses-permission").asSequence().forEach { node ->
val nameElement = node.attributes.getNamedItem("android:name")
if (nameElement.textContent in GMS_PERMISSIONS) {
nameElement.textContent.replace("com.google", gmsCoreVendorGroupId)
node.attributes.getNamedItem("android:name").apply {
if (textContent in GMS_PERMISSIONS) {
textContent.replace("com.google", gmsCoreVendorGroupId)
} else if (textContent in APP_PERMISSIONS) {
textContent = "$toPackageName.$textContent"
}
}
}
document.getElementsByTagName("provider").asSequence().forEach { node ->
val providerElement = node.attributes.getNamedItem("android:authorities")
providerElement.textContent = providerElement.textContent.split(";")
.joinToString(";") { authority ->
if (authority.startsWith("com.google")) {
authority.replace("com.google", gmsCoreVendorGroupId)
} else {
"$gmsCoreVendorGroupId.$authority"
node.attributes.getNamedItem("android:authorities").apply {
textContent = textContent.split(";")
.joinToString(";") { authority ->
APP_AUTHORITIES += authority
"$toPackageName.$authority"
}
}
}
}
document.getNode("manifest")
.attributes.getNamedItem("package").textContent =
setOrGetFallbackPackageName(toPackageName)
.attributes.getNamedItem("package").textContent = toPackageName
document.getNode("queries").appendChild(
document.createElement("package").apply {
@ -336,7 +341,7 @@ private object Constants {
)
val GMS_AUTHORITIES = setOf(
"google.android.gms.fileprovider",
"com.google.android.gms.fileprovider",
"com.google.android.gms.auth.accounts",
"com.google.android.gms.chimera",
"com.google.android.gms.fonts",
@ -346,7 +351,11 @@ private object Constants {
"subscribedfeeds",
)
val APP_PERMISSIONS = mutableSetOf<String>()
val APP_PERMISSIONS = mutableSetOf(
"org.microg.gms.STATUS_BROADCAST",
"org.microg.gms.EXTENDED_ACCESS",
"org.microg.gms.PROVISION"
)
val APP_AUTHORITIES = mutableSetOf<String>()
}