2023-09-20 05:33:02 +02:00
|
|
|
package app.revanced.patches.youtube.misc.minimizedplayback
|
2022-05-18 23:58:54 +02:00
|
|
|
|
2023-12-02 22:35:13 +01:00
|
|
|
import app.revanced.util.exception
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
2023-06-07 03:46:13 +02:00
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
|
|
|
import app.revanced.patcher.patch.annotation.Patch
|
2022-07-05 19:45:46 +02:00
|
|
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
2023-04-27 15:39:05 +02:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.NonInteractivePreference
|
2023-02-11 01:25:50 +01:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
|
2023-04-29 10:14:10 +02:00
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.KidsMinimizedPlaybackPolicyControllerFingerprint
|
2023-10-20 12:38:06 +02:00
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint
|
2022-08-22 01:59:43 +02:00
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackSettingsFingerprint
|
2023-06-28 15:43:45 +02:00
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackSettingsParentFingerprint
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
|
|
|
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
2023-12-05 00:47:46 +01:00
|
|
|
import app.revanced.patches.youtube.video.information.VideoInformationPatch
|
2023-08-27 21:40:49 +02:00
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
|
|
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
2022-05-18 23:58:54 +02:00
|
|
|
|
2023-09-20 05:33:02 +02:00
|
|
|
@Patch(
|
|
|
|
name = "Minimized playback",
|
2024-01-01 16:30:04 +01:00
|
|
|
description = "Unlocks options for picture-in-picture and background playback.",
|
2023-12-05 00:47:46 +01:00
|
|
|
dependencies = [
|
|
|
|
IntegrationsPatch::class,
|
|
|
|
PlayerTypeHookPatch::class,
|
|
|
|
VideoInformationPatch::class,
|
|
|
|
SettingsPatch::class
|
|
|
|
],
|
2023-09-20 05:33:02 +02:00
|
|
|
compatiblePackages = [
|
|
|
|
CompatiblePackage(
|
|
|
|
"com.google.android.youtube",
|
|
|
|
[
|
2023-09-28 01:28:25 +02:00
|
|
|
"18.32.39",
|
2023-10-08 03:37:42 +02:00
|
|
|
"18.37.36",
|
2023-11-12 16:43:11 +01:00
|
|
|
"18.38.44",
|
2023-11-12 17:01:49 +01:00
|
|
|
"18.43.45",
|
|
|
|
"18.44.41",
|
2023-12-02 00:07:29 +01:00
|
|
|
"18.45.41",
|
|
|
|
"18.45.43"
|
2023-09-20 05:33:02 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Suppress("unused")
|
|
|
|
object MinimizedPlaybackPatch : BytecodePatch(
|
|
|
|
setOf(
|
2023-10-20 12:38:06 +02:00
|
|
|
MinimizedPlaybackManagerFingerprint,
|
2023-06-28 15:43:45 +02:00
|
|
|
MinimizedPlaybackSettingsParentFingerprint,
|
2023-04-29 10:14:10 +02:00
|
|
|
KidsMinimizedPlaybackPolicyControllerFingerprint
|
2022-05-18 23:58:54 +02:00
|
|
|
)
|
|
|
|
) {
|
2024-01-01 16:33:07 +01:00
|
|
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/youtube/patches/MinimizedPlaybackPatch;"
|
2023-09-20 05:33:02 +02:00
|
|
|
|
2023-08-27 21:40:49 +02:00
|
|
|
override fun execute(context: BytecodeContext) {
|
2023-04-27 15:39:05 +02:00
|
|
|
// TODO: remove this empty preference sometime after mid 2023
|
2022-08-22 01:59:43 +02:00
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
2023-04-27 15:39:05 +02:00
|
|
|
NonInteractivePreference(
|
|
|
|
StringResource("revanced_minimized_playback_enabled_title", "Minimized playback"),
|
2023-09-20 05:33:02 +02:00
|
|
|
StringResource(
|
|
|
|
"revanced_minimized_playback_summary_on",
|
|
|
|
"This setting can be found in Settings -> Background"
|
|
|
|
)
|
2022-08-22 01:59:43 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-10-20 12:38:06 +02:00
|
|
|
MinimizedPlaybackManagerFingerprint.result?.apply {
|
2023-02-11 01:25:50 +01:00
|
|
|
mutableMethod.addInstructions(
|
2023-06-07 03:46:13 +02:00
|
|
|
0,
|
|
|
|
"""
|
2023-12-05 00:47:46 +01:00
|
|
|
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackIsNotShort()Z
|
2023-06-07 03:46:13 +02:00
|
|
|
move-result v0
|
|
|
|
return v0
|
2022-06-23 02:22:42 +02:00
|
|
|
"""
|
2023-02-11 01:25:50 +01:00
|
|
|
)
|
2023-10-20 12:38:06 +02:00
|
|
|
} ?: throw MinimizedPlaybackManagerFingerprint.exception
|
2022-07-05 19:45:46 +02:00
|
|
|
|
2023-04-27 15:39:05 +02:00
|
|
|
// Enable minimized playback option in YouTube settings
|
2023-08-27 21:40:49 +02:00
|
|
|
MinimizedPlaybackSettingsParentFingerprint.result ?: throw MinimizedPlaybackSettingsParentFingerprint.exception
|
2023-09-20 05:33:02 +02:00
|
|
|
MinimizedPlaybackSettingsFingerprint.resolve(
|
|
|
|
context,
|
|
|
|
MinimizedPlaybackSettingsParentFingerprint.result!!.classDef
|
|
|
|
)
|
2023-04-27 15:39:05 +02:00
|
|
|
MinimizedPlaybackSettingsFingerprint.result?.apply {
|
|
|
|
val booleanCalls = method.implementation!!.instructions.withIndex()
|
|
|
|
.filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
|
2022-07-05 19:45:46 +02:00
|
|
|
|
2023-04-27 15:39:05 +02:00
|
|
|
val settingsBooleanIndex = booleanCalls.elementAt(1).index
|
|
|
|
val settingsBooleanMethod =
|
|
|
|
context.toMethodWalker(method).nextMethod(settingsBooleanIndex, true).getMethod() as MutableMethod
|
2022-07-05 19:45:46 +02:00
|
|
|
|
2023-04-27 15:39:05 +02:00
|
|
|
settingsBooleanMethod.addInstructions(
|
2023-06-07 03:46:13 +02:00
|
|
|
0,
|
|
|
|
"""
|
|
|
|
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideMinimizedPlaybackAvailable()Z
|
|
|
|
move-result v0
|
|
|
|
return v0
|
2023-02-11 01:25:50 +01:00
|
|
|
"""
|
|
|
|
)
|
2023-08-27 21:40:49 +02:00
|
|
|
} ?: throw MinimizedPlaybackSettingsFingerprint.exception
|
2022-07-18 16:29:51 +02:00
|
|
|
|
2023-04-29 10:14:10 +02:00
|
|
|
// 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"
|
|
|
|
)
|
2023-08-27 21:40:49 +02:00
|
|
|
} ?: throw KidsMinimizedPlaybackPolicyControllerFingerprint.exception
|
2022-05-18 23:58:54 +02:00
|
|
|
}
|
2022-07-05 19:45:46 +02:00
|
|
|
}
|