Skip to content

Commit 4919cba

Browse files
author
LisoUseInAIKyrios
authored
fix(YouTube): Rename Minimized playback to Remove background playback restrictions (#3314)
1 parent 1d46b95 commit 4919cba

File tree

8 files changed

+137
-130
lines changed

8 files changed

+137
-130
lines changed

api/revanced-patches.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,12 @@ public final class app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch
16381638
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
16391639
}
16401640

1641+
public final class app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch : app/revanced/patcher/patch/BytecodePatch {
1642+
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch;
1643+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
1644+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
1645+
}
1646+
16411647
public final class app/revanced/patches/youtube/misc/debugging/DebuggingPatch : app/revanced/patcher/patch/ResourcePatch {
16421648
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/debugging/DebuggingPatch;
16431649
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package app.revanced.patches.youtube.misc.backgroundplayback
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
6+
import 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.backgroundplayback.fingerprints.KidsBackgroundPlaybackPolicyControllerFingerprint
14+
import app.revanced.patches.youtube.misc.backgroundplayback.fingerprints.BackgroundPlaybackManagerFingerprint
15+
import app.revanced.patches.youtube.misc.backgroundplayback.fingerprints.BackgroundPlaybackSettingsFingerprint
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.resultOrThrow
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 = "Remove background playback restrictions",
25+
description = "Removes restrictions on background playback, including playing kids videos in the background.",
26+
dependencies = [
27+
BackgroundPlaybackResourcePatch::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 BackgroundPlaybackPatch : BytecodePatch(
62+
setOf(
63+
BackgroundPlaybackManagerFingerprint,
64+
BackgroundPlaybackSettingsFingerprint,
65+
KidsBackgroundPlaybackPolicyControllerFingerprint
66+
)
67+
) {
68+
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
69+
"Lapp/revanced/integrations/youtube/patches/BackgroundPlaybackPatch;"
70+
71+
override fun execute(context: BytecodeContext) {
72+
AddResourcesPatch(this::class)
73+
74+
SettingsPatch.PreferenceScreen.MISC.addPreferences(
75+
NonInteractivePreference("revanced_background_playback")
76+
)
77+
78+
BackgroundPlaybackManagerFingerprint.resultOrThrow().mutableMethod.addInstructions(
79+
0,
80+
"""
81+
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackIsNotShort()Z
82+
move-result v0
83+
return v0
84+
"""
85+
)
86+
87+
// Enable background playback option in YouTube settings
88+
BackgroundPlaybackSettingsFingerprint.resultOrThrow().mutableMethod.apply {
89+
val booleanCalls = implementation!!.instructions.withIndex()
90+
.filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
91+
92+
val settingsBooleanIndex = booleanCalls.elementAt(1).index
93+
val settingsBooleanMethod =
94+
context.toMethodWalker(this).nextMethod(settingsBooleanIndex, true).getMethod() as MutableMethod
95+
96+
settingsBooleanMethod.addInstructions(
97+
0,
98+
"""
99+
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideBackgroundPlaybackAvailable()Z
100+
move-result v0
101+
return v0
102+
"""
103+
)
104+
}
105+
106+
// Force allowing background play for videos labeled for kids.
107+
KidsBackgroundPlaybackPolicyControllerFingerprint.resultOrThrow().mutableMethod.addInstruction(
108+
0,
109+
"return-void"
110+
)
111+
}
112+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.revanced.patches.youtube.misc.minimizedplayback
1+
package app.revanced.patches.youtube.misc.backgroundplayback
22

33
import app.revanced.patcher.data.ResourceContext
44
import app.revanced.patcher.patch.ResourcePatch
@@ -8,7 +8,7 @@ import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch
88
@Patch(
99
dependencies = [ResourceMappingPatch::class],
1010
)
11-
internal object MinimizedPlaybackResourcePatch : ResourcePatch() {
11+
internal object BackgroundPlaybackResourcePatch : ResourcePatch() {
1212
internal var prefBackgroundAndOfflineCategoryId: Long = -1
1313

1414
override fun execute(context: ResourceContext) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
1+
package app.revanced.patches.youtube.misc.backgroundplayback.fingerprints
22

33
import app.revanced.patcher.extensions.or
44
import app.revanced.patcher.fingerprint.MethodFingerprint
55
import com.android.tools.smali.dexlib2.AccessFlags
66
import com.android.tools.smali.dexlib2.Opcode
77

8-
internal object MinimizedPlaybackManagerFingerprint : MethodFingerprint(
8+
internal object BackgroundPlaybackManagerFingerprint : MethodFingerprint(
99
"Z",
1010
AccessFlags.PUBLIC or AccessFlags.STATIC,
1111
listOf("L"),
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
1+
package app.revanced.patches.youtube.misc.backgroundplayback.fingerprints
22

33
import app.revanced.patcher.extensions.or
4-
import app.revanced.patches.youtube.misc.minimizedplayback.MinimizedPlaybackResourcePatch
4+
import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackResourcePatch
55
import app.revanced.util.patch.LiteralValueFingerprint
66
import com.android.tools.smali.dexlib2.AccessFlags
77
import com.android.tools.smali.dexlib2.Opcode
88

9-
internal object MinimizedPlaybackSettingsFingerprint : LiteralValueFingerprint(
9+
internal object BackgroundPlaybackSettingsFingerprint : LiteralValueFingerprint(
1010
returnType = "Ljava/lang/String;",
1111
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
1212
parameters = listOf(),
@@ -19,5 +19,5 @@ internal object MinimizedPlaybackSettingsFingerprint : LiteralValueFingerprint(
1919
Opcode.IF_NEZ,
2020
Opcode.GOTO
2121
),
22-
literalSupplier = { MinimizedPlaybackResourcePatch.prefBackgroundAndOfflineCategoryId }
22+
literalSupplier = { BackgroundPlaybackResourcePatch.prefBackgroundAndOfflineCategoryId }
2323
)
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
1+
package app.revanced.patches.youtube.misc.backgroundplayback.fingerprints
22

33
import app.revanced.patcher.extensions.or
4-
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import app.revanced.util.patch.LiteralValueFingerprint
55
import com.android.tools.smali.dexlib2.AccessFlags
66
import com.android.tools.smali.dexlib2.Opcode
7-
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
87

9-
internal object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerprint(
8+
internal object KidsBackgroundPlaybackPolicyControllerFingerprint : LiteralValueFingerprint(
109
returnType = "V",
1110
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
1211
parameters = listOf("I", "L", "L"),
@@ -26,9 +25,5 @@ internal object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerp
2625
Opcode.INVOKE_VIRTUAL,
2726
Opcode.RETURN_VOID
2827
),
29-
customFingerprint = { methodDef, _ ->
30-
methodDef.implementation!!.instructions.any {
31-
((it as? NarrowLiteralInstruction)?.narrowLiteral == 5)
32-
}
33-
}
28+
literalSupplier = { 5 },
3429
)
Lines changed: 4 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,11 @@
11
package app.revanced.patches.youtube.misc.minimizedplayback
22

33
import app.revanced.patcher.data.BytecodeContext
4-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5-
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
64
import 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+
}

src/main/resources/addresources/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,9 @@
10511051
<string name="revanced_external_browser_summary_on">Opening links externally</string>
10521052
<string name="revanced_external_browser_summary_off">Opening links in app</string>
10531053
</patch>
1054-
<patch id="misc.minimizedplayback.MinimizedPlaybackPatch">
1055-
<string name="revanced_minimized_playback_title">Minimized playback</string>
1056-
<string name="revanced_minimized_playback_summary">This setting can be found in Settings -&gt; Background</string>
1054+
<patch id="misc.backgroundplayback.BackgroundPlaybackPatch">
1055+
<string name="revanced_background_playback_title">Background playback</string>
1056+
<string name="revanced_background_playback_summary">This setting can be found in Settings -&gt; Background</string>
10571057
</patch>
10581058
<patch id="misc.privacy.RemoveTrackingQueryParameterPatch">
10591059
<string name="revanced_remove_tracking_query_parameter_title">Remove tracking query parameter</string>

0 commit comments

Comments
 (0)