Skip to content

Commit

Permalink
fix(YouTube Music - Player components): Hide Audio / Video toggle s…
Browse files Browse the repository at this point in the history
…etting not working in landscape mode
  • Loading branch information
anddea committed Oct 15, 2024
1 parent 948ab9e commit e171e45
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.player.components.fingerprints.AudioVideoSwitchToggleFingerprint
import app.revanced.patches.music.player.components.fingerprints.AudioVideoSwitchToggleFingerprint.AUDIO_VIDEO_SWITCH_TOGGLE_VISIBILITY
import app.revanced.patches.music.player.components.fingerprints.EngagementPanelHeightFingerprint
import app.revanced.patches.music.player.components.fingerprints.EngagementPanelHeightParentFingerprint
import app.revanced.patches.music.player.components.fingerprints.HandleSearchRenderedFingerprint
Expand Down Expand Up @@ -46,7 +48,6 @@ import app.revanced.patches.music.utils.integrations.Constants.INTEGRATIONS_PATH
import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.AudioVideoSwitchToggle
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ColorGrey
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.DarkBackground
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerPlayPauseReplayButton
Expand Down Expand Up @@ -629,14 +630,25 @@ object PlayerComponentsPatch : BaseBytecodePatch(
// region patch for hide audio video switch toggle

AudioVideoSwitchToggleFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(AudioVideoSwitchToggle)
val viewIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val viewRegister = getInstruction<OneRegisterInstruction>(viewIndex).registerA

addInstruction(
viewIndex + 1,
"invoke-static {v$viewRegister}, $PLAYER_CLASS_DESCRIPTOR->hideAudioVideoSwitchToggle(Landroid/view/View;)V"
)
implementation!!.instructions
.withIndex()
.filter { (_, instruction) ->
val reference = (instruction as? ReferenceInstruction)?.reference
instruction.opcode == Opcode.INVOKE_VIRTUAL &&
reference is MethodReference &&
reference.toString() == AUDIO_VIDEO_SWITCH_TOGGLE_VISIBILITY
}
.map { (index, _) -> index }
.reversed()
.forEach { index ->
val instruction = getInstruction<FiveRegisterInstruction>(index)

replaceInstruction(
index,
"invoke-static {v${instruction.registerC}, v${instruction.registerD}}," +
"$PLAYER_CLASS_DESCRIPTOR->hideAudioVideoSwitchToggle(Landroid/view/View;I)V"
)
}
}

SettingsPatch.addSwitchPreference(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package app.revanced.patches.music.player.components.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.AudioVideoSwitchToggle
import app.revanced.util.fingerprint.LiteralValueFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.player.components.fingerprints.AudioVideoSwitchToggleFingerprint.AUDIO_VIDEO_SWITCH_TOGGLE_VISIBILITY
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal object AudioVideoSwitchToggleFingerprint : LiteralValueFingerprint(
internal object AudioVideoSwitchToggleFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
literalSupplier = { AudioVideoSwitchToggle },
)
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
customFingerprint = { methodDef, _ ->
methodDef.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.toString() == AUDIO_VIDEO_SWITCH_TOGGLE_VISIBILITY
} >= 0
}
) {
const val AUDIO_VIDEO_SWITCH_TOGGLE_VISIBILITY =
"Lcom/google/android/apps/youtube/music/player/AudioVideoSwitcherToggleView;->setVisibility(I)V"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import app.revanced.patches.shared.mapping.ResourceType.STYLE
@Patch(dependencies = [ResourceMappingPatch::class])
object SharedResourceIdPatch : ResourcePatch() {
var AccountSwitcherAccessibility = -1L
var AudioVideoSwitchToggle = -1L
var BottomSheetRecyclerView = -1L
var ButtonContainer = -1L
var ButtonIconPaddingMedium = -1L
Expand Down Expand Up @@ -62,7 +61,6 @@ object SharedResourceIdPatch : ResourcePatch() {
override fun execute(context: ResourceContext) {

AccountSwitcherAccessibility = getId(STRING, "account_switcher_accessibility_label")
AudioVideoSwitchToggle = getId(ID, "audio_video_switch_toggle")
BottomSheetRecyclerView = getId(LAYOUT, "bottom_sheet_recycler_view")
ButtonContainer = getId(ID, "button_container")
ButtonIconPaddingMedium = getId(DIMEN, "button_icon_padding_medium")
Expand Down

0 comments on commit e171e45

Please sign in to comment.