Skip to content

Commit

Permalink
feat(YouTube & YouTube Music - Hide settings menu): Add switch prefer…
Browse files Browse the repository at this point in the history
…ences for each setting entry
  • Loading branch information
anddea committed Oct 15, 2024
1 parent 00793d8 commit 3c9e660
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 85 deletions.
18 changes: 0 additions & 18 deletions src/main/kotlin/app/revanced/patches/music/ads/general/AdsPatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package app.revanced.patches.music.ads.general

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patches.music.ads.general.MusicAdsPatch.hookLithoFullscreenAds
import app.revanced.patches.music.ads.general.MusicAdsPatch.hookNonLithoFullscreenAds
import app.revanced.patches.music.ads.general.fingerprints.AccountMenuFooterFingerprint
import app.revanced.patches.music.ads.general.fingerprints.FloatingLayoutFingerprint
import app.revanced.patches.music.ads.general.fingerprints.GetPremiumTextViewFingerprint
import app.revanced.patches.music.ads.general.fingerprints.InterstitialsContainerFingerprint
import app.revanced.patches.music.ads.general.fingerprints.MembershipSettingsFingerprint
import app.revanced.patches.music.ads.general.fingerprints.MembershipSettingsParentFingerprint
import app.revanced.patches.music.ads.general.fingerprints.NotifierShelfFingerprint
import app.revanced.patches.music.ads.general.fingerprints.ShowDialogCommandFingerprint
import app.revanced.patches.music.navigation.components.NavigationBarComponentsPatch
Expand Down Expand Up @@ -55,7 +52,6 @@ object AdsPatch : BaseBytecodePatch(
FloatingLayoutFingerprint,
GetPremiumTextViewFingerprint,
InterstitialsContainerFingerprint,
MembershipSettingsParentFingerprint,
NotifierShelfFingerprint,
ShowDialogCommandFingerprint
)
Expand Down Expand Up @@ -163,20 +159,6 @@ object AdsPatch : BaseBytecodePatch(
}
}

// premium membership menu in settings
MembershipSettingsFingerprint.resolve(
context,
MembershipSettingsParentFingerprint.resultOrThrow().classDef
)
MembershipSettingsFingerprint.resultOrThrow().mutableMethod.addInstructions(
0, """
const/4 v0, 0x0
return-object v0
"""
)

// endregion

LithoFilterPatch.addFilter(ADS_FILTER_CLASS_DESCRIPTOR)

