From 09ee27646c2ae10ec2b9ab5971a2c6f35453b79a Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:25:11 +0900 Subject: [PATCH] fix(YouTube Music/MicroG support): can't share the stories to Facebook, Instagram and Snapchat --- .../fix/fileprovider/FileProviderPatch.kt | 50 +++++++++++++++++++ .../FileProviderResolverFingerprint.kt | 11 ++++ .../patches/music/utils/microg/MicroGPatch.kt | 4 +- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/fingerprints/FileProviderResolverFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt new file mode 100644 index 000000000..2c183c5c0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt @@ -0,0 +1,50 @@ +package app.revanced.patches.music.utils.fix.fileprovider + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.music.utils.fix.fileprovider.fingerprints.FileProviderResolverFingerprint +import app.revanced.patches.shared.patch.packagename.PackageNamePatch +import app.revanced.util.exception + +@Patch(dependencies = [PackageNamePatch::class]) +object FileProviderPatch : BytecodePatch( + setOf(FileProviderResolverFingerprint) +) { + override fun execute(context: BytecodeContext) { + + val youtubePackageName = PackageNamePatch.PackageNameYouTube + ?: throw PatchException("Invalid package name.") + + val musicPackageName = PackageNamePatch.PackageNameYouTubeMusic + ?: throw PatchException("Invalid package name.") + + /** + * For some reason, if the app gets "android.support.FILE_PROVIDER_PATHS", + * the package name of YouTube is used, not the package name of the YT Music. + * + * There is no issue in the stock YT Music, but this is an issue in the MicroG Build. + * https://github.com/inotia00/ReVanced_Extended/issues/1830 + * + * To solve this issue, replace the package name of YouTube with YT Music's package name. + */ + FileProviderResolverFingerprint.result?.let { + it.mutableMethod.apply { + addInstructionsWithLabels( + 0, """ + const-string v0, "$youtubePackageName.fileprovider" + invoke-static {p1, v0}, Ljava/util/Objects;->equals(Ljava/lang/Object;Ljava/lang/Object;)Z + move-result v0 + if-eqz v0, :ignore + const-string p1, "$musicPackageName.fileprovider" + """, ExternalLabel("ignore", getInstruction(0)) + ) + } + } ?: throw FileProviderResolverFingerprint.exception + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/fingerprints/FileProviderResolverFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/fingerprints/FileProviderResolverFingerprint.kt new file mode 100644 index 000000000..1f06a6a2f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/fingerprints/FileProviderResolverFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.music.utils.fix.fileprovider.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +object FileProviderResolverFingerprint : MethodFingerprint( + returnType = "L", + strings = listOf( + "android.support.FILE_PROVIDER_PATHS", + "Name must not be empty" + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/microg/MicroGPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/microg/MicroGPatch.kt index 9e3989080..aed9e93f0 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/microg/MicroGPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/microg/MicroGPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.music.utils.fix.clientspoof.ClientSpoofPatch +import app.revanced.patches.music.utils.fix.fileprovider.FileProviderPatch import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch.injectInit import app.revanced.patches.music.utils.microg.Constants.MUSIC_PACKAGE_NAME @@ -26,7 +27,8 @@ import app.revanced.patches.shared.patch.packagename.PackageNamePatch ClientSpoofPatch::class, MainActivityResolvePatch::class, MicroGResourcePatch::class, - PackageNamePatch::class + PackageNamePatch::class, + FileProviderPatch::class ], compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")] )