fix(GmsCore support): Try replacing in strings before prefixing to handle more edge cases

This commit is contained in:
oSumAtrIX 2026-03-01 00:10:52 +01:00
parent 0cd6be5cd8
commit 4d94a41c46
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4

View file

@ -87,15 +87,11 @@ fun gmsCoreSupportPatch(
"com.google.android.gms", "com.google.android.gms",
in GMS_PERMISSIONS, in GMS_PERMISSIONS,
in GMS_AUTHORITIES, in GMS_AUTHORITIES,
-> if (string.startsWith("com.google")) { -> string.prefixOrReplace("com.google", gmsCoreVendorGroupId)
string.replace("com.google", gmsCoreVendorGroupId)
} else {
"$gmsCoreVendorGroupId.$string"
}
in APP_PERMISSIONS, in APP_PERMISSIONS,
in APP_AUTHORITIES, in APP_AUTHORITIES,
-> "$toPackageName.$string" -> string.prefixOrReplace(fromPackageName, toPackageName)
else -> null else -> null
} }
@ -116,7 +112,17 @@ fun gmsCoreSupportPatch(
} }
in APP_AUTHORITIES -> in APP_AUTHORITIES ->
string.replace(it.authority, "$toPackageName.${it.authority}") if (it.authority.startsWith(fromPackageName)) {
string.replace(
it.authority,
it.authority.replace(fromPackageName, toPackageName)
)
} else {
string.replace(
it.authority,
"$toPackageName.${it.authority}",
)
}
else -> null else -> null
} }
@ -226,7 +232,7 @@ fun gmsCoreSupportResourcePatch(
node.attributes.getNamedItem("android:name").apply { node.attributes.getNamedItem("android:name").apply {
APP_PERMISSIONS += textContent APP_PERMISSIONS += textContent
textContent = "$toPackageName.$textContent" textContent = textContent.prefixOrReplace(fromPackageName, toPackageName)
} }
} }
@ -235,7 +241,7 @@ fun gmsCoreSupportResourcePatch(
if (textContent in GMS_PERMISSIONS) { if (textContent in GMS_PERMISSIONS) {
textContent.replace("com.google", gmsCoreVendorGroupId) textContent.replace("com.google", gmsCoreVendorGroupId)
} else if (textContent in APP_PERMISSIONS) { } else if (textContent in APP_PERMISSIONS) {
textContent = "$toPackageName.$textContent" textContent = textContent.prefixOrReplace(fromPackageName, toPackageName)
} }
} }
} }
@ -245,7 +251,8 @@ fun gmsCoreSupportResourcePatch(
textContent = textContent.split(";") textContent = textContent.split(";")
.joinToString(";") { authority -> .joinToString(";") { authority ->
APP_AUTHORITIES += authority APP_AUTHORITIES += authority
"$toPackageName.$authority"
authority.replace(fromPackageName, toPackageName)
} }
} }
} }
@ -345,3 +352,9 @@ private object Constants {
val APP_AUTHORITIES = mutableSetOf<String>() val APP_AUTHORITIES = mutableSetOf<String>()
} }
fun String.prefixOrReplace(from: String, to: String) = if (startsWith(from)) {
replace(from, to)
} else {
"$to.$this"
}