Skip to content

Commit b10a762

Browse files
Fix YT Music patching
1 parent 9e88fc6 commit b10a762

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

patches/src/main/kotlin/app/revanced/patches/music/layout/branding/CustomBrandingPatch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ val customBrandingPatch = baseCustomBrandingPatch(
6161
originalLauncherIconName = "ic_launcher_release",
6262
originalAppName = "@string/app_launcher_name",
6363
originalAppPackageName = MUSIC_PACKAGE_NAME,
64-
copyExistingIntentsToAliases = false,
64+
isYouTubeMusic = true,
6565
numberOfPresetAppNames = 5,
6666
mainActivityOnCreateFingerprint = musicActivityOnCreateFingerprint,
6767
mainActivityName = MUSIC_MAIN_ACTIVITY_NAME,

patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal fun baseCustomBrandingPatch(
7878
originalLauncherIconName: String,
7979
originalAppName: String,
8080
originalAppPackageName: String,
81-
copyExistingIntentsToAliases: Boolean,
81+
isYouTubeMusic: Boolean,
8282
numberOfPresetAppNames: Int,
8383
mainActivityOnCreateFingerprint: Fingerprint,
8484
mainActivityName: String,
@@ -130,15 +130,23 @@ internal fun baseCustomBrandingPatch(
130130
numberOfPresetAppNamesExtensionFingerprint.method.returnEarly(numberOfPresetAppNames)
131131

132132
notificationFingerprint.method.apply {
133-
// Find the field name of the notification builder. Field is an Object type.
134-
val builderCastIndex = indexOfFirstInstructionOrThrow {
135-
val reference = getReference<TypeReference>()
136-
opcode == Opcode.CHECK_CAST &&
137-
reference?.type == "Landroid/app/Notification\$Builder;"
138-
}
139-
val getBuilderIndex = indexOfFirstInstructionReversedOrThrow(builderCastIndex) {
140-
getReference<FieldReference>()?.type == "Ljava/lang/Object;"
133+
val getBuilderIndex = if (isYouTubeMusic) {
134+
// YT Music the field is not a plain object type.
135+
indexOfFirstInstructionOrThrow {
136+
getReference<FieldReference>()?.type == "Landroid/app/Notification\$Builder;"
137+
}
138+
} else {
139+
// Find the field name of the notification builder. Field is an Object type.
140+
val builderCastIndex = indexOfFirstInstructionOrThrow {
141+
val reference = getReference<TypeReference>()
142+
opcode == Opcode.CHECK_CAST &&
143+
reference?.type == "Landroid/app/Notification\$Builder;"
144+
}
145+
indexOfFirstInstructionReversedOrThrow(builderCastIndex) {
146+
getReference<FieldReference>()?.type == "Ljava/lang/Object;"
147+
}
141148
}
149+
142150
val builderFieldName = getInstruction<ReferenceInstruction>(getBuilderIndex)
143151
.getReference<FieldReference>()
144152

@@ -282,13 +290,7 @@ internal fun baseCustomBrandingPatch(
282290
alias.setAttribute("android:targetActivity", mainActivityName)
283291

284292
// Copy all intents from the original alias so long press actions still work.
285-
if (copyExistingIntentsToAliases) {
286-
for (i in 0 until intents.length) {
287-
alias.appendChild(
288-
intents.item(i).cloneNode(true)
289-
)
290-
}
291-
} else {
293+
if (isYouTubeMusic) {
292294
val intentFilter = document.createElement("intent-filter").apply {
293295
val action = document.createElement("action")
294296
action.setAttribute("android:name", "android.intent.action.MAIN")
@@ -299,6 +301,12 @@ internal fun baseCustomBrandingPatch(
299301
appendChild(category)
300302
}
301303
alias.appendChild(intentFilter)
304+
} else {
305+
for (i in 0 until intents.length) {
306+
alias.appendChild(
307+
intents.item(i).cloneNode(true)
308+
)
309+
}
302310
}
303311

304312
return alias

patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ val customBrandingPatch = baseCustomBrandingPatch(
1313
originalLauncherIconName = "ic_launcher",
1414
originalAppName = "@string/application_name",
1515
originalAppPackageName = YOUTUBE_PACKAGE_NAME,
16-
copyExistingIntentsToAliases = true,
16+
isYouTubeMusic = false,
1717
numberOfPresetAppNames = 5,
1818
mainActivityOnCreateFingerprint = mainActivityOnCreateFingerprint,
1919
mainActivityName = YOUTUBE_MAIN_ACTIVITY_NAME,

0 commit comments

Comments
 (0)