diff --git a/api/revanced-patches.api b/api/revanced-patches.api index f0d4cd1a33..4907b36990 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -350,6 +350,10 @@ public final class app/revanced/patches/music/misc/androidauto/BypassCertificate public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/music/misc/debugging/DebuggingPatch : app/revanced/patches/shared/misc/debugging/BaseDebuggingPatch { + public static final field INSTANCE Lapp/revanced/patches/music/misc/debugging/DebuggingPatch; +} + public final class app/revanced/patches/music/misc/gms/Constants { public static final field INSTANCE Lapp/revanced/patches/music/misc/gms/Constants; } @@ -366,6 +370,26 @@ public final class app/revanced/patches/music/misc/integrations/IntegrationsPatc public static final field INSTANCE Lapp/revanced/patches/music/misc/integrations/IntegrationsPatch; } +public final class app/revanced/patches/music/misc/settings/SettingsPatch : app/revanced/patcher/patch/BytecodePatch, java/io/Closeable { + public static final field INSTANCE Lapp/revanced/patches/music/misc/settings/SettingsPatch; + public fun close ()V + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V + public final fun newIntent (Ljava/lang/String;)Lapp/revanced/patches/shared/misc/settings/preference/IntentPreference$Intent; +} + +public final class app/revanced/patches/music/misc/settings/SettingsPatch$PreferenceScreen : app/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen { + public static final field INSTANCE Lapp/revanced/patches/music/misc/settings/SettingsPatch$PreferenceScreen; + public fun commit (Lapp/revanced/patches/shared/misc/settings/preference/PreferenceScreen;)V + public final fun getMISC ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen; +} + +public final class app/revanced/patches/music/misc/settings/SettingsResourcePatch : app/revanced/patches/shared/misc/settings/BaseSettingsResourcePatch { + public static final field INSTANCE Lapp/revanced/patches/music/misc/settings/SettingsResourcePatch; + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V + public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V +} + public final class app/revanced/patches/music/premium/backgroundplay/BackgroundPlayPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/music/premium/backgroundplay/BackgroundPlayPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V @@ -596,6 +620,13 @@ public final class app/revanced/patches/serviceportalbund/detection/root/RootDet public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public abstract class app/revanced/patches/shared/misc/debugging/BaseDebuggingPatch : app/revanced/patcher/patch/ResourcePatch { + public fun (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;Ljava/util/Set;Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;Ljava/util/Set;Ljava/util/Set;)V + public synthetic fun (Lkotlin/reflect/KClass;Lkotlin/reflect/KClass;Ljava/util/Set;Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;Ljava/util/Set;Ljava/util/Set;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V + public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V +} + public final class app/revanced/patches/shared/misc/fix/verticalscroll/VerticalScrollPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/shared/misc/fix/verticalscroll/VerticalScrollPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V @@ -1502,7 +1533,7 @@ public final class app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } -public final class app/revanced/patches/youtube/misc/debugging/DebuggingPatch : app/revanced/patcher/patch/ResourcePatch { +public final class app/revanced/patches/youtube/misc/debugging/DebuggingPatch : app/revanced/patches/shared/misc/debugging/BaseDebuggingPatch { public static final field INSTANCE Lapp/revanced/patches/youtube/misc/debugging/DebuggingPatch; public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V diff --git a/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt new file mode 100644 index 0000000000..edcf34bbf0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.music.misc.debugging + +import app.revanced.patches.music.misc.integrations.IntegrationsPatch +import app.revanced.patches.music.misc.settings.SettingsPatch +import app.revanced.patches.shared.misc.debugging.BaseDebuggingPatch + +@Suppress("unused") +object DebuggingPatch : BaseDebuggingPatch( + integrationsPatch = IntegrationsPatch::class, + settingsPatch = SettingsPatch::class, + compatiblePackages = setOf(CompatiblePackage("com.google.android.apps.youtube.music")), + miscPreferenceScreen = SettingsPatch.PreferenceScreen.MISC, +) diff --git a/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt new file mode 100644 index 0000000000..da05895649 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt @@ -0,0 +1,70 @@ +package app.revanced.patches.music.misc.settings + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.all.misc.packagename.ChangePackageNamePatch +import app.revanced.patches.all.misc.resources.AddResourcesPatch +import app.revanced.patches.music.misc.integrations.IntegrationsPatch +import app.revanced.patches.music.misc.settings.fingerprints.FullStackTraceActivityFingerprint +import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen +import app.revanced.patches.shared.misc.settings.preference.IntentPreference +import app.revanced.util.exception +import com.android.tools.smali.dexlib2.util.MethodUtil +import java.io.Closeable + +@Patch( + description = "Adds settings for ReVanced to YouTube Music.", + dependencies = [ + IntegrationsPatch::class, + SettingsResourcePatch::class, + AddResourcesPatch::class + ] +) +object SettingsPatch : BytecodePatch( + setOf(FullStackTraceActivityFingerprint) +), Closeable { + private const val INTEGRATIONS_PACKAGE = "app/revanced/integrations/music" + private const val ACTIVITY_HOOK_CLASS_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/settings/FullStackTraceActivityHook;" + + override fun execute(context: BytecodeContext) { + AddResourcesPatch(this::class) + + FullStackTraceActivityFingerprint.result?.let { result -> + result.mutableMethod.addInstructions( + 1, + """ + invoke-static { p0 }, $ACTIVITY_HOOK_CLASS_DESCRIPTOR->initialize(Landroid/app/Activity;)V + return-void + """ + ) + + // Remove other methods as they will break as the onCreate method is modified above. + result.mutableClass.apply { + methods.removeIf { it.name != "onCreate" && !MethodUtil.isConstructor(it) } + } + } ?: throw FullStackTraceActivityFingerprint.exception + } + + /** + * Creates an intent to open ReVanced settings. + */ + fun newIntent(settingsName: String) = IntentPreference.Intent( + data = settingsName, + targetClass = "com.google.android.libraries.strictmode.penalties.notification.FullStackTraceActivity" + ) { + // The package name change has to be reflected in the intent. + ChangePackageNamePatch.setOrGetFallbackPackageName("com.google.android.apps.youtube.music") + } + + object PreferenceScreen : BasePreferenceScreen() { + val MISC = Screen("revanced_misc_screen") + + override fun commit(screen: app.revanced.patches.shared.misc.settings.preference.PreferenceScreen) { + SettingsResourcePatch += screen + } + } + + override fun close() = PreferenceScreen.close() +} diff --git a/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsResourcePatch.kt new file mode 100644 index 0000000000..b1a392ad99 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsResourcePatch.kt @@ -0,0 +1,31 @@ +package app.revanced.patches.music.misc.settings + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patches.all.misc.resources.AddResourcesPatch +import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch +import app.revanced.patches.shared.misc.settings.BaseSettingsResourcePatch +import app.revanced.patches.shared.misc.settings.preference.IntentPreference +import app.revanced.util.ResourceGroup +import app.revanced.util.copyResources + +object SettingsResourcePatch : BaseSettingsResourcePatch( + IntentPreference( + "revanced_settings", + intent = SettingsPatch.newIntent("revanced_settings_intent") + ) to "settings_headers", + dependencies = setOf( + ResourceMappingPatch::class, + AddResourcesPatch::class, + ) +) { + override fun execute(context: ResourceContext) { + super.execute(context) + + AddResourcesPatch(this::class) + + context.copyResources( + "settings", + ResourceGroup("layout", "revanced_settings_with_toolbar.xml") + ) + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/misc/settings/fingerprints/FullStackTraceActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/settings/fingerprints/FullStackTraceActivityFingerprint.kt new file mode 100644 index 0000000000..c350d31bb8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/settings/fingerprints/FullStackTraceActivityFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.music.misc.settings.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object FullStackTraceActivityFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("Landroid/os/Bundle;"), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/FullStackTraceActivity;") && methodDef.name == "onCreate" + } +) diff --git a/src/main/kotlin/app/revanced/patches/shared/misc/debugging/BaseDebuggingPatch.kt b/src/main/kotlin/app/revanced/patches/shared/misc/debugging/BaseDebuggingPatch.kt new file mode 100644 index 0000000000..14d5e46f7f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/misc/debugging/BaseDebuggingPatch.kt @@ -0,0 +1,42 @@ +package app.revanced.patches.shared.misc.debugging + +import app.revanced.patcher.PatchClass +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.all.misc.resources.AddResourcesPatch +import app.revanced.patches.shared.misc.settings.preference.BasePreference +import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen +import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen +import app.revanced.patches.shared.misc.settings.preference.SwitchPreference + +abstract class BaseDebuggingPatch( + integrationsPatch: PatchClass, + settingsPatch: PatchClass, + compatiblePackages: Set, + // TODO: Settings patch should probably be abstracted + // so we do not have to pass it in as a dependency AND it's preference screen at the same time. + private val miscPreferenceScreen: BasePreferenceScreen.Screen, + private val additionalDebugPreferences: Set = emptySet(), + additionalDependencies: Set = emptySet(), +) : ResourcePatch( + name = "Enable debugging", + description = "Adds options for debugging.", + dependencies = setOf(integrationsPatch, settingsPatch) + AddResourcesPatch::class + additionalDependencies, + compatiblePackages = compatiblePackages, +) { + override fun execute(context: ResourceContext) { + AddResourcesPatch(BaseDebuggingPatch::class) + + miscPreferenceScreen.addPreferences( + PreferenceScreen( + "revanced_debug_screen", + sorting = PreferenceScreen.Sorting.UNSORTED, + preferences = setOf( + SwitchPreference("revanced_debug"), + SwitchPreference("revanced_debug_stacktrace"), + SwitchPreference("revanced_debug_toast_on_error"), + ) + additionalDebugPreferences, + ), + ) + } +} diff --git a/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt index 719c65593d..c26476e9a7 100644 --- a/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt @@ -12,9 +12,9 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.all.misc.resources.AddResourcesPatch +import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen import app.revanced.patches.shared.misc.settings.preference.PreferenceCategory import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen import app.revanced.patches.twitch.misc.integrations.IntegrationsPatch import app.revanced.patches.twitch.misc.settings.fingerprints.MenuGroupsOnClickFingerprint import app.revanced.patches.twitch.misc.settings.fingerprints.MenuGroupsUpdatedFingerprint @@ -47,7 +47,7 @@ object SettingsPatch : BytecodePatch( ), Closeable { private const val REVANCED_SETTINGS_MENU_ITEM_NAME = "RevancedSettings" private const val REVANCED_SETTINGS_MENU_ITEM_ID = 0x7 - private const val REVANCED_SETTINGS_MENU_ITEM_TITLE_RES = "revanced_settings" + private const val REVANCED_SETTINGS_MENU_ITEM_TITLE_RES = "revanced_settings_title" private const val REVANCED_SETTINGS_MENU_ITEM_ICON_RES = "ic_settings" private const val MENU_ITEM_ENUM_CLASS_DESCRIPTOR = "Ltv/twitch/android/feature/settings/menu/SettingsMenuItem;" diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/DebuggingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/DebuggingPatch.kt index 523a76d552..0db6a5accc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/DebuggingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/DebuggingPatch.kt @@ -1,38 +1,26 @@ package app.revanced.patches.youtube.misc.debugging import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patcher.patch.annotation.CompatiblePackage -import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.all.misc.resources.AddResourcesPatch -import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen -import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen.Sorting +import app.revanced.patches.shared.misc.debugging.BaseDebuggingPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch -@Patch( - name = "Enable debugging", - description = "Adds options for debugging.", - dependencies = [IntegrationsPatch::class, SettingsPatch::class, AddResourcesPatch::class], - compatiblePackages = [CompatiblePackage("com.google.android.youtube")], -) @Suppress("unused") -object DebuggingPatch : ResourcePatch() { +object DebuggingPatch : BaseDebuggingPatch( + integrationsPatch = IntegrationsPatch::class, + settingsPatch = SettingsPatch::class, + compatiblePackages = setOf(CompatiblePackage("com.google.android.youtube")), + miscPreferenceScreen = SettingsPatch.PreferenceScreen.MISC, + additionalDebugPreferences = setOf( + SwitchPreference("revanced_debug_protobuffer") + ), + additionalDependencies = setOf(AddResourcesPatch::class) +) { override fun execute(context: ResourceContext) { AddResourcesPatch(this::class) - SettingsPatch.PreferenceScreen.MISC.addPreferences( - PreferenceScreen( - key = "revanced_debug_screen", - sorting = Sorting.UNSORTED, - preferences = setOf( - SwitchPreference("revanced_debug"), - SwitchPreference("revanced_debug_protobuffer"), - SwitchPreference("revanced_debug_stacktrace"), - SwitchPreference("revanced_debug_toast_on_error"), - ), - ), - ) + super.execute(context) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsResourcePatch.kt index 3f8b1d16d2..243df6a209 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsResourcePatch.kt @@ -36,11 +36,10 @@ object SettingsResourcePatch : BaseSettingsResourcePatch( it.type == "string" && it.name == "app_theme_appearance_dark" }!!.id - arrayOf( + context.copyResources( + "settings", ResourceGroup("layout", "revanced_settings_with_toolbar.xml"), - ).forEach { resourceGroup -> - context.copyResources("settings", resourceGroup) - } + ) // Remove horizontal divider from the settings Preferences // To better match the appearance of the stock YouTube settings. diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index c7461f6219..e1711b6b47 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -1,7 +1,6 @@ - ReVanced Do you wish to proceed? Reset Refresh and restart @@ -16,10 +15,24 @@ GmsCore is not installed. Please install. GmsCore is failing to run. Please follow the \"Don\'t kill my app\" guide for GmsCore. + + Debugging + Enable or disable debugging options + Debug logging + Debug logs are enabled + Debug logs are disabled + Log stack traces + Debug logs include stack trace + Debug logs do not include stack trace + Show toast on ReVanced error + Toast shown if error occurs + Toast not shown if error occurs + Turning off error toasts hides all ReVanced error notifications.\n\nYou will not be notified of any unexpected events. + - ReVanced + ReVanced Import / Export Import / Export ReVanced settings @@ -36,21 +49,9 @@ Video - Debugging - Enable or disable debugging options - Debug logging - Debug logs are enabled - Debug logs are disabled Log protocol buffer Debug logs include proto buffer Debug logs do not include proto buffer - Log stack traces - Debug logs include stack trace - Debug logs do not include stack trace - Show toast on ReVanced error - Toast shown if error occurs - Toast not shown if error occurs - Turning off error toasts hides all ReVanced error notifications.\n\nYou will not be notified of any unexpected events. Hide gray separator @@ -983,7 +984,7 @@ Twitch debug mode is disabled - ReVanced Settings + ReVanced Ads Ad blocking settings Chat diff --git a/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml b/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml index c78967c615..1c91a9bc65 100644 --- a/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml +++ b/src/main/resources/settings/layout/revanced_settings_with_toolbar.xml @@ -21,7 +21,7 @@ android:layout_height="?attr/actionBarSize" android:background="?attr/ytBrandBackgroundSolid" app:navigationIcon="@drawable/yt_outline_arrow_left_black_24" - app:title="@string/revanced_settings" /> + app:title="@string/revanced_settings_title" />