From 37d415b53af4771d9c97a8b1c153be32bf3ac2e0 Mon Sep 17 00:00:00 2001
From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Date: Sat, 8 Jun 2024 11:35:20 +0300
Subject: [PATCH] fix(YouTube): Rename `Minimized playback` to `Remove
background playback restrictions` (#3314)
---
api/revanced-patches.api | 6 +
.../BackgroundPlaybackPatch.kt | 112 +++++++++++++++++
.../BackgroundPlaybackResourcePatch.kt} | 4 +-
.../BackgroundPlaybackManagerFingerprint.kt} | 4 +-
.../BackgroundPlaybackSettingsFingerprint.kt} | 8 +-
...undPlaybackPolicyControllerFingerprint.kt} | 13 +-
.../MinimizedPlaybackPatch.kt | 114 +-----------------
.../resources/addresources/values/strings.xml | 6 +-
8 files changed, 137 insertions(+), 130 deletions(-)
create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt
rename src/main/kotlin/app/revanced/patches/youtube/misc/{minimizedplayback/MinimizedPlaybackResourcePatch.kt => backgroundplayback/BackgroundPlaybackResourcePatch.kt} (80%)
rename src/main/kotlin/app/revanced/patches/youtube/misc/{minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt => backgroundplayback/fingerprints/BackgroundPlaybackManagerFingerprint.kt} (85%)
rename src/main/kotlin/app/revanced/patches/youtube/misc/{minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt => backgroundplayback/fingerprints/BackgroundPlaybackSettingsFingerprint.kt} (61%)
rename src/main/kotlin/app/revanced/patches/youtube/misc/{minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt => backgroundplayback/fingerprints/KidsBackgroundPlaybackPolicyControllerFingerprint.kt} (57%)
diff --git a/api/revanced-patches.api b/api/revanced-patches.api
index 9f2538706..4b2760448 100644
--- a/api/revanced-patches.api
+++ b/api/revanced-patches.api
@@ -1638,6 +1638,12 @@ public final class app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}
+public final class app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch : app/revanced/patcher/patch/BytecodePatch {
+ public static final field INSTANCE Lapp/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch;
+ public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
+ public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
+}
+
public final class app/revanced/patches/youtube/misc/debugging/DebuggingPatch : app/revanced/patcher/patch/ResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/debugging/DebuggingPatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt
new file mode 100644
index 000000000..9cad7fd4d
--- /dev/null
+++ b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt
@@ -0,0 +1,112 @@
+package app.revanced.patches.youtube.misc.backgroundplayback
+
+import app.revanced.patcher.data.BytecodeContext
+import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
+import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
+import app.revanced.patcher.patch.BytecodePatch
+import app.revanced.patcher.patch.annotation.CompatiblePackage
+import app.revanced.patcher.patch.annotation.Patch
+import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
+import app.revanced.patches.all.misc.resources.AddResourcesPatch
+import app.revanced.patches.shared.misc.settings.preference.NonInteractivePreference
+import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
+import app.revanced.patches.youtube.misc.backgroundplayback.fingerprints.KidsBackgroundPlaybackPolicyControllerFingerprint
+import app.revanced.patches.youtube.misc.backgroundplayback.fingerprints.BackgroundPlaybackManagerFingerprint
+import app.revanced.patches.youtube.misc.backgroundplayback.fingerprints.BackgroundPlaybackSettingsFingerprint
+import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
+import app.revanced.patches.youtube.misc.settings.SettingsPatch
+import app.revanced.patches.youtube.video.information.VideoInformationPatch
+import app.revanced.util.resultOrThrow
+import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
+import com.android.tools.smali.dexlib2.iface.reference.MethodReference
+
+@Patch(
+ name = "Remove background playback restrictions",
+ description = "Removes restrictions on background playback, including playing kids videos in the background.",
+ dependencies = [
+ BackgroundPlaybackResourcePatch::class,
+ IntegrationsPatch::class,
+ PlayerTypeHookPatch::class,
+ VideoInformationPatch::class,
+ SettingsPatch::class,
+ AddResourcesPatch::class
+ ],
+ compatiblePackages = [
+ CompatiblePackage(
+ "com.google.android.youtube",
+ [
+ "18.48.39",
+ "18.49.37",
+ "19.01.34",
+ "19.02.39",
+ "19.03.36",
+ "19.04.38",
+ "19.05.36",
+ "19.06.39",
+ "19.07.40",
+ "19.08.36",
+ "19.09.38",
+ "19.10.39",
+ "19.11.43",
+ "19.12.41",
+ "19.13.37",
+ "19.14.43",
+ "19.15.36",
+ "19.16.39",
+ ]
+ )
+ ]
+)
+@Suppress("unused")
+object BackgroundPlaybackPatch : BytecodePatch(
+ setOf(
+ BackgroundPlaybackManagerFingerprint,
+ BackgroundPlaybackSettingsFingerprint,
+ KidsBackgroundPlaybackPolicyControllerFingerprint
+ )
+) {
+ private const val INTEGRATIONS_CLASS_DESCRIPTOR =
+ "Lapp/revanced/integrations/youtube/patches/BackgroundPlaybackPatch;"
+
+ override fun execute(context: BytecodeContext) {
+ AddResourcesPatch(this::class)
+
+ SettingsPatch.PreferenceScreen.MISC.addPreferences(
+ NonInteractivePreference("revanced_background_playback")
+ )
+
+ BackgroundPlaybackManagerFingerprint.resultOrThrow().mutableMethod.addInstructions(
+ 0,
+ """
+ invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackIsNotShort()Z
+ move-result v0
+ return v0
+ """
+ )
+
+ // Enable background playback option in YouTube settings
+ BackgroundPlaybackSettingsFingerprint.resultOrThrow().mutableMethod.apply {
+ val booleanCalls = implementation!!.instructions.withIndex()
+ .filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
+
+ val settingsBooleanIndex = booleanCalls.elementAt(1).index
+ val settingsBooleanMethod =
+ context.toMethodWalker(this).nextMethod(settingsBooleanIndex, true).getMethod() as MutableMethod
+
+ settingsBooleanMethod.addInstructions(
+ 0,
+ """
+ invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideBackgroundPlaybackAvailable()Z
+ move-result v0
+ return v0
+ """
+ )
+ }
+
+ // Force allowing background play for videos labeled for kids.
+ KidsBackgroundPlaybackPolicyControllerFingerprint.resultOrThrow().mutableMethod.addInstruction(
+ 0,
+ "return-void"
+ )
+ }
+}
diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackResourcePatch.kt
similarity index 80%
rename from src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackResourcePatch.kt
rename to src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackResourcePatch.kt
index d310d3abf..3be877a9a 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackResourcePatch.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackResourcePatch.kt
@@ -1,4 +1,4 @@
-package app.revanced.patches.youtube.misc.minimizedplayback
+package app.revanced.patches.youtube.misc.backgroundplayback
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
@@ -8,7 +8,7 @@ import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch
@Patch(
dependencies = [ResourceMappingPatch::class],
)
-internal object MinimizedPlaybackResourcePatch : ResourcePatch() {
+internal object BackgroundPlaybackResourcePatch : ResourcePatch() {
internal var prefBackgroundAndOfflineCategoryId: Long = -1
override fun execute(context: ResourceContext) {
diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/BackgroundPlaybackManagerFingerprint.kt
similarity index 85%
rename from src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt
rename to src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/BackgroundPlaybackManagerFingerprint.kt
index 2be2ec0d7..4695df5da 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/BackgroundPlaybackManagerFingerprint.kt
@@ -1,11 +1,11 @@
-package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
+package app.revanced.patches.youtube.misc.backgroundplayback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
-internal object MinimizedPlaybackManagerFingerprint : MethodFingerprint(
+internal object BackgroundPlaybackManagerFingerprint : MethodFingerprint(
"Z",
AccessFlags.PUBLIC or AccessFlags.STATIC,
listOf("L"),
diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/BackgroundPlaybackSettingsFingerprint.kt
similarity index 61%
rename from src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt
rename to src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/BackgroundPlaybackSettingsFingerprint.kt
index 8f31e0173..c57d9173e 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/BackgroundPlaybackSettingsFingerprint.kt
@@ -1,12 +1,12 @@
-package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
+package app.revanced.patches.youtube.misc.backgroundplayback.fingerprints
import app.revanced.patcher.extensions.or
-import app.revanced.patches.youtube.misc.minimizedplayback.MinimizedPlaybackResourcePatch
+import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackResourcePatch
import app.revanced.util.patch.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
-internal object MinimizedPlaybackSettingsFingerprint : LiteralValueFingerprint(
+internal object BackgroundPlaybackSettingsFingerprint : LiteralValueFingerprint(
returnType = "Ljava/lang/String;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
@@ -19,5 +19,5 @@ internal object MinimizedPlaybackSettingsFingerprint : LiteralValueFingerprint(
Opcode.IF_NEZ,
Opcode.GOTO
),
- literalSupplier = { MinimizedPlaybackResourcePatch.prefBackgroundAndOfflineCategoryId }
+ literalSupplier = { BackgroundPlaybackResourcePatch.prefBackgroundAndOfflineCategoryId }
)
diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/KidsBackgroundPlaybackPolicyControllerFingerprint.kt
similarity index 57%
rename from src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt
rename to src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/KidsBackgroundPlaybackPolicyControllerFingerprint.kt
index af992d609..7f33326c5 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/fingerprints/KidsBackgroundPlaybackPolicyControllerFingerprint.kt
@@ -1,12 +1,11 @@
-package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints
+package app.revanced.patches.youtube.misc.backgroundplayback.fingerprints
import app.revanced.patcher.extensions.or
-import app.revanced.patcher.fingerprint.MethodFingerprint
+import app.revanced.util.patch.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
-import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
-internal object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerprint(
+internal object KidsBackgroundPlaybackPolicyControllerFingerprint : LiteralValueFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("I", "L", "L"),
@@ -26,9 +25,5 @@ internal object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerp
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
),
- customFingerprint = { methodDef, _ ->
- methodDef.implementation!!.instructions.any {
- ((it as? NarrowLiteralInstruction)?.narrowLiteral == 5)
- }
- }
+ literalSupplier = { 5 },
)
diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt
index c3569590b..b354a6bc7 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt
@@ -1,117 +1,11 @@
package app.revanced.patches.youtube.misc.minimizedplayback
import app.revanced.patcher.data.BytecodeContext
-import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
-import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
-import app.revanced.patcher.patch.annotation.CompatiblePackage
-import app.revanced.patcher.patch.annotation.Patch
-import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
-import app.revanced.patches.all.misc.resources.AddResourcesPatch
-import app.revanced.patches.shared.misc.settings.preference.NonInteractivePreference
-import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
-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.PlayerTypeHookPatch
-import app.revanced.patches.youtube.misc.settings.SettingsPatch
-import app.revanced.patches.youtube.video.information.VideoInformationPatch
-import app.revanced.util.exception
-import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
-import com.android.tools.smali.dexlib2.iface.reference.MethodReference
-
-@Patch(
- name = "Minimized playback",
- description = "Unlocks options for picture-in-picture and background playback.",
- dependencies = [
- MinimizedPlaybackResourcePatch::class,
- IntegrationsPatch::class,
- PlayerTypeHookPatch::class,
- VideoInformationPatch::class,
- SettingsPatch::class,
- AddResourcesPatch::class
- ],
- compatiblePackages = [
- CompatiblePackage(
- "com.google.android.youtube",
- [
- "18.48.39",
- "18.49.37",
- "19.01.34",
- "19.02.39",
- "19.03.36",
- "19.04.38",
- "19.05.36",
- "19.06.39",
- "19.07.40",
- "19.08.36",
- "19.09.38",
- "19.10.39",
- "19.11.43",
- "19.12.41",
- "19.13.37",
- "19.14.43",
- "19.15.36",
- "19.16.39",
- ]
- )
- ]
-)
-@Suppress("unused")
-object MinimizedPlaybackPatch : BytecodePatch(
- setOf(
- MinimizedPlaybackManagerFingerprint,
- MinimizedPlaybackSettingsFingerprint,
- KidsMinimizedPlaybackPolicyControllerFingerprint
- )
-) {
- private const val INTEGRATIONS_CLASS_DESCRIPTOR =
- "Lapp/revanced/integrations/youtube/patches/MinimizedPlaybackPatch;"
+import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackPatch
+@Deprecated("This patch class has been renamed to BackgroundPlaybackPatch.")
+object MinimizedPlaybackPatch : BytecodePatch(dependencies = setOf(BackgroundPlaybackPatch::class)) {
override fun execute(context: BytecodeContext) {
- AddResourcesPatch(this::class)
-
- SettingsPatch.PreferenceScreen.MISC.addPreferences(
- NonInteractivePreference("revanced_minimized_playback")
- )
-
- MinimizedPlaybackManagerFingerprint.result?.apply {
- mutableMethod.addInstructions(
- 0,
- """
- invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackIsNotShort()Z
- move-result v0
- return v0
- """
- )
- } ?: throw MinimizedPlaybackManagerFingerprint.exception
-
- // Enable minimized playback option in YouTube settings
- MinimizedPlaybackSettingsFingerprint.result?.apply {
- val booleanCalls = method.implementation!!.instructions.withIndex()
- .filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
-
- val settingsBooleanIndex = booleanCalls.elementAt(1).index
- val settingsBooleanMethod =
- context.toMethodWalker(method).nextMethod(settingsBooleanIndex, true).getMethod() as MutableMethod
-
- settingsBooleanMethod.addInstructions(
- 0,
- """
- invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideMinimizedPlaybackAvailable()Z
- move-result v0
- return v0
- """
- )
- } ?: throw MinimizedPlaybackSettingsFingerprint.exception
-
- // 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"
- )
- } ?: throw KidsMinimizedPlaybackPolicyControllerFingerprint.exception
}
-}
+}
\ No newline at end of file
diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml
index 774198dbd..1a85eafc6 100644
--- a/src/main/resources/addresources/values/strings.xml
+++ b/src/main/resources/addresources/values/strings.xml
@@ -1051,9 +1051,9 @@
Opening links externally
Opening links in app
-
- Minimized playback
- This setting can be found in Settings -> Background
+
+ Background playback
+ This setting can be found in Settings -> Background
Remove tracking query parameter