Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube): Support version 19.43.41 #3854

Merged
merged 8 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@

/** @noinspection unused*/
public final class DisableFullscreenAmbientModePatch {
public static boolean enableFullScreenAmbientMode() {
return !Settings.DISABLE_FULLSCREEN_AMBIENT_MODE.get();

private static final boolean DISABLE_FULLSCREEN_AMBIENT_MODE = Settings.DISABLE_FULLSCREEN_AMBIENT_MODE.get();

/**
* Constant found in: androidx.window.embedding.COLOR_SYSTEM_DEFAULT
*/
private static final int DIVIDER_ATTRIBUTES_COLOR_SYSTEM_DEFAULT = -16777216;

/**
* Injection point.
*/
public static int getFullScreenBackgroundColor(int originalColor) {
if (DISABLE_FULLSCREEN_AMBIENT_MODE) {
return DIVIDER_ATTRIBUTES_COLOR_SYSTEM_DEFAULT;
}

return originalColor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.revanced.extension.youtube.patches;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.settings.BaseSettings;

@SuppressWarnings("unused")
public final class EnableDebuggingPatch {

private static final ConcurrentMap<Long, Boolean> featureFlags
= new ConcurrentHashMap<>(100, 0.75f, 1);

public static boolean isFeatureFlagEnabled(long flag, boolean value) {
if (value && BaseSettings.DEBUG.get()) {
if (featureFlags.putIfAbsent(flag, true) == null) {
Logger.printDebug(() -> "feature is enabled: " + flag);
}
}

return value;
}
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 5 additions & 5 deletions patches/api/patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,10 @@ public final class app/revanced/patches/youtube/interaction/seekbar/EnableSlideT
public static final fun getEnableSlideToSeekPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatchKt {
public static final fun getSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatchKt {
public static final fun getSwipeControlsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}
Expand Down Expand Up @@ -1196,10 +1200,6 @@ public final class app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch
public static final fun getSeekbarColorPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/layout/seekbar/SeekbarThumbnailsPatchKt {
public static final fun getSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatchKt {
public static final fun getShortsAutoplayPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ public final class app/revanced/patches/youtube/misc/check/CheckEnvironmentPatch
}

public final class app/revanced/patches/youtube/misc/debugging/EnableDebuggingPatchKt {
public static final fun getEnableDebuggingPatch ()Lapp/revanced/patcher/patch/ResourcePatch;
public static final fun getEnableDebuggingPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatchKt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package app.revanced.patches.youtube.layout.seekbar
package app.revanced.patches.youtube.interaction.seekbar

import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.interaction.seekbar.fullscreenSeekbarThumbnailsQualityFingerprint
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package app.revanced.patches.youtube.layout.hide.fullscreenambientmode

import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.playservice.is_19_43_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import java.util.logging.Logger
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/DisableFullscreenAmbientModePatch;"
Expand All @@ -24,7 +26,6 @@ val disableFullscreenAmbientModePatch = bytecodePatch(
settingsPatch,
sharedExtensionPatch,
addResourcesPatch,
versionCheckPatch,
)

compatibleWith(
Expand All @@ -37,30 +38,27 @@ val disableFullscreenAmbientModePatch = bytecodePatch(
),
)

val initializeAmbientModeMatch by initializeAmbientModeFingerprint()
val setFullScreenBackgroundColorMatch by setFullScreenBackgroundColorFingerprint()

execute {
// TODO: fix this patch when 19.43+ is eventually supported.
if (is_19_43_or_greater) {
// 19.43+ the feature flag was inlined as false and no longer exists.
// This patch can be updated to change a single method, but for now show a more descriptive error.
return@execute Logger.getLogger(this::class.java.name)
.severe("'Disable fullscreen ambient mode' does not yet support 19.43+")
}

addResources("youtube", "layout.hide.fullscreenambientmode.disableFullscreenAmbientModePatch")

PreferenceScreen.PLAYER.addPreferences(
SwitchPreference("revanced_disable_fullscreen_ambient_mode"),
)

initializeAmbientModeMatch.mutableMethod.apply {
val moveIsEnabledIndex = initializeAmbientModeMatch.patternMatch!!.endIndex
setFullScreenBackgroundColorMatch.mutableMethod.apply {
val insertIndex = indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "setBackgroundColor"
}
val register = getInstruction<FiveRegisterInstruction>(insertIndex).registerD

addInstruction(
moveIsEnabledIndex,
"invoke-static { }, " +
"$EXTENSION_CLASS_DESCRIPTOR->enableFullScreenAmbientMode()Z",
addInstructions(
insertIndex,
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getFullScreenBackgroundColor(I)I
move-result v$register
"""
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app.revanced.patches.youtube.layout.hide.fullscreenambientmode

import app.revanced.util.literal
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.AccessFlags
import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal val initializeAmbientModeFingerprint = fingerprint {
internal val setFullScreenBackgroundColorFingerprint = fingerprint {
returns("V")
accessFlags(AccessFlags.CONSTRUCTOR, AccessFlags.PUBLIC)
opcodes(Opcode.MOVE_RESULT)
literal { 45389368 }
accessFlags(AccessFlags.PROTECTED, AccessFlags.FINAL)
parameters("Z", "I", "I", "I", "I")
custom { method, classDef ->
classDef.type.endsWith("/YouTubePlayerViewNotForReflection;")
&& method.name == "onLayout"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.revanced.patches.youtube.misc.debugging

import app.revanced.patcher.patch.resourcePatch
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreenPreference
Expand All @@ -9,9 +10,15 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.applyMatch
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode

private const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/EnableDebuggingPatch;"

@Suppress("unused")
val enableDebuggingPatch = resourcePatch(
val enableDebuggingPatch = bytecodePatch(
name = "Enable debugging",
description = "Adds options for debugging.",
) {
Expand All @@ -21,9 +28,19 @@ val enableDebuggingPatch = resourcePatch(
addResourcesPatch,
)

compatibleWith("com.google.android.youtube")
compatibleWith(
"com.google.android.youtube"(
"18.38.44",
"18.49.37",
"19.16.39",
"19.25.37",
"19.34.42",
)
)

val experimentalFeatureFlagParentMatch by experimentalFeatureFlagParentFingerprint()

execute {
execute { context ->
addResources("youtube", "misc.debugging.enableDebuggingPatch")

PreferenceScreen.MISC.addPreferences(
Expand All @@ -38,5 +55,23 @@ val enableDebuggingPatch = resourcePatch(
),
),
)

// Hook the method that looks up if a feature flag is active or not.
experimentalFeatureFlagFingerprint.applyMatch(
context,
experimentalFeatureFlagParentMatch
).mutableMethod.apply {
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT)

addInstructions(
insertIndex,
"""
move-result v0
invoke-static { p1, p2, v0 }, $EXTENSION_CLASS_DESCRIPTOR->isFeatureFlagEnabled(JZ)Z
move-result v0
return v0
"""
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.patches.youtube.misc.debugging

import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal val experimentalFeatureFlagParentFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("L")
parameters("L", "J", "[B")
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
strings("Unable to parse proto typed experiment flag: ")
}

internal val experimentalFeatureFlagFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
returns("Z")
parameters("J", "Z")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.revanced.patches.youtube.misc.litho.filter

import app.revanced.patcher.fingerprint
import app.revanced.util.literal
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

Expand Down Expand Up @@ -48,3 +49,21 @@ internal val emptyComponentFingerprint = fingerprint {
classDef.methods.filter { AccessFlags.STATIC.isSet(it.accessFlags) }.size == 1
}
}

internal val nativeUpbFeatureFlagFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("L")
parameters("L")
opcodes(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
)
literal { 45419603L }
}

internal val lithoNativeComponentNamesFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
returns("Z")
parameters()
literal { 45631264L }
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.playservice.is_19_18_or_greater
import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
Expand Down Expand Up @@ -41,6 +42,8 @@ val lithoFilterPatch = bytecodePatch(
val protobufBufferReferenceMatch by protobufBufferReferenceFingerprint()
val readComponentIdentifierMatch by readComponentIdentifierFingerprint()
val emptyComponentMatch by emptyComponentFingerprint()
val nativeUpbFeatureFlagMatch by nativeUpbFeatureFlagFingerprint()
val lithoNativeComponentNamesMatch by lithoNativeComponentNamesFingerprint()

var filterCount = 0

Expand Down Expand Up @@ -235,6 +238,36 @@ val lithoFilterPatch = bytecodePatch(
}

// endregion

// region A/B test of new Litho native code.

// Turn off a feature flag that enables native code of protobuf parsing (Upb protobuf)
// If this is enabled, then the litho protobuffer hook will always show an empty buffer
// since it's no longer handled by the hooked Java code.
//
// This flag has been present since at least 18.38,
// and forcing it on also works so theoretically it could be enabled anytime.
nativeUpbFeatureFlagMatch.let {
val endIndex = it.patternMatch!!.endIndex
it.mutableMethod.apply {
val register = getInstruction<OneRegisterInstruction>(endIndex).registerA
addInstruction(endIndex + 1, "const/4 v$register, 0x0")
}
}
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved

// Native Litho components. If this feature is enabled, then the litho paths
// are missing nearly all component names and almost all filters are broken.
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
if (is_19_25_or_greater) {
lithoNativeComponentNamesMatch.mutableMethod.apply {
// Don't use return early, so the debug patch logs if this was originally on.
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.RETURN)
val register = getInstruction<OneRegisterInstruction>(insertIndex).registerA

addInstruction(insertIndex, "const/4 v$register, 0x0")
}
}

// endregion
}

finalize {
Expand Down
Loading