Skip to content

Commit 77864f4

Browse files
unofficial 20.37 support
1 parent a352a05 commit 77864f4

File tree

10 files changed

+107
-25
lines changed

10 files changed

+107
-25
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/VersionCheckPatch.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ private static boolean isVersionOrGreater(String version) {
2323
public static final boolean IS_20_21_OR_GREATER = isVersionOrGreater("20.21.00");
2424

2525
public static final boolean IS_20_22_OR_GREATER = isVersionOrGreater("20.22.00");
26+
27+
public static final boolean IS_20_37_OR_GREATER = isVersionOrGreater("20.37.00");
2628
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_2;
2222
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_3;
2323
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_4;
24+
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.TABLET;
2425
import static app.revanced.extension.youtube.patches.OpenShortsInRegularPlayerPatch.ShortsPlayerType;
2526
import static app.revanced.extension.youtube.patches.SeekbarThumbnailsPatch.SeekbarThumbnailsHighQualityAvailability;
2627
import static app.revanced.extension.youtube.patches.components.PlayerFlyoutMenuItemsFilter.HideAudioFlyoutMenuAvailability;
@@ -47,6 +48,7 @@
4748
import app.revanced.extension.youtube.patches.AlternativeThumbnailsPatch.StillImagesAvailability;
4849
import app.revanced.extension.youtube.patches.AlternativeThumbnailsPatch.ThumbnailOption;
4950
import app.revanced.extension.youtube.patches.AlternativeThumbnailsPatch.ThumbnailStillTime;
51+
import app.revanced.extension.youtube.patches.VersionCheckPatch;
5052
import app.revanced.extension.youtube.sponsorblock.SponsorBlockSettings;
5153
import app.revanced.extension.youtube.swipecontrols.SwipeControlsConfigurationProvider.SwipeOverlayStyle;
5254

@@ -478,6 +480,13 @@ public class Settings extends BaseSettings {
478480
migrateOldSettingToNew(DEPRECATED_RESTORE_OLD_VIDEO_QUALITY_MENU, ADVANCED_VIDEO_QUALITY_MENU);
479481
migrateOldSettingToNew(DEPRECATED_AUTO_CAPTIONS, DISABLE_AUTO_CAPTIONS);
480482

483+
// 20.37+ YT removed parts of the code for the legacy tablet miniplayer.
484+
// This check must remain until the Tablet type is eventually removed.
485+
if (VersionCheckPatch.IS_20_37_OR_GREATER && MINIPLAYER_TYPE.get() == TABLET) {
486+
Logger.printInfo(() -> "Resetting miniplayer tablet type");
487+
MINIPLAYER_TYPE.resetToDefault();
488+
}
489+
481490
// Migrate renamed enum.
482491
//noinspection deprecation
483492
if (MINIPLAYER_TYPE.get() == MiniplayerType.PHONE) {

patches/api/patches.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ public final class app/revanced/patches/youtube/misc/playservice/VersionCheckPat
15491549
public static final fun is_20_30_or_greater ()Z
15501550
public static final fun is_20_31_or_greater ()Z
15511551
public static final fun is_20_34_or_greater ()Z
1552+
public static final fun is_20_37_or_greater ()Z
15521553
}
15531554

15541555
public final class app/revanced/patches/youtube/misc/privacy/RemoveTrackingQueryParameterPatchKt {

patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ internal val miniplayerOverrideNoContextFingerprint by fingerprint {
174174
)
175175
}
176176

177+
/**
178+
* 20.36 and lower. Codes appears to be removed in 20.37+
179+
*/
177180
internal val miniplayerResponseModelSizeCheckFingerprint by fingerprint {
178181
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
179182
returns("L")

patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ val miniplayerPatch = bytecodePatch(
9999

100100

101101
preferences +=
102-
if (is_20_03_or_greater) {
102+
if (is_20_37_or_greater) {
103103
ListPreference("revanced_miniplayer_type")
104+
} else if (is_20_03_or_greater) {
105+
ListPreference(
106+
key = "revanced_miniplayer_type",
107+
entriesKey = "revanced_miniplayer_type_legacy_20_03_entries",
108+
entryValuesKey = "revanced_miniplayer_type_legacy_20_03_entry_values"
109+
)
104110
} else if (is_19_43_or_greater) {
105111
ListPreference(
106112
key = "revanced_miniplayer_type",
@@ -210,7 +216,7 @@ val miniplayerPatch = bytecodePatch(
210216
"""
211217
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->$extensionMethod(F)F
212218
move-result v$register
213-
""",
219+
"""
214220
)
215221
}
216222
}
@@ -226,30 +232,41 @@ val miniplayerPatch = bytecodePatch(
226232
"""
227233
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getModernMiniplayerOverrideType(I)I
228234
move-result v$register
229-
""",
235+
"""
230236
)
231237
}
232238

233239
// region Enable tablet miniplayer.
240+
// Parts of the YT code is removed in 20.37+ and the legacy player no longer works.
234241

235-
miniplayerOverrideNoContextFingerprint.match(
236-
miniplayerDimensionsCalculatorParentFingerprint.originalClassDef,
237-
).method.apply {
238-
findReturnIndicesReversed().forEach { index -> insertLegacyTabletMiniplayerOverride(index) }
239-
}
242+
if (!is_20_37_or_greater) {
243+
miniplayerOverrideNoContextFingerprint.match(
244+
miniplayerDimensionsCalculatorParentFingerprint.originalClassDef,
245+
).method.apply {
246+
findReturnIndicesReversed().forEach { index ->
247+
insertLegacyTabletMiniplayerOverride(
248+
index
249+
)
250+
}
251+
}
240252

241-
// endregion
253+
// endregion
242254

243-
// region Legacy tablet miniplayer hooks.
244-
miniplayerOverrideFingerprint.let {
245-
val appNameStringIndex = it.instructionMatches.last().index
246-
navigate(it.originalMethod).to(appNameStringIndex).stop().apply {
247-
findReturnIndicesReversed().forEach { index -> insertLegacyTabletMiniplayerOverride(index) }
255+
// region Legacy tablet miniplayer hooks.
256+
miniplayerOverrideFingerprint.let {
257+
val appNameStringIndex = it.instructionMatches.last().index
258+
navigate(it.originalMethod).to(appNameStringIndex).stop().apply {
259+
findReturnIndicesReversed().forEach { index ->
260+
insertLegacyTabletMiniplayerOverride(
261+
index
262+
)
263+
}
264+
}
248265
}
249-
}
250266

251-
miniplayerResponseModelSizeCheckFingerprint.let {
252-
it.method.insertLegacyTabletMiniplayerOverride(it.instructionMatches.last().index)
267+
miniplayerResponseModelSizeCheckFingerprint.let {
268+
it.method.insertLegacyTabletMiniplayerOverride(it.instructionMatches.last().index)
269+
}
253270
}
254271

255272
// endregion

patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/Fingerprints.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ import com.android.tools.smali.dexlib2.AccessFlags
1010
import com.android.tools.smali.dexlib2.Opcode
1111

1212
internal val toolBarButtonFingerprint by fingerprint {
13-
returns("V")
1413
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
15-
parameters("Landroid/view/MenuItem;")
14+
returns("V")
1615
instructions(
1716
resourceLiteral(ResourceType.ID, "menu_item_view"),
1817
methodCall(returnType = "I", opcode = Opcode.INVOKE_INTERFACE),
19-
opcode(Opcode.MOVE_RESULT, maxAfter = 0), // Value is zero if resource does not exist.
18+
opcode(Opcode.MOVE_RESULT, maxAfter = 0),
2019
fieldAccess(type = "Landroid/widget/ImageView;", opcode = Opcode.IGET_OBJECT, maxAfter = 6),
2120
methodCall("Landroid/content/res/Resources;", "getDrawable", maxAfter = 8),
2221
methodCall("Landroid/widget/ImageView;", "setImageDrawable", maxAfter = 4)
2322
)
23+
custom { method, _ ->
24+
// 20.37+ has second parameter of "Landroid/content/Context;"
25+
val parameterCount = method.parameterTypes.count()
26+
(parameterCount == 1 || parameterCount == 2)
27+
&& method.parameterTypes.firstOrNull() == "Landroid/view/MenuItem;"
28+
}
2429
}
2530

2631
internal val spoofAppVersionFingerprint by fingerprint {

patches/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import app.revanced.patches.all.misc.resources.addResources
77
import app.revanced.patches.all.misc.resources.addResourcesPatch
88
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
99
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
10+
import app.revanced.patches.youtube.misc.playservice.is_20_37_or_greater
1011
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
1112
import app.revanced.patches.youtube.misc.settings.settingsPatch
1213
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@@ -42,7 +43,11 @@ val bypassURLRedirectsPatch = bytecodePatch(
4243
)
4344

4445
arrayOf(
45-
abUriParserFingerprint to 2,
46+
if (is_20_37_or_greater) {
47+
(abUriParserFingerprint to 2)
48+
} else {
49+
(abUriParserLegacyFingerprint to 2)
50+
},
4651
httpUriParserFingerprint to 0
4752
).forEach { (fingerprint, index) ->
4853
fingerprint.method.apply {

patches/src/main/kotlin/app/revanced/patches/youtube/misc/links/Fingerprints.kt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package app.revanced.patches.youtube.misc.links
22

3-
import app.revanced.patcher.checkCast
4-
import app.revanced.patcher.fieldAccess
53
import app.revanced.patcher.fingerprint
64
import app.revanced.patcher.methodCall
75
import app.revanced.patcher.string
86
import com.android.tools.smali.dexlib2.AccessFlags
97

10-
internal val abUriParserFingerprint by fingerprint {
8+
/**
9+
* 20.36 and lower.
10+
*/
11+
internal val abUriParserLegacyFingerprint by fingerprint {
1112
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
1213
returns("Ljava/lang/Object;")
1314
parameters("Ljava/lang/Object;")
@@ -18,6 +19,23 @@ internal val abUriParserFingerprint by fingerprint {
1819
)
1920
}
2021

22+
/**
23+
* 20.37+
24+
*/
25+
internal val abUriParserFingerprint by fingerprint {
26+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
27+
returns("Ljava/lang/Object;")
28+
parameters("Ljava/lang/Object;")
29+
instructions(
30+
// Method is a switch statement of unrelated code,
31+
// and there's no strings or anything unique to fingerprint.
32+
methodCall(smali = "Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;"),
33+
methodCall(smali = "Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;"),
34+
methodCall(smali = "Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;"),
35+
methodCall(smali = "Ljava/util/List;->get(I)Ljava/lang/Object;"),
36+
)
37+
}
38+
2139
internal val httpUriParserFingerprint by fingerprint {
2240
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
2341
returns("Landroid/net/Uri;")

patches/src/main/kotlin/app/revanced/patches/youtube/misc/playservice/VersionCheckPatch.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ var is_20_31_or_greater = false
7979
private set
8080
var is_20_34_or_greater = false
8181
private set
82+
var is_20_37_or_greater = false
83+
private set
8284

8385
val versionCheckPatch = resourcePatch(
8486
description = "Uses the Play Store service version to find the major/minor version of the YouTube target app.",
@@ -122,5 +124,6 @@ val versionCheckPatch = resourcePatch(
122124
is_20_30_or_greater = 253105000 <= playStoreServicesVersion
123125
is_20_31_or_greater = 253205000 <= playStoreServicesVersion
124126
is_20_34_or_greater = 253505000 <= playStoreServicesVersion
127+
is_20_37_or_greater = 253805000 <= playStoreServicesVersion
125128
}
126129
}

patches/src/main/resources/addresources/values/arrays.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,32 @@
218218
<item>@string/revanced_miniplayer_type_entry_0</item>
219219
<item>@string/revanced_miniplayer_type_entry_1</item>
220220
<item>@string/revanced_miniplayer_type_entry_2</item>
221-
<item>@string/revanced_miniplayer_type_entry_3</item>
221+
<!-- YT legacy tablet code is partially removed in 20.37+ -->
222222
<item>@string/revanced_miniplayer_type_entry_4</item>
223223
<item>@string/revanced_miniplayer_type_entry_5</item>
224224
<item>@string/revanced_miniplayer_type_entry_6</item>
225225
<item>@string/revanced_miniplayer_type_entry_7</item>
226226
</string-array>
227227
<string-array name="revanced_miniplayer_type_entry_values">
228+
<item>DISABLED</item>
229+
<item>DEFAULT</item>
230+
<item>MINIMAL</item>
231+
<item>MODERN_1</item>
232+
<item>MODERN_2</item>
233+
<item>MODERN_3</item>
234+
<item>MODERN_4</item>
235+
</string-array>
236+
<string-array name="revanced_miniplayer_type_legacy_20_03_entries">
237+
<item>@string/revanced_miniplayer_type_entry_0</item>
238+
<item>@string/revanced_miniplayer_type_entry_1</item>
239+
<item>@string/revanced_miniplayer_type_entry_2</item>
240+
<item>@string/revanced_miniplayer_type_entry_3</item>
241+
<item>@string/revanced_miniplayer_type_entry_4</item>
242+
<item>@string/revanced_miniplayer_type_entry_5</item>
243+
<item>@string/revanced_miniplayer_type_entry_6</item>
244+
<item>@string/revanced_miniplayer_type_entry_7</item>
245+
</string-array>
246+
<string-array name="revanced_miniplayer_type_legacy_20_03_entry_values">
228247
<item>DISABLED</item>
229248
<item>DEFAULT</item>
230249
<item>MINIMAL</item>

0 commit comments

Comments
 (0)