mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-06-12 13:17:38 +02:00
fix(YouTube - Remove background playback restrictions): Enable for Shorts as well (#3671)
This commit is contained in:
@ -1,30 +1,33 @@
|
||||
package app.revanced.patches.youtube.misc.backgroundplayback
|
||||
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.instructions
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patcher.patch.resourcePatch
|
||||
import app.revanced.patches.all.misc.resources.addResources
|
||||
import app.revanced.patches.all.misc.resources.addResourcesPatch
|
||||
import app.revanced.patches.shared.misc.mapping.get
|
||||
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
|
||||
import app.revanced.patches.shared.misc.mapping.resourceMappings
|
||||
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
||||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
|
||||
import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch
|
||||
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
|
||||
import app.revanced.patches.youtube.misc.settings.settingsPatch
|
||||
import app.revanced.patches.youtube.video.information.videoInformationPatch
|
||||
import app.revanced.util.addInstructionsAtControlFlowLabel
|
||||
import app.revanced.util.findInstructionIndicesReversedOrThrow
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.returnEarly
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
internal var prefBackgroundAndOfflineCategoryId = -1L
|
||||
private set
|
||||
|
||||
private val backgroundPlaybackResourcePatch = resourcePatch {
|
||||
dependsOn(resourceMappingPatch)
|
||||
dependsOn(resourceMappingPatch, addResourcesPatch)
|
||||
|
||||
execute {
|
||||
prefBackgroundAndOfflineCategoryId = resourceMappings["string", "pref_background_and_offline_category"]
|
||||
@ -58,45 +61,54 @@ val backgroundPlaybackPatch = bytecodePatch(
|
||||
|
||||
val backgroundPlaybackManagerMatch by backgroundPlaybackManagerFingerprint()
|
||||
val backgroundPlaybackSettingsMatch by backgroundPlaybackSettingsFingerprint()
|
||||
|
||||
val shortsBackgroundPlaybackFeatureFlagMatch by shortsBackgroundPlaybackFeatureFlagFingerprint()
|
||||
val backgroundPlaybackManagerShortsMatch by backgroundPlaybackManagerShortsFingerprint()
|
||||
|
||||
val kidsBackgroundPlaybackPolicyControllerMatch by kidsBackgroundPlaybackPolicyControllerFingerprint()
|
||||
|
||||
execute { context ->
|
||||
backgroundPlaybackManagerMatch.mutableMethod.apply {
|
||||
findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index ->
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
addResources("youtube", "misc.backgroundplayback.backgroundPlaybackPatch")
|
||||
|
||||
addInstructionsAtControlFlowLabel(
|
||||
index,
|
||||
"""
|
||||
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->allowBackgroundPlayback(Z)Z
|
||||
move-result v$register
|
||||
""",
|
||||
)
|
||||
PreferenceScreen.SHORTS.addPreferences(
|
||||
SwitchPreference("revanced_shorts_disable_background_playback")
|
||||
)
|
||||
|
||||
arrayOf(
|
||||
backgroundPlaybackManagerMatch to "isBackgroundPlaybackAllowed",
|
||||
backgroundPlaybackManagerShortsMatch to "isBackgroundShortsPlaybackAllowed"
|
||||
).forEach { (match, integrationsMethod) ->
|
||||
match.mutableMethod.apply {
|
||||
findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index ->
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
|
||||
addInstructionsAtControlFlowLabel(
|
||||
index,
|
||||
"""
|
||||
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->$integrationsMethod(Z)Z
|
||||
move-result v$register
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enable background playback option in YouTube settings
|
||||
backgroundPlaybackSettingsMatch.mutableMethod.apply {
|
||||
val booleanCalls = instructions.withIndex()
|
||||
.filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
|
||||
val booleanCalls = instructions.withIndex().filter {
|
||||
it.value.getReference<MethodReference>()?.returnType == "Z"
|
||||
}
|
||||
|
||||
val settingsBooleanIndex = booleanCalls.elementAt(1).index
|
||||
val settingsBooleanMethod = context.navigate(this).at(settingsBooleanIndex).mutable()
|
||||
|
||||
settingsBooleanMethod.addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->overrideBackgroundPlaybackAvailable()Z
|
||||
move-result v0
|
||||
return v0
|
||||
""",
|
||||
)
|
||||
settingsBooleanMethod.returnEarly(true)
|
||||
}
|
||||
|
||||
// Force allowing background play for Shorts.
|
||||
shortsBackgroundPlaybackFeatureFlagMatch.mutableMethod.returnEarly(true)
|
||||
|
||||
// Force allowing background play for videos labeled for kids.
|
||||
kidsBackgroundPlaybackPolicyControllerMatch.mutableMethod.addInstruction(
|
||||
0,
|
||||
"return-void",
|
||||
)
|
||||
kidsBackgroundPlaybackPolicyControllerMatch.mutableMethod.returnEarly()
|
||||
}
|
||||
}
|
||||
|
@ -70,3 +70,17 @@ internal val kidsBackgroundPlaybackPolicyControllerFingerprint = fingerprint {
|
||||
)
|
||||
literal { 5 }
|
||||
}
|
||||
|
||||
internal val backgroundPlaybackManagerShortsFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
|
||||
returns("Z")
|
||||
parameters("L")
|
||||
literal { 151635310 }
|
||||
}
|
||||
|
||||
internal val shortsBackgroundPlaybackFeatureFlagFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||
returns("Z")
|
||||
parameters()
|
||||
literal { 45415425 }
|
||||
}
|
@ -86,6 +86,11 @@ This is because Crowdin requires temporarily flattening this file and removing t
|
||||
<string name="revanced_settings_screen_11_misc_title">Misc</string>
|
||||
<string name="revanced_settings_screen_12_video_title">Video</string>
|
||||
</patch>
|
||||
<patch id="misc.backgroundplayback.backgroundPlaybackPatch">
|
||||
<string name="revanced_shorts_disable_background_playback_title">Disable Shorts background play</string>
|
||||
<string name="revanced_shorts_disable_background_playback_summary_on">Shorts background play is disabled</string>
|
||||
<string name="revanced_shorts_disable_background_playback_summary_off">Shorts background play is enabled</string>
|
||||
</patch>
|
||||
<patch id="misc.debugging.enableDebuggingPatch">
|
||||
<string name="revanced_debug_screen_title">Debugging</string>
|
||||
<string name="revanced_debug_screen_summary">Enable or disable debugging options</string>
|
||||
|
Reference in New Issue
Block a user