SettingsPatch.addSwitchPreference(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import app.revanced.patches.music.general.components.fingerprints.FloatingButton
import app.revanced.patches.music.general.components.fingerprints.HistoryMenuItemFingerprint
import app.revanced.patches.music.general.components.fingerprints.HistoryMenuItemOfflineTabFingerprint
import app.revanced.patches.music.general.components.fingerprints.MediaRouteButtonFingerprint
import app.revanced.patches.music.general.components.fingerprints.ParentToolMenuFingerprint
import app.revanced.patches.music.general.components.fingerprints.PlayerOverlayChipFingerprint
import app.revanced.patches.music.general.components.fingerprints.PreferenceScreenFingerprint
import app.revanced.patches.music.general.components.fingerprints.SearchBarFingerprint
import app.revanced.patches.music.general.components.fingerprints.SearchBarParentFingerprint
import app.revanced.patches.music.general.components.fingerprints.SoundSearchFingerprint
Expand All @@ -26,6 +28,7 @@ import app.revanced.patches.music.general.components.fingerprints.TopBarMenuItem
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.integrations.Constants.GENERAL_PATH
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicTasteBuilderShelf
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerOverlayChip
Expand Down Expand Up @@ -62,17 +65,20 @@ object LayoutComponentsPatch : BaseBytecodePatch(
HistoryMenuItemFingerprint,
HistoryMenuItemOfflineTabFingerprint,
MediaRouteButtonFingerprint,
ParentToolMenuFingerprint,
PlayerOverlayChipFingerprint,
PreferenceScreenFingerprint,
SearchBarParentFingerprint,
SoundSearchFingerprint,
TasteBuilderConstructorFingerprint,
TooltipContentViewFingerprint,
TopBarMenuItemImageViewFingerprint
)
) {
private const val INTEGRATIONS_SETTINGS_MENU_DESCRIPTOR =
"$GENERAL_PATH/SettingsMenuPatch;"
private const val CUSTOM_FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/CustomFilter;"

private const val LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/LayoutComponentsFilter;"

Expand Down Expand Up @@ -194,6 +200,35 @@ object LayoutComponentsPatch : BaseBytecodePatch(

// endregion

// region patch for hide setting menus

PreferenceScreenFingerprint.resultOrThrow().mutableMethod.apply {
addInstructions(
implementation!!.instructions.lastIndex, """
invoke-virtual/range {p0 .. p0}, Lcom/google/android/apps/youtube/music/settings/fragment/SettingsHeadersFragment;->getPreferenceScreen()Landroidx/preference/PreferenceScreen;
move-result-object v0
invoke-static {v0}, $INTEGRATIONS_SETTINGS_MENU_DESCRIPTOR->hideSettingsMenu(Landroidx/preference/PreferenceScreen;)V
"""
)
}

// The lowest version supported by the patch does not have parent tool settings
ParentToolMenuFingerprint.result?.let {
it.mutableMethod.apply {
val index = it.scanResult.patternScanResult!!.startIndex + 1
val register = getInstruction<FiveRegisterInstruction>(index).registerD

addInstructions(
index, """
invoke-static {v$register}, $INTEGRATIONS_SETTINGS_MENU_DESCRIPTOR->hideParentToolsMenu(Z)Z
move-result v$register
"""
)
}
}

// endregion

// region patch for hide sound search button

SoundSearchFingerprint.result?.let {
Expand Down Expand Up @@ -299,16 +334,6 @@ object LayoutComponentsPatch : BaseBytecodePatch(
"revanced_custom_filter_strings",
"revanced_custom_filter"
)
SettingsPatch.addSwitchPreference(
CategoryType.GENERAL,
"revanced_hide_settings_menu",
"false"
)
SettingsPatch.addPreferenceWithIntent(
CategoryType.GENERAL,
"revanced_hide_settings_menu_filter_strings",
"revanced_hide_settings_menu"
)
SettingsPatch.addSwitchPreference(
CategoryType.GENERAL,
"revanced_hide_button_shelf",
Expand Down Expand Up @@ -373,5 +398,66 @@ object LayoutComponentsPatch : BaseBytecodePatch(
"revanced_hide_voice_search_button",
"false"
)

SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_parent_tools",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_general",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_playback",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_data_saving",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_downloads_and_storage",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_notification",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_privacy_and_location",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_recommendations",
"false",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_paid_memberships",
"true",
false
)
SettingsPatch.addSwitchPreference(
CategoryType.SETTINGS,
"revanced_hide_settings_menu_about",
"false",
false
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.revanced.patches.music.general.components.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object ParentToolMenuFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.CONST_4,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET,
),
strings = listOf("pref_key_parent_tools"),
customFingerprint = { methodDef, _ ->
methodDef.name == "onSettingsLoaded"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.revanced.patches.music.general.components.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

internal object PreferenceScreenFingerprint : MethodFingerprint(
returnType = "V",
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/apps/youtube/music/settings/fragment/SettingsHeadersFragment;" &&
methodDef.name == "onCreatePreferences"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum class CategoryType(val value: String, var added: Boolean) {
FLYOUT("flyout", false),
NAVIGATION("navigation", false),
PLAYER("player", false),
SETTINGS("settings", false),
VIDEO("video", false),
RETURN_YOUTUBE_DISLIKE("ryd", false),
SPONSOR_BLOCK("sb", false),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
package app.revanced.patches.shared.settingmenu

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.patches.shared.settingmenu.fingerprints.SettingsMenuFingerprint
import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import app.revanced.patches.shared.settingmenu.fingerprints.FindPreferenceFingerprint
import app.revanced.patches.shared.settingmenu.fingerprints.RemovePreferenceFingerprint
import app.revanced.util.findMethodOrThrow
import app.revanced.util.getMethodCall

@Patch(
description = "Hide the settings menu for YouTube or YouTube Music.",
dependencies = [ViewGroupMarginLayoutParamsHookPatch::class]
)
object SettingsMenuPatch : BytecodePatch(
setOf(SettingsMenuFingerprint)
setOf(
FindPreferenceFingerprint,
RemovePreferenceFingerprint
)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$PATCHES_PATH/SettingsMenuPatch;"
"$PATCHES_PATH/BaseSettingsMenuPatch;"

override fun execute(context: BytecodeContext) {

SettingsMenuFingerprint.resultOrThrow().mutableMethod.apply {
val insertIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.type == "Landroid/support/v7/widget/RecyclerView;"
}
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val findPreferenceMethodCall = FindPreferenceFingerprint.getMethodCall()
val removePreferenceMethodCall = RemovePreferenceFingerprint.getMethodCall()

addInstruction(
insertIndex,
"invoke-static {v$insertRegister}, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideSettingsMenu(Landroid/support/v7/widget/RecyclerView;)V"
)
}
context.findMethodOrThrow(INTEGRATIONS_CLASS_DESCRIPTOR) {
name == "removePreference"
}.addInstructionsWithLabels(
0, """
invoke-virtual {p0, p1}, $findPreferenceMethodCall
move-result-object v0
if-eqz v0, :ignore
invoke-virtual {p0, v0}, $removePreferenceMethodCall
:ignore
return-void
"""
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.revanced.patches.shared.settingmenu.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object FindPreferenceFingerprint : MethodFingerprint(
returnType = "Landroidx/preference/Preference;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Ljava/lang/CharSequence;"),
strings = listOf("Key cannot be null"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Landroidx/preference/PreferenceGroup;"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.patches.shared.settingmenu.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object RemovePreferenceFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroidx/preference/Preference;"),
opcodes = listOf(Opcode.INVOKE_VIRTUAL),
customFingerprint = custom@{ methodDef, _ ->
if (methodDef.definingClass != "Landroidx/preference/PreferenceGroup;") {
return@custom false
}
val instructions = methodDef.implementation?.instructions ?: return@custom false
instructions.elementAt(0).opcode == Opcode.INVOKE_DIRECT
}
)

This file was deleted.

Loading

0 comments on commit 3c9e660

Please sign in to comment.