fix(GmsCore support): Rename MicroG GmsCore specific strings as well and rename app specific strings correctly
This commit is contained in:
parent
450454019d
commit
c2ac1f04a0
1 changed files with 33 additions and 24 deletions
|
|
@ -55,7 +55,7 @@ fun gmsCoreSupportPatch(
|
||||||
) = bytecodePatch(
|
) = bytecodePatch(
|
||||||
name = "GmsCore support",
|
name = "GmsCore support",
|
||||||
description = "Allows the app to work without root by using a different package name when patched " +
|
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(
|
val gmsCoreVendorGroupIdOption = stringOption(
|
||||||
key = "gmsCoreVendorGroupId",
|
key = "gmsCoreVendorGroupId",
|
||||||
|
|
@ -88,8 +88,9 @@ fun gmsCoreSupportPatch(
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation.instructions.forEachIndexed insnLoop@{ index, instruction ->
|
implementation.instructions.forEachIndexed insnLoop@{ index, instruction ->
|
||||||
val string = ((instruction as? Instruction21c)?.reference as? StringReference)?.string
|
val string =
|
||||||
?: return@insnLoop
|
((instruction as? Instruction21c)?.reference as? StringReference)?.string
|
||||||
|
?: return@insnLoop
|
||||||
|
|
||||||
// Apply transformation.
|
// Apply transformation.
|
||||||
val transformedString = transform(string) ?: return@insnLoop
|
val transformedString = transform(string) ?: return@insnLoop
|
||||||
|
|
@ -111,7 +112,7 @@ 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")) {
|
-> if (string.startsWith("com.google")) {
|
||||||
string.replace("com.google", gmsCoreVendorGroupId)
|
string.replace("com.google", gmsCoreVendorGroupId)
|
||||||
} else {
|
} else {
|
||||||
"$gmsCoreVendorGroupId.$string"
|
"$gmsCoreVendorGroupId.$string"
|
||||||
|
|
@ -119,7 +120,7 @@ fun gmsCoreSupportPatch(
|
||||||
|
|
||||||
in APP_PERMISSIONS,
|
in APP_PERMISSIONS,
|
||||||
in APP_AUTHORITIES,
|
in APP_AUTHORITIES,
|
||||||
-> "$toPackageName.$string"
|
-> "$toPackageName.$string"
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +192,7 @@ fun gmsCoreSupportPatch(
|
||||||
mainActivityOnCreateFingerprint.method.addInstruction(
|
mainActivityOnCreateFingerprint.method.addInstruction(
|
||||||
0,
|
0,
|
||||||
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->" +
|
"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.
|
// Change the vendor of GmsCore in the extension.
|
||||||
|
|
@ -232,35 +233,39 @@ fun gmsCoreSupportResourcePatch(
|
||||||
execute {
|
execute {
|
||||||
addResources("shared", "misc.gms.gmsCoreSupportResourcePatch")
|
addResources("shared", "misc.gms.gmsCoreSupportResourcePatch")
|
||||||
|
|
||||||
|
val toPackageName = setOrGetFallbackPackageName(toPackageName)
|
||||||
|
|
||||||
document("AndroidManifest.xml").use { document ->
|
document("AndroidManifest.xml").use { document ->
|
||||||
document.getElementsByTagName("permission").asSequence().forEach { node ->
|
document.getElementsByTagName("permission").asSequence().forEach { node ->
|
||||||
val nameElement = node.attributes.getNamedItem("android:name")
|
node.attributes.getNamedItem("android:name").apply {
|
||||||
nameElement.textContent = toPackageName + nameElement.textContent
|
APP_PERMISSIONS += textContent
|
||||||
|
|
||||||
|
textContent = "$toPackageName.$textContent"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementsByTagName("uses-permission").asSequence().forEach { node ->
|
document.getElementsByTagName("uses-permission").asSequence().forEach { node ->
|
||||||
val nameElement = node.attributes.getNamedItem("android:name")
|
node.attributes.getNamedItem("android:name").apply {
|
||||||
if (nameElement.textContent in GMS_PERMISSIONS) {
|
if (textContent in GMS_PERMISSIONS) {
|
||||||
nameElement.textContent.replace("com.google", gmsCoreVendorGroupId)
|
textContent.replace("com.google", gmsCoreVendorGroupId)
|
||||||
|
} else if (textContent in APP_PERMISSIONS) {
|
||||||
|
textContent = "$toPackageName.$textContent"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementsByTagName("provider").asSequence().forEach { node ->
|
document.getElementsByTagName("provider").asSequence().forEach { node ->
|
||||||
val providerElement = node.attributes.getNamedItem("android:authorities")
|
node.attributes.getNamedItem("android:authorities").apply {
|
||||||
|
textContent = textContent.split(";")
|
||||||
providerElement.textContent = providerElement.textContent.split(";")
|
.joinToString(";") { authority ->
|
||||||
.joinToString(";") { authority ->
|
APP_AUTHORITIES += authority
|
||||||
if (authority.startsWith("com.google")) {
|
"$toPackageName.$authority"
|
||||||
authority.replace("com.google", gmsCoreVendorGroupId)
|
|
||||||
} else {
|
|
||||||
"$gmsCoreVendorGroupId.$authority"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getNode("manifest")
|
document.getNode("manifest")
|
||||||
.attributes.getNamedItem("package").textContent =
|
.attributes.getNamedItem("package").textContent = toPackageName
|
||||||
setOrGetFallbackPackageName(toPackageName)
|
|
||||||
|
|
||||||
document.getNode("queries").appendChild(
|
document.getNode("queries").appendChild(
|
||||||
document.createElement("package").apply {
|
document.createElement("package").apply {
|
||||||
|
|
@ -336,7 +341,7 @@ private object Constants {
|
||||||
)
|
)
|
||||||
|
|
||||||
val GMS_AUTHORITIES = setOf(
|
val GMS_AUTHORITIES = setOf(
|
||||||
"google.android.gms.fileprovider",
|
"com.google.android.gms.fileprovider",
|
||||||
"com.google.android.gms.auth.accounts",
|
"com.google.android.gms.auth.accounts",
|
||||||
"com.google.android.gms.chimera",
|
"com.google.android.gms.chimera",
|
||||||
"com.google.android.gms.fonts",
|
"com.google.android.gms.fonts",
|
||||||
|
|
@ -346,7 +351,11 @@ private object Constants {
|
||||||
"subscribedfeeds",
|
"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>()
|
val APP_AUTHORITIES = mutableSetOf<String>()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue