From 3865add7995dc039a239ed02ab802152c7b9430f Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 15 Nov 2022 00:05:42 +0100 Subject: [PATCH] feat(youtube/debugging): include by default & add option to debug on Android --- .../annotations/DebuggingCompatibility.kt} | 4 +- .../patch/DebuggingPatch.kt} | 43 +++++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/misc/{enabledebugging/annotations/EnableDebuggingCompatibility.kt => debugging/annotations/DebuggingCompatibility.kt} (64%) rename src/main/kotlin/app/revanced/patches/youtube/misc/{enabledebugging/patch/EnableDebuggingPatch.kt => debugging/patch/DebuggingPatch.kt} (57%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/annotations/DebuggingCompatibility.kt similarity index 64% rename from src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/debugging/annotations/DebuggingCompatibility.kt index 4cd51784..cac120bc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/annotations/DebuggingCompatibility.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.enabledebugging.annotations +package app.revanced.patches.youtube.misc.debugging.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package @@ -6,4 +6,4 @@ import app.revanced.patcher.annotation.Package @Compatibility([Package("com.google.android.youtube")]) @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) -internal annotation class EnableDebuggingCompatibility +internal annotation class DebuggingCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/patch/DebuggingPatch.kt similarity index 57% rename from src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/debugging/patch/DebuggingPatch.kt index 2bebbb7f..f76b2cc9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/patch/DebuggingPatch.kt @@ -1,28 +1,26 @@ -package app.revanced.patches.youtube.misc.enabledebugging.patch +package app.revanced.patches.youtube.misc.debugging.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.* import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.youtube.misc.enabledebugging.annotations.EnableDebuggingCompatibility +import app.revanced.patches.youtube.misc.debugging.annotations.DebuggingCompatibility import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference import org.w3c.dom.Element -@Patch(false) +@Patch @Name("debugging") @DependsOn([IntegrationsPatch::class, SettingsPatch::class]) @Description("Adds debugging options.") -@EnableDebuggingCompatibility +@DebuggingCompatibility @Version("0.0.1") -class EnableDebuggingPatch : ResourcePatch { +class DebuggingPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { SettingsPatch.PreferenceScreen.MISC.addPreferences( SwitchPreference( @@ -34,18 +32,29 @@ class EnableDebuggingPatch : ResourcePatch { ) ) - // create an xml editor instance - context.xmlEditor["AndroidManifest.xml"].use { dom -> - // get the application node - val applicationNode = dom - .file - .getElementsByTagName("application") - .item(0) as Element + if (debuggable == true) { + context.xmlEditor["AndroidManifest.xml"].use { dom -> + val applicationNode = dom + .file + .getElementsByTagName("application") + .item(0) as Element - // set application as debuggable - applicationNode.setAttribute("android:debuggable", "true") + // set application as debuggable + applicationNode.setAttribute("android:debuggable", "true") + } } return PatchResultSuccess() } + + companion object : OptionsContainer() { + var debuggable: Boolean? by option( + PatchOption.BooleanOption( + key = "debuggable", + default = false, + title = "App debugging", + description = "Whether to make the app debuggable on Android.", + ) + ) + } }