diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt deleted file mode 100644 index 3ceb6457a..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt +++ /dev/null @@ -1,23 +0,0 @@ -package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerprint( - "V", - AccessFlags.PUBLIC or AccessFlags.FINAL, - listOf("I", "L", "L"), - listOf( - Opcode.IF_EQZ, - Opcode.SGET_OBJECT, - Opcode.IF_NE, - Opcode.CONST_4, - Opcode.IPUT_BOOLEAN, - Opcode.IF_EQZ, - Opcode.IGET, - Opcode.INVOKE_STATIC - ), - customFingerprint = { it.definingClass.endsWith("MinimizedPlaybackPolicyController;") } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/PipControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/PipControllerFingerprint.kt deleted file mode 100644 index 3de1e8a2d..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/PipControllerFingerprint.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object PipControllerFingerprint : MethodFingerprint( - returnType = "L", - access = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L"), - opcodes = listOf( - Opcode.IGET_BOOLEAN - ), - customFingerprint = { it.definingClass.endsWith("DefaultPipController;") } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt index 321e7d2b0..d87e3dd4d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/patch/MinimizedPlaybackPatch.kt @@ -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.") @@ -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 + settingsBooleanMethod.addInstructions( + 0, """ + invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideMinimizedPlaybackAvailable()Z move-result v0 return v0 """ - ) - - KidsMinimizedPlaybackPolicyControllerFingerprint.result?.apply { - mutableMethod.addInstructions( - 0, """ - invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->isMinimizedPlaybackEnabled()Z - move-result v0 - if-eqz v0, :enable - return-void - :enable - nop - """ ) - } ?: return KidsMinimizedPlaybackPolicyControllerFingerprint.toErrorResult() + } ?: return MinimizedPlaybackSettingsFingerprint.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 PipControllerFingerprint.toErrorResult() return PatchResultSuccess() }