fix(YouTube Music - Hide ads): Renewal banner or update banner disappears too late

This commit is contained in:
inotia00
2025-01-31 20:28:54 +09:00
parent 9b56cb6c0d
commit a50eed6466
5 changed files with 125 additions and 15 deletions

View File

@ -7,6 +7,7 @@ import app.revanced.patches.music.navigation.components.navigationBarComponentsP
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.extension.Constants.ADS_PATH
import app.revanced.patches.music.utils.extension.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.navigation.navigationBarHookPatch
import app.revanced.patches.music.utils.patch.PatchList.HIDE_ADS
import app.revanced.patches.music.utils.resourceid.buttonContainer
import app.revanced.patches.music.utils.resourceid.floatingLayout
@ -55,6 +56,7 @@ val adsPatch = bytecodePatch(
baseAdsPatch("$ADS_PATH/MusicAdsPatch;", "hideMusicAds"),
lithoFilterPatch,
navigationBarComponentsPatch, // for 'Hide upgrade button' setting
navigationBarHookPatch,
sharedResourceIdPatch,
)

View File

@ -0,0 +1,30 @@
package app.revanced.patches.music.utils.navigation
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal val tabLayoutViewSetSelectedFingerprint = legacyFingerprint(
name = "tabLayoutViewSetSelectedFingerprint",
returnType = "V",
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
parameters = listOf("I"),
customFingerprint = { method, classDef ->
classDef.type == "Lcom/google/android/material/tabs/TabLayout;" &&
indexOfChildAtInstruction(method) >= 0 &&
indexOfSetViewActivatedInstruction(method) >= 0
}
)
internal fun indexOfChildAtInstruction(method: Method) = method.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>()?.name == "getChildAt"
}
private fun indexOfSetViewActivatedInstruction(method: Method) = method.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>()?.name == "setActivated"
}

View File

@ -0,0 +1,48 @@
package app.revanced.patches.music.utils.navigation
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.music.utils.extension.Constants.SHARED_PATH
import app.revanced.patches.music.utils.extension.sharedExtensionPatch
import app.revanced.util.fingerprint.methodOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal const val EXTENSION_CLASS_DESCRIPTOR =
"$SHARED_PATH/NavigationBar;"
val navigationBarHookPatch = bytecodePatch(
description = "navigationBarHookPatch",
) {
dependsOn(sharedExtensionPatch)
execute {
tabLayoutViewSetSelectedFingerprint.methodOrThrow().apply {
val childAtIndex = indexOfChildAtInstruction(this)
val tabIndexRegister =
getInstruction<FiveRegisterInstruction>(childAtIndex).registerD
implementation!!.instructions
.withIndex()
.filter { (_, instruction) ->
val reference = (instruction as? ReferenceInstruction)?.reference
reference is MethodReference &&
reference.name == "setActivated"
}
.map { (index, _) -> index }
.reversed()
.forEach { index ->
val isSelectedRegister =
getInstruction<FiveRegisterInstruction>(childAtIndex).registerD
addInstruction(
index,
"invoke-static {v$tabIndexRegister, v$isSelectedRegister}, " +
"$EXTENSION_CLASS_DESCRIPTOR->navigationTabSelected(IZ)V"
)
}
}
}
}