Skip to content

Commit 328234f

Browse files
fix(YouTube Music - GmsCore support): Handle sharing links to certain apps such as Instagram (#6026)
1 parent 326953c commit 328234f

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package app.revanced.patches.music.misc.fileprovider
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
4+
import app.revanced.patcher.patch.bytecodePatch
5+
import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName
6+
import app.revanced.patches.music.utils.fix.fileprovider.fileProviderResolverFingerprint
7+
8+
internal fun fileProviderPatch(
9+
youtubePackageName: String,
10+
musicPackageName: String
11+
) = bytecodePatch(
12+
description = "Fixes broken YouTube Music file provider that prevents sharing with specific apps such as Instagram."
13+
) {
14+
finalize {
15+
// Must do modification last, so change package name value is correctly set.
16+
val musicChangedPackageName = setOrGetFallbackPackageName(musicPackageName)
17+
18+
// For some reason, if the app gets "android.support.FILE_PROVIDER_PATHS",
19+
// the package name of YouTube is used, not the package name of the YT Music.
20+
//
21+
// There is no issue in the stock YT Music, but this is an issue in the GmsCore Build.
22+
// https://github.com/ReVanced/revanced-patches/issues/55
23+
//
24+
// To solve this issue, replace the package name of YouTube with YT Music's package name.
25+
fileProviderResolverFingerprint.method.addInstructionsWithLabels(
26+
0,
27+
"""
28+
const-string v0, "com.google.android.youtube.fileprovider"
29+
invoke-static { p1, v0 }, Ljava/util/Objects;->equals(Ljava/lang/Object;Ljava/lang/Object;)Z
30+
move-result v0
31+
if-nez v0, :fix
32+
const-string v0, "$youtubePackageName.fileprovider"
33+
invoke-static { p1, v0 }, Ljava/util/Objects;->equals(Ljava/lang/Object;Ljava/lang/Object;)Z
34+
move-result v0
35+
if-nez v0, :fix
36+
goto :ignore
37+
:fix
38+
const-string p1, "$musicChangedPackageName.fileprovider"
39+
:ignore
40+
nop
41+
"""
42+
)
43+
}
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package app.revanced.patches.music.utils.fix.fileprovider
2+
3+
import app.revanced.patcher.fingerprint
4+
5+
internal val fileProviderResolverFingerprint = fingerprint {
6+
returns("L")
7+
strings(
8+
"android.support.FILE_PROVIDER_PATHS",
9+
"Name must not be empty"
10+
)
11+
}

patches/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import app.revanced.patches.music.misc.gms.Constants.REVANCED_MUSIC_PACKAGE_NAME
99
import app.revanced.patches.music.misc.settings.PreferenceScreen
1010
import app.revanced.patches.music.misc.settings.settingsPatch
1111
import app.revanced.patches.music.misc.spoof.spoofVideoStreamsPatch
12+
import app.revanced.patches.music.misc.fileprovider.fileProviderPatch
1213
import app.revanced.patches.shared.castContextFetchFingerprint
1314
import app.revanced.patches.shared.misc.gms.gmsCoreSupportPatch
1415
import app.revanced.patches.shared.misc.settings.preference.IntentPreference
@@ -60,6 +61,10 @@ private fun gmsCoreSupportResourcePatch(
6061
) {
6162
dependsOn(
6263
addResourcesPatch,
63-
settingsPatch
64+
settingsPatch,
65+
fileProviderPatch(
66+
MUSIC_PACKAGE_NAME,
67+
REVANCED_MUSIC_PACKAGE_NAME
68+
)
6469
)
6570
}

patches/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName
66
import app.revanced.patches.all.misc.resources.addResources
77
import app.revanced.patches.all.misc.resources.addResourcesPatch
88
import app.revanced.patches.music.misc.extension.sharedExtensionPatch
9+
import app.revanced.patches.music.misc.gms.Constants.MUSIC_PACKAGE_NAME
910
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
1011
import app.revanced.patches.shared.misc.settings.preference.BasePreference
1112
import app.revanced.patches.shared.misc.settings.preference.BasePreferenceScreen
@@ -126,7 +127,7 @@ fun newIntent(settingsName: String) = IntentPreference.Intent(
126127
targetClass = "com.google.android.gms.common.api.GoogleApiActivity"
127128
) {
128129
// The package name change has to be reflected in the intent.
129-
setOrGetFallbackPackageName("com.google.android.apps.youtube.music")
130+
setOrGetFallbackPackageName(MUSIC_PACKAGE_NAME)
130131
}
131132

132133
object PreferenceScreen : BasePreferenceScreen() {

0 commit comments

Comments
 (0)