diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt new file mode 100644 index 00000000..9a9f629b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt @@ -0,0 +1,23 @@ +package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("I", "L", "L"), + opcodes = listOf( + Opcode.IF_EQZ, + Opcode.SGET_OBJECT, + Opcode.IF_NE, + Opcode.CONST_4, + Opcode.IPUT_BOOLEAN, + Opcode.IF_EQZ, + Opcode.IGET, + Opcode.INVOKE_STATIC + ), + customFingerprint = { it.definingClass.endsWith("MinimizedPlaybackPolicyController;") } +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt index a7676589..ee2ad6f2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.toMethodWalker +import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult @@ -17,6 +18,7 @@ import app.revanced.patches.shared.settings.preference.impl.NonInteractivePrefer import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.minimizedplayback.annotations.MinimizedPlaybackCompatibility +import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.KidsMinimizedPlaybackPolicyControllerFingerprint import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackSettingsFingerprint import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch @@ -33,7 +35,8 @@ import org.jf.dexlib2.iface.reference.MethodReference class MinimizedPlaybackPatch : BytecodePatch( listOf( MinimizedPlaybackManagerFingerprint, - MinimizedPlaybackSettingsFingerprint + MinimizedPlaybackSettingsFingerprint, + KidsMinimizedPlaybackPolicyControllerFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -73,6 +76,15 @@ class MinimizedPlaybackPatch : BytecodePatch( ) } ?: return MinimizedPlaybackSettingsFingerprint.toErrorResult() + // Force allowing background play for videos labeled for kids. + // Some regions and YouTube accounts do not require this patch. + KidsMinimizedPlaybackPolicyControllerFingerprint.result?.apply { + mutableMethod.addInstruction( + 0, + "return-void" + ) + } ?: return KidsMinimizedPlaybackPolicyControllerFingerprint.toErrorResult() + return PatchResultSuccess() }