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 000000000..de1571ae1 --- /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" + } +}