Skip to content

Commit

Permalink
fix(youtube/minimized-playback): disable minimized playback for shorts (
Browse files Browse the repository at this point in the history
#1990)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX committed Apr 27, 2023
1 parent db67c54 commit b91d18d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 90 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.settings.preference.impl.NonInteractivePreference
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
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.minimizedplayback.fingerprints.PipControllerFingerprint
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.reference.MethodReference


@Patch
@Name("minimized-playback")
@Description("Enables minimized and background playback.")
Expand All @@ -37,75 +32,47 @@ import org.jf.dexlib2.iface.reference.MethodReference
@Version("0.0.1")
class MinimizedPlaybackPatch : BytecodePatch(
listOf(
KidsMinimizedPlaybackPolicyControllerFingerprint,
MinimizedPlaybackManagerFingerprint,
MinimizedPlaybackSettingsFingerprint,
PipControllerFingerprint
MinimizedPlaybackSettingsFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
// TODO: remove this empty preference sometime after mid 2023
SettingsPatch.PreferenceScreen.MISC.addPreferences(
SwitchPreference(
"revanced_enable_minimized_playback",
StringResource("revanced_minimized_playback_enabled_title", "Enable minimized playback"),
true,
StringResource("revanced_minimized_playback_summary_on", "Minimized playback is enabled"),
StringResource("revanced_minimized_playback_summary_off", "Minimized playback is disabled")
NonInteractivePreference(
StringResource("revanced_minimized_playback_enabled_title", "Minimized playback"),
StringResource("revanced_minimized_playback_summary_on", "This setting can be found in Settings -> General")
)
)

MinimizedPlaybackManagerFingerprint.result?.apply {
mutableMethod.addInstructions(
0, """
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->isMinimizedPlaybackEnabled()Z
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackIsNotShort()Z
move-result v0
return v0
"""
)
} ?: return MinimizedPlaybackManagerFingerprint.toErrorResult()

val method = MinimizedPlaybackSettingsFingerprint.result!!.mutableMethod
val booleanCalls = method.implementation!!.instructions.withIndex()
.filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
// 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
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->isMinimizedPlaybackEnabled()Z
move-result v0
return v0
"""
)

KidsMinimizedPlaybackPolicyControllerFingerprint.result?.apply {
mutableMethod.addInstructions(
settingsBooleanMethod.addInstructions(
0, """
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->isMinimizedPlaybackEnabled()Z
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideMinimizedPlaybackAvailable()Z
move-result v0
if-eqz v0, :enable
return-void
:enable
nop
"""
)
} ?: return KidsMinimizedPlaybackPolicyControllerFingerprint.toErrorResult()

PipControllerFingerprint.result?.apply {
val insertIndex = scanResult.patternScanResult!!.endIndex + 1
val pipEnabledRegister = (mutableMethod.instruction(insertIndex - 1) as TwoRegisterInstruction).registerA

mutableMethod.addInstructions(
insertIndex,
"""
invoke-static {v$pipEnabledRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->isNotPlayingShorts(Z)Z
move-result v$pipEnabledRegister
return v0
"""
)
} ?: return MinimizedPlaybackSettingsFingerprint.toErrorResult()

} ?: return PipControllerFingerprint.toErrorResult()
return PatchResultSuccess()
}

Expand Down

0 comments on commit b91d18d

Please sign in to comment.