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

fix(YouTube): Fix video playback by switching to ReVanced GmsCore vendor #2907

Merged
merged 11 commits into from
Mar 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ abstract class BaseGmsCoreSupportPatch(
) : BytecodePatch(
name = "GmsCore support",
description = "Allows patched Google apps to run without root and under a different package name " +
"by using GmsCore instead of Google Play Services.",
"by using GmsCore instead of Google Play Services.",
dependencies = setOf(
ChangePackageNamePatch::class,
gmsCoreSupportResourcePatch::class,
integrationsPatchDependency
integrationsPatchDependency,
) + dependencies,
compatiblePackages = compatiblePackages,
fingerprints = setOf(GmsCoreSupportFingerprint, mainActivityOnCreateFingerprint) + fingerprints,
requiresIntegrations = true
requiresIntegrations = true,
) {
init {
// Manually register all options of the resource patch so that they are visible in the patch API.
Expand All @@ -77,7 +77,7 @@ abstract class BaseGmsCoreSupportPatch(
val transformations = arrayOf(
::commonTransform,
::contentUrisTransform,
packageNameTransform(fromPackageName, packageName)
packageNameTransform(fromPackageName, packageName),
)
context.transformStringReferences transform@{ string ->
transformations.forEach { transform ->
Expand All @@ -96,7 +96,7 @@ abstract class BaseGmsCoreSupportPatch(
// Check the availability of GmsCore.
mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstruction(
1, // Hack to not disturb other patches (such as the integrations patch).
"invoke-static {}, Lapp/revanced/integrations/youtube/patches/GmsCoreSupport;->checkAvailability()V"
"invoke-static {}, Lapp/revanced/integrations/youtube/patches/GmsCoreSupport;->checkAvailability()V",
) ?: throw mainActivityOnCreateFingerprint.exception

// Change the vendor of GmsCore in ReVanced Integrations.
Expand Down Expand Up @@ -130,8 +130,8 @@ abstract class BaseGmsCoreSupportPatch(
BuilderInstruction21c(
Opcode.CONST_STRING,
instruction.registerA,
ImmutableStringReference(transformedString)
)
ImmutableStringReference(transformedString),
),
)
}
}
Expand All @@ -145,7 +145,8 @@ abstract class BaseGmsCoreSupportPatch(
"com.google.android.gms",
in PERMISSIONS,
in ACTIONS,
in AUTHORITIES -> referencedString.replace("com.google", gmsCoreVendor!!)
in AUTHORITIES,
-> referencedString.replace("com.google", gmsCoreVendor!!)

// No vendor prefix for whatever reason...
"subscribedfeeds" -> "$gmsCoreVendor.subscribedfeeds"
Expand All @@ -161,7 +162,7 @@ abstract class BaseGmsCoreSupportPatch(
if (str.startsWith(uriPrefix)) {
return str.replace(
uriPrefix,
"content://${authority.replace("com.google", gmsCoreVendor!!)}"
"content://${authority.replace("com.google", gmsCoreVendor!!)}",
)
}
}
Expand All @@ -174,13 +175,13 @@ abstract class BaseGmsCoreSupportPatch(
}

return null

}

private fun packageNameTransform(fromPackageName: String, toPackageName: String): (String) -> String? = { string ->
when (string) {
"$fromPackageName.SuggestionsProvider",
"$fromPackageName.fileprovider" -> string.replace(fromPackageName, toPackageName)
"$fromPackageName.fileprovider",
-> string.replace(fromPackageName, toPackageName)

else -> null
}
Expand Down Expand Up @@ -273,6 +274,9 @@ abstract class BaseGmsCoreSupportPatch(
// fido
"com.google.android.gms.fido.fido2.privileged.START",

// gass
"com.google.android.gms.gass.START",

// games
"com.google.android.gms.games.service.START",
"com.google.android.gms.games.PLAY_GAMES_UPGRADE",
Expand All @@ -292,8 +296,18 @@ abstract class BaseGmsCoreSupportPatch(
// misc
"com.google.android.gms.gmscompliance.service.START",
"com.google.android.gms.oss.licenses.service.START",
"com.google.android.gms.tapandpay.service.BIND",
"com.google.android.gms.measurement.START",
"com.google.android.gms.languageprofile.service.START",
"com.google.android.gms.clearcut.service.START",
"com.google.android.gms.icing.LIGHTWEIGHT_INDEX_SERVICE",

// potoken
"com.google.android.gms.potokens.service.START",

// droidguard/ safetynet
"com.google.android.gms.droidguard.service.START",
"com.google.android.gms.safetynet.service.START",
"com.google.android.gms.tapandpay.service.BIND"
)

/**
Expand All @@ -314,9 +328,9 @@ abstract class BaseGmsCoreSupportPatch(
"com.google.android.gms.fonts",

// phenotype
"com.google.android.gms.phenotype"
"com.google.android.gms.phenotype",
)
}

// endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import app.revanced.patches.all.misc.resources.AddResourcesPatch
import org.w3c.dom.Element
import org.w3c.dom.Node

private const val OBSOLETE_VANCED_MICROG_PATCH_OPTION_VALUE = "com.mgoogle"

/**
* Abstract resource patch that allows Google apps to run without root and under a different package name
* by using GmsCore instead of Google Play Services.
Expand All @@ -27,10 +29,9 @@ abstract class BaseGmsCoreSupportResourcePatch(
internal val gmsCoreVendorOption =
stringPatchOption(
key = "gmsCoreVendor",
default = "com.mgoogle",
default = "app.revanced",
values =
mapOf(
"Vanced" to "com.mgoogle",
"ReVanced" to "app.revanced",
),
title = "GmsCore Vendor",
Expand All @@ -43,6 +44,16 @@ abstract class BaseGmsCoreSupportResourcePatch(
override fun execute(context: ResourceContext) {
AddResourcesPatch(BaseGmsCoreSupportResourcePatch::class)

// Ignore old Vanced MicroG options, if the patch options are from an old Manager/CLI installation.
// This could be done in the option validation, but that shows
// a warning message the user might interpret as something went wrong.
// So instead silently use the updated default value.
// TODO: Remove this temporary logic (and also revert the `gms_core_not_running_warning` string change)
if (gmsCoreVendorOption.value == OBSOLETE_VANCED_MICROG_PATCH_OPTION_VALUE) {
gmsCoreVendorOption.value = gmsCoreVendorOption.default
// If there was patch logging, it would be useful here.
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the simplest approach, to keep updating as simple and foolproof as possible.

Since there is no easy way to show a dialog in the Integrations Gms check, allowing Vanced MicroG makes it much more difficult informing the user what to do to fix their app.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding logging, you can use the regular logger facade by Java:

Logger.info()

context.patchManifest()
context.addSpoofingMetadata()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference

@Patch(
name = "Client spoof",
description = "Adds options to spoof the client to allow video playback.",
dependencies = [SpoofSignaturePatch::class],
description = "Spoofs the client to allow video playback.",
compatiblePackages = [
CompatiblePackage("com.google.android.youtube"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,11 @@ import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen.Sorting
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.*
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ParamsMapPutFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.PlayerResponseModelImplGeneralFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.PlayerResponseModelImplLiveStreamFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.PlayerResponseModelImplRecommendedLevelFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ScrubbedPreviewLayoutFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardRendererDecoderRecommendedLevelFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardRendererDecoderSpecFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardRendererSpecFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardThumbnailFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardThumbnailParentFingerprint
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHookPatch
import app.revanced.util.*
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
Expand All @@ -43,6 +33,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
AddResourcesPatch::class,
],
)
@Deprecated("This patch will be removed in the future.")
object SpoofSignaturePatch : BytecodePatch(
setOf(
PlayerResponseModelImplGeneralFingerprint,
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/addresources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
<string name="revanced_settings_import_failure_parse">Import failed: %s</string>
</patch>
<patch id="misc.gms.BaseGmsCoreSupportResourcePatch">
<!-- Temporarily use an 'update' message, to handle migrating users from Vanced MicroG -->
<string name="gms_core_not_installed_warning">GmsCore is outdated. Please update it.</string>
oSumAtrIX marked this conversation as resolved.
Show resolved Hide resolved
<!-- TODO: change back to this string
<string name="gms_core_not_installed_warning">GmsCore is not installed. Please install.</string>
-->
<string name="gms_core_not_running_warning">GmsCore is failing to run. Please follow the \"Don\'t kill my app\" guide for GmsCore.</string>
</patch>
</app>
Expand Down
Loading