From 11b59f767c94514d49a84593618ff9d2aace2636 Mon Sep 17 00:00:00 2001 From: bennett-sh <110846042+bennett-sh@users.noreply.github.com> Date: Sun, 11 Dec 2022 01:37:56 +0100 Subject: [PATCH] feat: `predictive-back-gesture` patch (#1236) Co-authored-by: oSumAtrIX --- .../patch/PredictiveBackGesturePatch.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/all/interaction/gestures/patch/PredictiveBackGesturePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/all/interaction/gestures/patch/PredictiveBackGesturePatch.kt b/src/main/kotlin/app/revanced/patches/all/interaction/gestures/patch/PredictiveBackGesturePatch.kt new file mode 100644 index 00000000..de1571ae --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/all/interaction/gestures/patch/PredictiveBackGesturePatch.kt @@ -0,0 +1,36 @@ +package app.revanced.patches.all.interaction.gestures.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.Patch + +@Patch +@Name("predictive-back-gesture") +@Description("Enables the predictive back gesture introduced on Android 13.") +@Version("0.0.1") +class PredictiveBackGesturePatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + context.xmlEditor["AndroidManifest.xml"].use { editor -> + val document = editor.file + + with(document.getElementsByTagName("application").item(0)) { + attributes.getNamedItem(FLAG)?.let { + document.createAttribute(FLAG) + .apply { value = "true" } + .let(attributes::setNamedItem) + } + } + } + + return PatchResultSuccess() + } + + private companion object { + const val FLAG = "android:enableOnBackInvokedCallback" + } +}