From d4fd18bc74c92e17cdfb21b627b2f6a8919ff2dc Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Tue, 19 Jul 2022 00:40:56 +0100 Subject: [PATCH] feat: `minimize-playback-music` patch (#200) * feat: `minimize-playback` - unblocks minimized playback on kids music * refactor: add missing `;` * fix: rename to `minimized-playback-music` Co-authored-by: oSumAtrIX --- .../MinimizedPlaybackCompatibility.kt | 13 +++++++ .../MinimizedPlaybackManagerFingerprint.kt | 36 ++++++++++++++++++ .../patch/MinimizedPlaybackPatch.kt | 38 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/annotations/MinimizedPlaybackCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/annotations/MinimizedPlaybackCompatibility.kt b/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/annotations/MinimizedPlaybackCompatibility.kt new file mode 100644 index 00000000..e3092d41 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/annotations/MinimizedPlaybackCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.music.layout.minimizedplayback.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.apps.youtube.music", arrayOf("5.14.53") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class MinimizedPlaybackCompatibility diff --git a/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt new file mode 100644 index 00000000..b9845bef --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt @@ -0,0 +1,36 @@ +package app.revanced.patches.music.layout.minimizedplayback.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patches.music.layout.minimizedplayback.annotations.MinimizedPlaybackCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("minimized-playback-manager-fingerprint") +@MatchingMethod( + "Llxw;", "c" +) +@MinimizedPlaybackCompatibility +@Version("0.0.1") +object MinimizedPlaybackManagerFingerprint : MethodFingerprint( + "V", + AccessFlags.PUBLIC or AccessFlags.FINAL, + listOf("I", "L", "Z"), + listOf( + Opcode.IGET, + Opcode.IF_NE, + Opcode.IGET_OBJECT, + Opcode.IF_NE, + Opcode.IGET_BOOLEAN, + Opcode.IF_EQ, + Opcode.GOTO, + Opcode.RETURN_VOID, + Opcode.SGET_OBJECT, + Opcode.CONST_4, + Opcode.IF_NE, + Opcode.IPUT_BOOLEAN, + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt new file mode 100644 index 00000000..dad62812 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.music.layout.minimizedplayback.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.BytecodeData +import app.revanced.patcher.data.impl.toMethodWalker +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.music.layout.minimizedplayback.annotations.MinimizedPlaybackCompatibility +import app.revanced.patches.music.layout.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.reference.MethodReference + +@Patch +@Name("minimized-playback-music") +@Description("Enables minimized playback on Kids music.") +@MinimizedPlaybackCompatibility +@Version("0.0.1") +class MinimizedPlaybackPatch : BytecodePatch( + listOf( + MinimizedPlaybackManagerFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + MinimizedPlaybackManagerFingerprint.result!!.mutableMethod.addInstructions( + 0, """ + return-void + """ + ) + + return PatchResultSuccess() + } +}