From 7cc405f7e900b85aaa172e8693cd4ca2e790451d Mon Sep 17 00:00:00 2001 From: Swakshan Date: Wed, 5 Jun 2024 00:04:24 +0530 Subject: [PATCH] feat(all): Added `Export all activities` patch from ReVanced --- .../exportall/ExportAllActivitiesPatch.kt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/kotlin/crimera/patches/all/activity/exportall/ExportAllActivitiesPatch.kt diff --git a/src/main/kotlin/crimera/patches/all/activity/exportall/ExportAllActivitiesPatch.kt b/src/main/kotlin/crimera/patches/all/activity/exportall/ExportAllActivitiesPatch.kt new file mode 100644 index 00000000..e9cfb3f8 --- /dev/null +++ b/src/main/kotlin/crimera/patches/all/activity/exportall/ExportAllActivitiesPatch.kt @@ -0,0 +1,43 @@ +package crimera.patches.all.activity.exportall + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotation.Patch + +//credits - @ReVanced +@Patch( + name = "Export all activities", + description = "Makes all app activities exportable.", + use = false, +) +@Suppress("unused") +object ExportAllActivitiesPatch : ResourcePatch() { + private const val EXPORTED_FLAG = "android:exported" + + override fun execute(context: ResourceContext) { + context.xmlEditor["AndroidManifest.xml"].use { editor -> + val document = editor.file + + val activities = document.getElementsByTagName("activity") + + for (i in 0..activities.length) { + activities.item(i)?.apply { + val exportedAttribute = attributes.getNamedItem(EXPORTED_FLAG) + + if (exportedAttribute != null) { + if (exportedAttribute.nodeValue != "true") { + exportedAttribute.nodeValue = "true" + } + } + // Reason why the attribute is added in the case it does not exist: + // https://github.com/revanced/revanced-patches/pull/1751/files#r1141481604 + else { + document.createAttribute(EXPORTED_FLAG) + .apply { value = "true" } + .let(attributes::setNamedItem) + } + } + } + } + } +} \ No newline at end of file