11package app.revanced.patches.youtube.misc.minimizedplayback
22
33import app.revanced.patcher.data.BytecodeContext
4- import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5- import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
64import app.revanced.patcher.patch.BytecodePatch
7- import app.revanced.patcher.patch.annotation.CompatiblePackage
8- import app.revanced.patcher.patch.annotation.Patch
9- import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
10- import app.revanced.patches.all.misc.resources.AddResourcesPatch
11- import app.revanced.patches.shared.misc.settings.preference.NonInteractivePreference
12- import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
13- import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.KidsMinimizedPlaybackPolicyControllerFingerprint
14- import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint
15- import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackSettingsFingerprint
16- import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
17- import app.revanced.patches.youtube.misc.settings.SettingsPatch
18- import app.revanced.patches.youtube.video.information.VideoInformationPatch
19- import app.revanced.util.exception
20- import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
21- import com.android.tools.smali.dexlib2.iface.reference.MethodReference
22-
23- @Patch(
24- name = " Minimized playback" ,
25- description = " Unlocks options for picture-in-picture and background playback." ,
26- dependencies = [
27- MinimizedPlaybackResourcePatch ::class ,
28- IntegrationsPatch ::class ,
29- PlayerTypeHookPatch ::class ,
30- VideoInformationPatch ::class ,
31- SettingsPatch ::class ,
32- AddResourcesPatch ::class
33- ],
34- compatiblePackages = [
35- CompatiblePackage (
36- " com.google.android.youtube" ,
37- [
38- " 18.48.39" ,
39- " 18.49.37" ,
40- " 19.01.34" ,
41- " 19.02.39" ,
42- " 19.03.36" ,
43- " 19.04.38" ,
44- " 19.05.36" ,
45- " 19.06.39" ,
46- " 19.07.40" ,
47- " 19.08.36" ,
48- " 19.09.38" ,
49- " 19.10.39" ,
50- " 19.11.43" ,
51- " 19.12.41" ,
52- " 19.13.37" ,
53- " 19.14.43" ,
54- " 19.15.36" ,
55- " 19.16.39" ,
56- ]
57- )
58- ]
59- )
60- @Suppress(" unused" )
61- object MinimizedPlaybackPatch : BytecodePatch(
62- setOf(
63- MinimizedPlaybackManagerFingerprint ,
64- MinimizedPlaybackSettingsFingerprint ,
65- KidsMinimizedPlaybackPolicyControllerFingerprint
66- )
67- ) {
68- private const val INTEGRATIONS_CLASS_DESCRIPTOR =
69- " Lapp/revanced/integrations/youtube/patches/MinimizedPlaybackPatch;"
5+ import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackPatch
706
7+ @Deprecated(" This patch class has been renamed to BackgroundPlaybackPatch." )
8+ object MinimizedPlaybackPatch : BytecodePatch(dependencies = setOf(BackgroundPlaybackPatch ::class)) {
719 override fun execute (context : BytecodeContext ) {
72- AddResourcesPatch (this ::class )
73-
74- SettingsPatch .PreferenceScreen .MISC .addPreferences(
75- NonInteractivePreference (" revanced_minimized_playback" )
76- )
77-
78- MinimizedPlaybackManagerFingerprint .result?.apply {
79- mutableMethod.addInstructions(
80- 0 ,
81- """
82- invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR ->playbackIsNotShort()Z
83- move-result v0
84- return v0
85- """
86- )
87- } ? : throw MinimizedPlaybackManagerFingerprint .exception
88-
89- // Enable minimized playback option in YouTube settings
90- MinimizedPlaybackSettingsFingerprint .result?.apply {
91- val booleanCalls = method.implementation!! .instructions.withIndex()
92- .filter { ((it.value as ? ReferenceInstruction )?.reference as ? MethodReference )?.returnType == " Z" }
93-
94- val settingsBooleanIndex = booleanCalls.elementAt(1 ).index
95- val settingsBooleanMethod =
96- context.toMethodWalker(method).nextMethod(settingsBooleanIndex, true ).getMethod() as MutableMethod
97-
98- settingsBooleanMethod.addInstructions(
99- 0 ,
100- """
101- invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR ->overrideMinimizedPlaybackAvailable()Z
102- move-result v0
103- return v0
104- """
105- )
106- } ? : throw MinimizedPlaybackSettingsFingerprint .exception
107-
108- // Force allowing background play for videos labeled for kids.
109- // Some regions and YouTube accounts do not require this patch.
110- KidsMinimizedPlaybackPolicyControllerFingerprint .result?.apply {
111- mutableMethod.addInstruction(
112- 0 ,
113- " return-void"
114- )
115- } ? : throw KidsMinimizedPlaybackPolicyControllerFingerprint .exception
11610 }
117- }
11+ }
0 commit comments