Skip to content

Commit a39ef1e

Browse files
refactor(YouTube Music - Custom branding): Resolve startup app crash when patching unsupported newer app versions
1 parent 1d8e977 commit a39ef1e

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

extensions/shared/library/src/main/java/app/revanced/extension/shared/patches/CustomBrandingPatch.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Context;
66
import android.content.pm.PackageManager;
77
import android.graphics.Color;
8+
import android.view.View;
89

910
import java.util.ArrayList;
1011
import java.util.List;
@@ -71,6 +72,17 @@ private String packageAndNameIndexToClassAlias(String packageName, int appIndex)
7172
}
7273
}
7374

75+
/**
76+
* Injection point.
77+
*/
78+
public static View getLottieViewOrNull(View lottieStartupView) {
79+
if (BaseSettings.CUSTOM_BRANDING_ICON.get() == BrandingTheme.ORIGINAL) {
80+
return lottieStartupView;
81+
}
82+
83+
return null;
84+
}
85+
7486
/**
7587
* Injection point.
7688
*/

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package app.revanced.patches.music.layout.branding
22

3-
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
44
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
55
import app.revanced.patcher.patch.bytecodePatch
6-
import app.revanced.patcher.util.smali.ExternalLabel
76
import app.revanced.patches.music.misc.extension.sharedExtensionPatch
87
import app.revanced.patches.music.misc.gms.Constants.MUSIC_MAIN_ACTIVITY_NAME
98
import app.revanced.patches.music.misc.gms.Constants.MUSIC_PACKAGE_NAME
109
import app.revanced.patches.music.misc.gms.musicActivityOnCreateFingerprint
1110
import app.revanced.patches.music.misc.settings.PreferenceScreen
11+
import app.revanced.patches.shared.layout.branding.EXTENSION_CLASS_DESCRIPTOR
1212
import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch
1313
import app.revanced.patches.shared.misc.mapping.get
1414
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
1515
import app.revanced.patches.shared.misc.mapping.resourceMappings
1616
import app.revanced.util.getReference
1717
import app.revanced.util.indexOfFirstInstructionOrThrow
18-
import app.revanced.util.indexOfFirstInstructionReversed
1918
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
2019
import com.android.tools.smali.dexlib2.Opcode
21-
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
20+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
21+
import com.android.tools.smali.dexlib2.iface.reference.TypeReference
2222

2323
private val disableSplashAnimationPatch = bytecodePatch {
2424

@@ -33,23 +33,22 @@ private val disableSplashAnimationPatch = bytecodePatch {
3333
// but the animation is not always the same size as the launch screen and it's still
3434
// barely shown. Instead turn off the animation entirely (app will also launch a little faster).
3535
cairoSplashAnimationConfigFingerprint.method.apply {
36-
val mainActivityLaunchAnimation = resourceMappings["layout", "main_activity_launch_animation"]
3736
val literalIndex = indexOfFirstLiteralInstructionOrThrow(
38-
mainActivityLaunchAnimation
37+
resourceMappings["layout", "main_activity_launch_animation"]
3938
)
40-
val insertIndex = indexOfFirstInstructionReversed(literalIndex) {
41-
this.opcode == Opcode.INVOKE_VIRTUAL &&
42-
getReference<MethodReference>()?.name == "setContentView"
43-
} + 1
44-
val jumpIndex = indexOfFirstInstructionOrThrow(insertIndex) {
45-
opcode == Opcode.INVOKE_VIRTUAL &&
46-
getReference<MethodReference>()?.parameterTypes?.firstOrNull() == "Ljava/lang/Runnable;"
47-
} + 1
39+
val checkCastIndex = indexOfFirstInstructionOrThrow(literalIndex) {
40+
opcode == Opcode.CHECK_CAST &&
41+
getReference<TypeReference>()?.type == "Lcom/airbnb/lottie/LottieAnimationView;"
42+
}
43+
val register = getInstruction<OneRegisterInstruction>(checkCastIndex).registerA
4844

49-
addInstructionsWithLabels(
50-
insertIndex,
51-
"goto :skip_animation",
52-
ExternalLabel("skip_animation", getInstruction(jumpIndex))
45+
// If using a custom icon then set the lottie animation view to null to bypasses the startup animation.
46+
addInstructions(
47+
checkCastIndex,
48+
"""
49+
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getLottieViewOrNull(Landroid/view/View;)Landroid/view/View;
50+
move-result-object v$register
51+
"""
5352
)
5453
}
5554
}

0 commit comments

Comments
 (0)