Skip to content

Commit

Permalink
fix(youtube/integrations): fix playback of embedded videos (ReVanced#…
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed May 29, 2023
1 parent 2669f88 commit 1dffbaf
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint
import org.jf.dexlib2.AccessFlags

/**
* For embedded playback.
* It appears this hook may no longer be needed as one of the constructor parameters is the already hooked
* [EmbeddedPlayerControlsOverlayFingerprint]
*/
object APIPlayerServiceFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ -> methodDef.definingClass == "Lcom/google/android/apps/youtube/embeddedplayer/service/service/jar/ApiPlayerService;" },
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package app.revanced.patches.youtube.misc.integrations.fingerprints

import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint

object InitFingerprint : IntegrationsFingerprint(
/**
* Hooks the context when the app is launched as a regular application (and is not an embedded video playback).
*/
object ApplicationInitFingerprint : IntegrationsFingerprint(
strings = listOf("Application creation", "Application.onCreate"),
// Integrations context is the Activity itself.
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import app.revanced.patcher.extensions.or
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint
import org.jf.dexlib2.AccessFlags

/**
* For embedded playback inside Google Play store (and probably other situations as well).
*
* Note: this fingerprint may no longer be needed, as it appears
* [RemoteEmbedFragmentFingerprint] may be set before this hook is called.
*/
object EmbeddedPlayerControlsOverlayFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PRIVATE or AccessFlags.CONSTRUCTOR,
returnType = "V",
parameters = listOf("L", "L", "L"),
parameters = listOf("Landroid/content/Context;", "L", "L"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.startsWith("Lcom/google/android/apps/youtube/embeddedplayer/service/ui/overlays/controlsoverlay/remoteloaded/")
},
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint
import org.jf.dexlib2.AccessFlags

/**
* For embedded playback inside the Google app (such as the in app 'discover' tab).
*
* Note: this fingerprint may or may not be needed, as
* [RemoteEmbedFragmentFingerprint] might be set before this is called.
*/
object EmbeddedPlayerFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
returnType = "L",
parameters = listOf("L", "L", "Landroid/content/Context;"),
strings = listOf("android.hardware.type.television"), // String is also found in other classes
// Integrations context is the third method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size + 2 }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint
import org.jf.dexlib2.AccessFlags

/**
* For embedded playback. Likely covers Google Play store and other Google products.
*/
object RemoteEmbedFragmentFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
returnType = "V",
parameters = listOf("Landroid/content/Context;", "L", "L"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/apps/youtube/embeddedplayer/service/jar/client/RemoteEmbedFragment;"
},
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint
import org.jf.dexlib2.AccessFlags

/**
* For embedded playback inside 3rd party android app (such as 3rd party Reddit apps).
*/
object RemoteEmbeddedPlayerFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PRIVATE or AccessFlags.CONSTRUCTOR,
returnType = "V",
parameters = listOf("Landroid/content/Context;", "L", "L", "Z"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/youtube/api/jar/client/RemoteEmbeddedPlayer;"
},
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints

import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint

/**
* Old API activity to embed YouTube into 3rd party Android apps.
*
* In 2023 supported was ended and is no longer available,
* but this may still be used by older apps:
* https://developers.google.com/youtube/android/player
*/
object StandalonePlayerActivityFingerprint : IntegrationsFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/youtube/api/StandalonePlayerActivity;"
&& methodDef.name == "onCreate"
},
// Integrations context is the Activity itself.
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.patch.annotations.RequiresIntegrations
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
import app.revanced.patches.youtube.misc.integrations.fingerprints.InitFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.EmbeddedPlayerControlsOverlayFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.ServiceFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.StandalonePlayerFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.EmbeddedPlayerFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.ApplicationInitFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.RemoteEmbedFragmentFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.RemoteEmbeddedPlayerFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.APIPlayerServiceFingerprint
import app.revanced.patches.youtube.misc.integrations.fingerprints.StandalonePlayerActivityFingerprint

@Name("integrations")
@IntegrationsCompatibility
@RequiresIntegrations
class IntegrationsPatch : AbstractIntegrationsPatch(
"Lapp/revanced/integrations/utils/ReVancedUtils;",
listOf(InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint, EmbeddedPlayerControlsOverlayFingerprint),
listOf(
ApplicationInitFingerprint,
StandalonePlayerActivityFingerprint,
RemoteEmbeddedPlayerFingerprint,
RemoteEmbedFragmentFingerprint,
EmbeddedPlayerControlsOverlayFingerprint,
EmbeddedPlayerFingerprint,
APIPlayerServiceFingerprint,
),
)

0 comments on commit 1dffbaf

Please sign in to comment.