Skip to content

Commit 670030a

Browse files
fix(YouTube - Wide search bar): Do not default to phone layout with tablet devices
1 parent 409f98c commit 670030a

File tree

2 files changed

+60
-55
lines changed

2 files changed

+60
-55
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
11
package app.revanced.patches.youtube.layout.searchbar
22

33
import app.revanced.patcher.fingerprint
4+
import app.revanced.util.containsLiteralInstruction
45
import com.android.tools.smali.dexlib2.AccessFlags
5-
import com.android.tools.smali.dexlib2.Opcode
6-
7-
internal val createSearchSuggestionsFingerprint = fingerprint {
8-
opcodes(
9-
Opcode.INVOKE_STATIC,
10-
Opcode.MOVE_RESULT,
11-
Opcode.CONST_4,
12-
)
13-
strings("ss_rds")
14-
}
156

167
internal val setWordmarkHeaderFingerprint = fingerprint {
178
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
189
returns("V")
1910
parameters("Landroid/widget/ImageView;")
20-
opcodes(
21-
Opcode.IGET_OBJECT,
22-
Opcode.INVOKE_STATIC,
23-
Opcode.MOVE_RESULT,
24-
Opcode.IF_NEZ,
25-
Opcode.IGET_BOOLEAN,
26-
Opcode.IF_EQZ,
27-
Opcode.IGET_OBJECT,
28-
Opcode.CONST,
29-
null, // invoke-static or invoke-virtual.
30-
)
11+
custom { methodDef, _ ->
12+
methodDef.containsLiteralInstruction(ytWordmarkHeaderId) &&
13+
methodDef.containsLiteralInstruction(ytPremiumWordmarkHeaderId)
14+
}
3115
}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
11
package app.revanced.patches.youtube.layout.searchbar
22

3-
import app.revanced.patcher.Fingerprint
4-
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
53
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6-
import app.revanced.patcher.patch.BytecodePatchContext
74
import app.revanced.patcher.patch.bytecodePatch
8-
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
5+
import app.revanced.patcher.patch.resourcePatch
96
import app.revanced.patches.all.misc.resources.addResources
107
import app.revanced.patches.all.misc.resources.addResourcesPatch
8+
import app.revanced.patches.shared.misc.mapping.get
9+
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
10+
import app.revanced.patches.shared.misc.mapping.resourceMappings
1111
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
1212
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
1313
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
1414
import app.revanced.patches.youtube.misc.settings.settingsPatch
15+
import app.revanced.util.addInstructionsAtControlFlowLabel
16+
import app.revanced.util.findInstructionIndicesReversedOrThrow
17+
import app.revanced.util.getReference
18+
import app.revanced.util.indexOfFirstInstructionOrThrow
19+
import com.android.tools.smali.dexlib2.Opcode
1520
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
21+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
1622

1723
private const val EXTENSION_CLASS_DESCRIPTOR =
1824
"Lapp/revanced/extension/youtube/patches/WideSearchbarPatch;"
1925

26+
internal var ytWordmarkHeaderId = -1L
27+
private set
28+
internal var ytPremiumWordmarkHeaderId = -1L
29+
private set
30+
31+
private val wideSearchbarResourcePatch = resourcePatch {
32+
dependsOn(resourceMappingPatch)
33+
34+
execute {
35+
ytWordmarkHeaderId = resourceMappings[
36+
"attr",
37+
"ytWordmarkHeader",
38+
]
39+
40+
ytPremiumWordmarkHeaderId = resourceMappings[
41+
"attr",
42+
"ytPremiumWordmarkHeader",
43+
]
44+
}
45+
}
46+
2047
val wideSearchbarPatch = bytecodePatch(
2148
name = "Wide search bar",
22-
description = "Adds an option to replace the search icon with a wide search bar. This will hide the YouTube logo when active.",
49+
description = "Adds an option to replace the search icon with a wide search bar. " +
50+
"This will hide the YouTube logo when active.",
2351
) {
2452
dependsOn(
2553
sharedExtensionPatch,
2654
settingsPatch,
2755
addResourcesPatch,
56+
wideSearchbarResourcePatch,
2857
)
2958

3059
compatibleWith(
@@ -46,37 +75,29 @@ val wideSearchbarPatch = bytecodePatch(
4675
SwitchPreference("revanced_wide_searchbar"),
4776
)
4877

49-
/**
50-
* Navigate a fingerprints method at a given index mutably.
51-
*
52-
* @param index The index to navigate to.
53-
* @param from The fingerprint to navigate the method on.
54-
* @return The [MutableMethod] which was navigated on.
55-
*/
56-
fun BytecodePatchContext.walkMutable(index: Int, from: Fingerprint) =
57-
navigate(from.originalMethod).to(index).stop()
78+
setWordmarkHeaderFingerprint.let {
79+
// Navigate to the method that checks if the YT logo is shown beside the search bar.
80+
val showLogoMethod = with(it.originalMethod) {
81+
val invokeStaticIndex = indexOfFirstInstructionOrThrow {
82+
opcode == Opcode.INVOKE_STATIC &&
83+
getReference<MethodReference>()?.returnType == "Z"
84+
}
85+
navigate(it.originalMethod).to(invokeStaticIndex).stop()
86+
}
5887

59-
/**
60-
* Injects instructions required for certain methods.
61-
*/
62-
fun MutableMethod.injectSearchBarHook() {
63-
val insertIndex = implementation!!.instructions.size - 1
64-
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
65-
66-
addInstructions(
67-
insertIndex,
68-
"""
69-
invoke-static {v$insertRegister}, $EXTENSION_CLASS_DESCRIPTOR->enableWideSearchbar(Z)Z
70-
move-result v$insertRegister
71-
""",
72-
)
73-
}
88+
showLogoMethod.apply {
89+
findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index ->
90+
val register = getInstruction<OneRegisterInstruction>(index).registerA
7491

75-
mapOf(
76-
setWordmarkHeaderFingerprint to 1,
77-
createSearchSuggestionsFingerprint to createSearchSuggestionsFingerprint.patternMatch!!.startIndex,
78-
).forEach { (fingerprint, callIndex) ->
79-
walkMutable(callIndex, fingerprint).injectSearchBarHook()
92+
addInstructionsAtControlFlowLabel(
93+
index,
94+
"""
95+
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->enableWideSearchbar(Z)Z
96+
move-result v$register
97+
"""
98+
)
99+
}
100+
}
80101
}
81102
}
82103
}

0 commit comments

Comments
 (0)