fix(YouTube/Description components): add supports A/B tests for the Expand video description setting

This commit is contained in:
inotia00 2024-04-25 02:41:19 +09:00
parent 10b7895ca8
commit 16dad655ba
3 changed files with 41 additions and 3 deletions

View File

@ -1,19 +1,26 @@
package app.revanced.patches.youtube.player.descriptions package app.revanced.patches.youtube.player.descriptions
import app.revanced.patcher.data.BytecodeContext 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.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.youtube.player.descriptions.fingerprints.EngagementPanelSubHeaderFingerprint
import app.revanced.patches.youtube.player.descriptions.fingerprints.TextViewComponentFingerprint import app.revanced.patches.youtube.player.descriptions.fingerprints.TextViewComponentFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexReversed
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceName
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Suppress("unused") @Suppress("unused")
object DescriptionComponentsPatch : BaseBytecodePatch( object DescriptionComponentsPatch : BaseBytecodePatch(
@ -22,17 +29,22 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
dependencies = setOf( dependencies = setOf(
BottomSheetRecyclerViewPatch::class, BottomSheetRecyclerViewPatch::class,
LithoFilterPatch::class, LithoFilterPatch::class,
SettingsPatch::class PlayerTypeHookPatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class
), ),
compatiblePackages = COMPATIBLE_PACKAGE, compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(TextViewComponentFingerprint) fingerprints = setOf(
EngagementPanelSubHeaderFingerprint,
TextViewComponentFingerprint
)
) { ) {
private const val FILTER_CLASS_DESCRIPTOR = private const val FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/DescriptionsFilter;" "$COMPONENTS_PATH/DescriptionsFilter;"
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
// patch for Expand video description and Disable video description interaction. // patch for disable video description interaction and expand video description.
// since these patches are still A/B tested, they are classified as 'Experimental flags'. // since these patches are still A/B tested, they are classified as 'Experimental flags'.
if (SettingsPatch.upward1902) { if (SettingsPatch.upward1902) {
TextViewComponentFingerprint.resultOrThrow().let { TextViewComponentFingerprint.resultOrThrow().let {
@ -48,6 +60,17 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
} }
} }
EngagementPanelSubHeaderFingerprint.resultOrThrow().mutableMethod.apply {
val instructionIndex = getTargetIndexReversed(Opcode.INVOKE_INTERFACE) + 1
val viewRegister = getInstruction<OneRegisterInstruction>(instructionIndex).registerA
addInstruction(
instructionIndex + 1,
"invoke-static { v$viewRegister }, " +
"$PLAYER_CLASS_DESCRIPTOR->engagementPanelSubHeaderViewLoaded(Landroid/view/View;)V",
)
}
BottomSheetRecyclerViewPatch.injectCall("$PLAYER_CLASS_DESCRIPTOR->onVideoDescriptionCreate(Landroid/support/v7/widget/RecyclerView;)V") BottomSheetRecyclerViewPatch.injectCall("$PLAYER_CLASS_DESCRIPTOR->onVideoDescriptionCreate(Landroid/support/v7/widget/RecyclerView;)V")
/** /**

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.player.descriptions.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.PanelSubHeader
import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal object EngagementPanelSubHeaderFingerprint : LiteralValueFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
returnType = "V",
parameters = listOf("Landroid/view/ViewGroup;", "L"),
literalSupplier = { PanelSubHeader }
)

View File

@ -58,6 +58,7 @@ object SharedResourceIdPatch : ResourcePatch() {
var InterstitialsContainer = -1L var InterstitialsContainer = -1L
var MenuItemView = -1L var MenuItemView = -1L
var MusicAppDeeplinkButtonView = -1L var MusicAppDeeplinkButtonView = -1L
var PanelSubHeader = -1L
var PosterArtWidthDefault = -1L var PosterArtWidthDefault = -1L
var QualityAuto = -1L var QualityAuto = -1L
var QuickActionsElementContainer = -1L var QuickActionsElementContainer = -1L
@ -133,6 +134,7 @@ object SharedResourceIdPatch : ResourcePatch() {
InterstitialsContainer = getId(ID, "interstitials_container") InterstitialsContainer = getId(ID, "interstitials_container")
MenuItemView = getId(ID, "menu_item_view") MenuItemView = getId(ID, "menu_item_view")
MusicAppDeeplinkButtonView = getId(ID, "music_app_deeplink_button_view") MusicAppDeeplinkButtonView = getId(ID, "music_app_deeplink_button_view")
PanelSubHeader = getId(ID, "panel_subheader")
PosterArtWidthDefault = getId(DIMEN, "poster_art_width_default") PosterArtWidthDefault = getId(DIMEN, "poster_art_width_default")
QualityAuto = getId(STRING, "quality_auto") QualityAuto = getId(STRING, "quality_auto")
QuickActionsElementContainer = getId(ID, "quick_actions_element_container") QuickActionsElementContainer = getId(ID, "quick_actions_element_container")