From 328234f39ada81542e596f04e8ce410c787c15c8 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 28 Sep 2025 14:31:40 +0400 Subject: [PATCH] fix(YouTube Music - GmsCore support): Handle sharing links to certain apps such as Instagram (#6026) --- .../misc/fileprovider/FileProviderPatch.kt | 44 +++++++++++++++++++ .../music/misc/fileprovider/Fingerprints.kt | 11 +++++ .../music/misc/gms/GmsCoreSupportPatch.kt | 7 ++- .../music/misc/settings/SettingsPatch.kt | 3 +- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/FileProviderPatch.kt create mode 100644 patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/Fingerprints.kt diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/FileProviderPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/FileProviderPatch.kt new file mode 100644 index 000000000..32c162a46 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/FileProviderPatch.kt @@ -0,0 +1,44 @@ +package app.revanced.patches.music.misc.fileprovider + +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName +import app.revanced.patches.music.utils.fix.fileprovider.fileProviderResolverFingerprint + +internal fun fileProviderPatch( + youtubePackageName: String, + musicPackageName: String +) = bytecodePatch( + description = "Fixes broken YouTube Music file provider that prevents sharing with specific apps such as Instagram." +) { + finalize { + // Must do modification last, so change package name value is correctly set. + val musicChangedPackageName = setOrGetFallbackPackageName(musicPackageName) + + // 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 GmsCore Build. + // https://github.com/ReVanced/revanced-patches/issues/55 + // + // To solve this issue, replace the package name of YouTube with YT Music's package name. + fileProviderResolverFingerprint.method.addInstructionsWithLabels( + 0, + """ + const-string v0, "com.google.android.youtube.fileprovider" + invoke-static { p1, v0 }, Ljava/util/Objects;->equals(Ljava/lang/Object;Ljava/lang/Object;)Z + move-result v0 + if-nez v0, :fix + const-string v0, "$youtubePackageName.fileprovider" + invoke-static { p1, v0 }, Ljava/util/Objects;->equals(Ljava/lang/Object;Ljava/lang/Object;)Z + move-result v0 + if-nez v0, :fix + goto :ignore + :fix + const-string p1, "$musicChangedPackageName.fileprovider" + :ignore + nop + """ + ) + } +} \ No newline at end of file diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/Fingerprints.kt new file mode 100644 index 000000000..16a2d6a58 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/fileprovider/Fingerprints.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.music.utils.fix.fileprovider + +import app.revanced.patcher.fingerprint + +internal val fileProviderResolverFingerprint = fingerprint { + returns("L") + strings( + "android.support.FILE_PROVIDER_PATHS", + "Name must not be empty" + ) +} \ No newline at end of file diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt index a037909a6..0d6b319d8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt @@ -9,6 +9,7 @@ import app.revanced.patches.music.misc.gms.Constants.REVANCED_MUSIC_PACKAGE_NAME import app.revanced.patches.music.misc.settings.PreferenceScreen import app.revanced.patches.music.misc.settings.settingsPatch import app.revanced.patches.music.misc.spoof.spoofVideoStreamsPatch +import app.revanced.patches.music.misc.fileprovider.fileProviderPatch import app.revanced.patches.shared.castContextFetchFingerprint import app.revanced.patches.shared.misc.gms.gmsCoreSupportPatch import app.revanced.patches.shared.misc.settings.preference.IntentPreference @@ -60,6 +61,10 @@ private fun gmsCoreSupportResourcePatch( ) { dependsOn( addResourcesPatch, - settingsPatch + settingsPatch, + fileProviderPatch( + MUSIC_PACKAGE_NAME, + REVANCED_MUSIC_PACKAGE_NAME + ) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt index 1ea963470..e95db8c36 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch import app.revanced.patches.music.misc.extension.sharedExtensionPatch +import app.revanced.patches.music.misc.gms.Constants.MUSIC_PACKAGE_NAME import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.shared.misc.settings.preference.BasePreference import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen @@ -126,7 +127,7 @@ fun newIntent(settingsName: String) = IntentPreference.Intent( targetClass = "com.google.android.gms.common.api.GoogleApiActivity" ) { // The package name change has to be reflected in the intent. - setOrGetFallbackPackageName("com.google.android.apps.youtube.music") + setOrGetFallbackPackageName(MUSIC_PACKAGE_NAME) } object PreferenceScreen : BasePreferenceScreen() {