build: Bump dependencies
This commit also migrates away from deprecated to new APIs
This commit is contained in:
@ -22,19 +22,21 @@ abstract class BaseGmsCoreSupportResourcePatch(
|
||||
private val fromPackageName: String,
|
||||
private val toPackageName: String,
|
||||
private val spoofedPackageSignature: String,
|
||||
dependencies: Set<PatchClass> = setOf()
|
||||
dependencies: Set<PatchClass> = setOf(),
|
||||
) : ResourcePatch(dependencies = setOf(ChangePackageNamePatch::class, AddResourcesPatch::class) + dependencies) {
|
||||
internal val gmsCoreVendorOption = stringPatchOption(
|
||||
key = "gmsCoreVendor",
|
||||
default = "com.mgoogle",
|
||||
values = mapOf(
|
||||
"Vanced" to "com.mgoogle",
|
||||
"ReVanced" to "app.revanced"
|
||||
),
|
||||
title = "GmsCore Vendor",
|
||||
description = "The group id of the GmsCore vendor.",
|
||||
required = true
|
||||
) { it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$")) }
|
||||
internal val gmsCoreVendorOption =
|
||||
stringPatchOption(
|
||||
key = "gmsCoreVendor",
|
||||
default = "com.mgoogle",
|
||||
values =
|
||||
mapOf(
|
||||
"Vanced" to "com.mgoogle",
|
||||
"ReVanced" to "app.revanced",
|
||||
),
|
||||
title = "GmsCore Vendor",
|
||||
description = "The group id of the GmsCore vendor.",
|
||||
required = true,
|
||||
) { it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$")) }
|
||||
|
||||
protected val gmsCoreVendor by gmsCoreVendorOption
|
||||
|
||||
@ -49,17 +51,20 @@ abstract class BaseGmsCoreSupportResourcePatch(
|
||||
* Add metadata to manifest to support spoofing the package name and signature of GmsCore.
|
||||
*/
|
||||
private fun ResourceContext.addSpoofingMetadata() {
|
||||
fun Node.adoptChild(tagName: String, block: Element.() -> Unit) {
|
||||
fun Node.adoptChild(
|
||||
tagName: String,
|
||||
block: Element.() -> Unit,
|
||||
) {
|
||||
val child = ownerDocument.createElement(tagName)
|
||||
child.block()
|
||||
appendChild(child)
|
||||
}
|
||||
|
||||
xmlEditor["AndroidManifest.xml"].use {
|
||||
val applicationNode = it
|
||||
.file
|
||||
.getElementsByTagName("application")
|
||||
.item(0)
|
||||
document["AndroidManifest.xml"].use { document ->
|
||||
val applicationNode =
|
||||
document
|
||||
.getElementsByTagName("application")
|
||||
.item(0)
|
||||
|
||||
// Spoof package name and signature.
|
||||
applicationNode.adoptChild("meta-data") {
|
||||
@ -87,27 +92,27 @@ abstract class BaseGmsCoreSupportResourcePatch(
|
||||
private fun ResourceContext.patchManifest() {
|
||||
val packageName = ChangePackageNamePatch.setOrGetFallbackPackageName(toPackageName)
|
||||
|
||||
val manifest = this["AndroidManifest.xml"].readText()
|
||||
this["AndroidManifest.xml"].writeText(
|
||||
val manifest = this.get("AndroidManifest.xml", false).readText()
|
||||
this.get("AndroidManifest.xml", false).writeText(
|
||||
manifest.replace(
|
||||
"package=\"$fromPackageName",
|
||||
"package=\"$packageName"
|
||||
"package=\"$packageName",
|
||||
).replace(
|
||||
"android:authorities=\"$fromPackageName",
|
||||
"android:authorities=\"$packageName"
|
||||
"android:authorities=\"$packageName",
|
||||
).replace(
|
||||
"$fromPackageName.permission.C2D_MESSAGE",
|
||||
"$packageName.permission.C2D_MESSAGE"
|
||||
"$packageName.permission.C2D_MESSAGE",
|
||||
).replace(
|
||||
"$fromPackageName.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION",
|
||||
"$packageName.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION"
|
||||
"$packageName.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION",
|
||||
).replace(
|
||||
"com.google.android.c2dm",
|
||||
"$gmsCoreVendor.android.c2dm"
|
||||
"$gmsCoreVendor.android.c2dm",
|
||||
).replace(
|
||||
"</queries>",
|
||||
"<package android:name=\"$gmsCoreVendor.android.gms\"/></queries>"
|
||||
)
|
||||
"<package android:name=\"$gmsCoreVendor.android.gms\"/></queries>",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import java.util.*
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
object ResourceMappingPatch : ResourcePatch() {
|
||||
internal lateinit var resourceMappings: List<ResourceElement>
|
||||
private set
|
||||
@ -17,15 +16,15 @@ object ResourceMappingPatch : ResourcePatch() {
|
||||
|
||||
override fun execute(context: ResourceContext) {
|
||||
// save the file in memory to concurrently read from
|
||||
val resourceXmlFile = context["res/values/public.xml"].readBytes()
|
||||
val resourceXmlFile = context.get("res/values/public.xml", false).readBytes()
|
||||
|
||||
// create a synchronized list to store the resource mappings
|
||||
val mappings = Collections.synchronizedList(mutableListOf<ResourceElement>())
|
||||
|
||||
for (threadIndex in 0 until THREAD_COUNT) {
|
||||
threadPoolExecutor.execute thread@{
|
||||
context.xmlEditor[resourceXmlFile.inputStream()].use { editor ->
|
||||
val resources = editor.file.documentElement.childNodes
|
||||
context.document[resourceXmlFile.inputStream()].use { document ->
|
||||
val resources = document.documentElement.childNodes
|
||||
val resourcesLength = resources.length
|
||||
val jobSize = resourcesLength / THREAD_COUNT
|
||||
|
||||
@ -59,4 +58,4 @@ object ResourceMappingPatch : ResourcePatch() {
|
||||
}
|
||||
|
||||
data class ResourceElement(val type: String, val name: String, val id: Long)
|
||||
}
|
||||
}
|
||||
|
@ -21,16 +21,18 @@ import java.io.Closeable
|
||||
*/
|
||||
abstract class BaseSettingsResourcePatch(
|
||||
private val rootPreference: Pair<IntentPreference, String>? = null,
|
||||
dependencies: Set<PatchClass> = emptySet()
|
||||
dependencies: Set<PatchClass> = emptySet(),
|
||||
) : ResourcePatch(
|
||||
dependencies = setOf(AddResourcesPatch::class) + dependencies
|
||||
), MutableSet<BasePreference> by mutableSetOf(), Closeable {
|
||||
dependencies = setOf(AddResourcesPatch::class) + dependencies,
|
||||
),
|
||||
MutableSet<BasePreference> by mutableSetOf(),
|
||||
Closeable {
|
||||
private lateinit var context: ResourceContext
|
||||
|
||||
override fun execute(context: ResourceContext) {
|
||||
context.copyResources(
|
||||
"settings",
|
||||
ResourceGroup("xml", "revanced_prefs.xml")
|
||||
ResourceGroup("xml", "revanced_prefs.xml"),
|
||||
)
|
||||
|
||||
this.context = context
|
||||
@ -49,14 +51,14 @@ abstract class BaseSettingsResourcePatch(
|
||||
|
||||
// Add the root preference to an existing fragment if needed.
|
||||
rootPreference?.let { (intentPreference, fragment) ->
|
||||
context.xmlEditor["res/xml/$fragment.xml"].use {
|
||||
context.document["res/xml/$fragment.xml"].use {
|
||||
it.getNode("PreferenceScreen").addPreference(intentPreference)
|
||||
}
|
||||
}
|
||||
|
||||
// Add all preferences to the ReVanced fragment.
|
||||
context.xmlEditor["res/xml/revanced_prefs.xml"].use { editor ->
|
||||
val revancedPreferenceScreenNode = editor.getNode("PreferenceScreen")
|
||||
context.document["res/xml/revanced_prefs.xml"].use { document ->
|
||||
val revancedPreferenceScreenNode = document.getNode("PreferenceScreen")
|
||||
forEach { revancedPreferenceScreenNode.addPreference(it) }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user