feat(YouTube - GmsCore): Require ignoring battery optimizations (#2952)
This commit is contained in:
parent
025f5427c4
commit
c0bef25590
|
@ -34,5 +34,5 @@ object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
|
||||||
PrimeMethodFingerprint,
|
PrimeMethodFingerprint,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
override val gmsCoreVendor by gmsCoreVendorGroupIdOption
|
override val gmsCoreVendorGroupId by gmsCoreVendorGroupIdOption
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package app.revanced.patches.shared.misc.gms
|
||||||
|
|
||||||
import app.revanced.patcher.PatchClass
|
import app.revanced.patcher.PatchClass
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
|
@ -12,7 +12,7 @@ import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.AC
|
||||||
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.AUTHORITIES
|
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.AUTHORITIES
|
||||||
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.PERMISSIONS
|
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.PERMISSIONS
|
||||||
import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint
|
import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint
|
||||||
import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint.GET_GMS_CORE_VENDOR_METHOD_NAME
|
import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint.GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME
|
||||||
import app.revanced.util.exception
|
import app.revanced.util.exception
|
||||||
import app.revanced.util.getReference
|
import app.revanced.util.getReference
|
||||||
import app.revanced.util.returnEarly
|
import app.revanced.util.returnEarly
|
||||||
|
@ -32,7 +32,7 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||||
* @param toPackageName The package name to fall back to if no custom package name is specified in patch options.
|
* @param toPackageName The package name to fall back to if no custom package name is specified in patch options.
|
||||||
* @param primeMethodFingerprint The fingerprint of the "prime" method that needs to be patched.
|
* @param primeMethodFingerprint The fingerprint of the "prime" method that needs to be patched.
|
||||||
* @param earlyReturnFingerprints The fingerprints of methods that need to be returned early.
|
* @param earlyReturnFingerprints The fingerprints of methods that need to be returned early.
|
||||||
* @param mainActivityOnCreateFingerprint The fingerprint of the main activity's onCreate method.
|
* @param mainActivityOnCreateFingerprint The fingerprint of the main activity onCreate method.
|
||||||
* @param integrationsPatchDependency The patch responsible for the integrations.
|
* @param integrationsPatchDependency The patch responsible for the integrations.
|
||||||
* @param gmsCoreSupportResourcePatch The corresponding resource patch that is used to patch the resources.
|
* @param gmsCoreSupportResourcePatch The corresponding resource patch that is used to patch the resources.
|
||||||
* @param dependencies Additional dependencies of this patch.
|
* @param dependencies Additional dependencies of this patch.
|
||||||
|
@ -60,7 +60,10 @@ abstract class BaseGmsCoreSupportPatch(
|
||||||
integrationsPatchDependency,
|
integrationsPatchDependency,
|
||||||
) + dependencies,
|
) + dependencies,
|
||||||
compatiblePackages = compatiblePackages,
|
compatiblePackages = compatiblePackages,
|
||||||
fingerprints = setOf(GmsCoreSupportFingerprint, mainActivityOnCreateFingerprint) + fingerprints,
|
fingerprints = setOf(
|
||||||
|
GmsCoreSupportFingerprint,
|
||||||
|
mainActivityOnCreateFingerprint,
|
||||||
|
) + fingerprints,
|
||||||
requiresIntegrations = true,
|
requiresIntegrations = true,
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
|
@ -68,7 +71,7 @@ abstract class BaseGmsCoreSupportPatch(
|
||||||
gmsCoreSupportResourcePatch.options.values.forEach(options::register)
|
gmsCoreSupportResourcePatch.options.values.forEach(options::register)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal abstract val gmsCoreVendor: String?
|
internal abstract val gmsCoreVendorGroupId: String?
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
val packageName = ChangePackageNamePatch.setOrGetFallbackPackageName(toPackageName)
|
val packageName = ChangePackageNamePatch.setOrGetFallbackPackageName(toPackageName)
|
||||||
|
@ -93,16 +96,17 @@ abstract class BaseGmsCoreSupportPatch(
|
||||||
// Return these methods early to prevent the app from crashing.
|
// Return these methods early to prevent the app from crashing.
|
||||||
earlyReturnFingerprints.toList().returnEarly()
|
earlyReturnFingerprints.toList().returnEarly()
|
||||||
|
|
||||||
// Check the availability of GmsCore.
|
// Verify GmsCore is installed and whitelisted for power optimizations and background usage.
|
||||||
mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstruction(
|
mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstructions(
|
||||||
1, // Hack to not disturb other patches (such as the integrations patch).
|
1, // Hack to not disturb other patches (such as the YTMusic integrations patch).
|
||||||
"invoke-static {}, Lapp/revanced/integrations/shared/GmsCoreSupport;->checkAvailability()V",
|
"invoke-static/range { p0 .. p0 }, Lapp/revanced/integrations/shared/GmsCoreSupport;->" +
|
||||||
|
"checkGmsCore(Landroid/content/Context;)V",
|
||||||
) ?: throw mainActivityOnCreateFingerprint.exception
|
) ?: throw mainActivityOnCreateFingerprint.exception
|
||||||
|
|
||||||
// Change the vendor of GmsCore in ReVanced Integrations.
|
// Change the vendor of GmsCore in ReVanced Integrations.
|
||||||
GmsCoreSupportFingerprint.result?.mutableClass?.methods
|
GmsCoreSupportFingerprint.result?.mutableClass?.methods
|
||||||
?.single { it.name == GET_GMS_CORE_VENDOR_METHOD_NAME }
|
?.single { it.name == GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME }
|
||||||
?.replaceInstruction(0, "const-string v0, \"$gmsCoreVendor\"")
|
?.replaceInstruction(0, "const-string v0, \"$gmsCoreVendorGroupId\"")
|
||||||
?: throw GmsCoreSupportFingerprint.exception
|
?: throw GmsCoreSupportFingerprint.exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,10 +150,10 @@ abstract class BaseGmsCoreSupportPatch(
|
||||||
in PERMISSIONS,
|
in PERMISSIONS,
|
||||||
in ACTIONS,
|
in ACTIONS,
|
||||||
in AUTHORITIES,
|
in AUTHORITIES,
|
||||||
-> referencedString.replace("com.google", gmsCoreVendor!!)
|
-> referencedString.replace("com.google", gmsCoreVendorGroupId!!)
|
||||||
|
|
||||||
// No vendor prefix for whatever reason...
|
// No vendor prefix for whatever reason...
|
||||||
"subscribedfeeds" -> "$gmsCoreVendor.subscribedfeeds"
|
"subscribedfeeds" -> "$gmsCoreVendorGroupId.subscribedfeeds"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +166,7 @@ abstract class BaseGmsCoreSupportPatch(
|
||||||
if (str.startsWith(uriPrefix)) {
|
if (str.startsWith(uriPrefix)) {
|
||||||
return str.replace(
|
return str.replace(
|
||||||
uriPrefix,
|
uriPrefix,
|
||||||
"content://${authority.replace("com.google", gmsCoreVendor!!)}",
|
"content://${authority.replace("com.google", gmsCoreVendorGroupId!!)}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +174,7 @@ abstract class BaseGmsCoreSupportPatch(
|
||||||
// gms also has a 'subscribedfeeds' authority, check for that one too
|
// gms also has a 'subscribedfeeds' authority, check for that one too
|
||||||
val subFeedsUriPrefix = "content://subscribedfeeds"
|
val subFeedsUriPrefix = "content://subscribedfeeds"
|
||||||
if (str.startsWith(subFeedsUriPrefix)) {
|
if (str.startsWith(subFeedsUriPrefix)) {
|
||||||
return str.replace(subFeedsUriPrefix, "content://$gmsCoreVendor.subscribedfeeds")
|
return str.replace(subFeedsUriPrefix, "content://$gmsCoreVendorGroupId.subscribedfeeds")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,6 @@ abstract class BaseGmsCoreSupportResourcePatch(
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
private const val VANCED_VENDOR = "com.mgoogle"
|
|
||||||
private const val PACKAGE_NAME_REGEX_PATTERN = "^[a-z]\\w*(\\.[a-z]\\w*)+\$"
|
private const val PACKAGE_NAME_REGEX_PATTERN = "^[a-z]\\w*(\\.[a-z]\\w*)+\$"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
internal object GmsCoreSupportFingerprint : MethodFingerprint(
|
internal object GmsCoreSupportFingerprint : MethodFingerprint(
|
||||||
customFingerprint = { _, classDef ->
|
customFingerprint = { _, classDef ->
|
||||||
classDef.type.endsWith("GmsCoreSupport;")
|
classDef.type.endsWith("GmsCoreSupport;")
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
const val GET_GMS_CORE_VENDOR_METHOD_NAME = "getGmsCoreVendor"
|
const val GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME = "getGmsCoreVendorGroupId"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,14 @@ package app.revanced.patches.youtube.misc.announcements
|
||||||
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
|
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
import app.revanced.patcher.patch.annotation.Patch
|
||||||
import app.revanced.patches.all.misc.resources.AddResourcesPatch
|
import app.revanced.patches.all.misc.resources.AddResourcesPatch
|
||||||
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
||||||
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
||||||
import app.revanced.patches.youtube.shared.fingerprints.MainActivityFingerprint
|
import app.revanced.patches.youtube.shared.fingerprints.MainActivityOnCreateFingerprint
|
||||||
import app.revanced.util.exception
|
import app.revanced.util.resultOrThrow
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Announcements",
|
name = "Announcements",
|
||||||
|
@ -21,7 +19,7 @@ import com.android.tools.smali.dexlib2.Opcode
|
||||||
)
|
)
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object AnnouncementsPatch : BytecodePatch(
|
object AnnouncementsPatch : BytecodePatch(
|
||||||
setOf(MainActivityFingerprint)
|
setOf(MainActivityOnCreateFingerprint)
|
||||||
) {
|
) {
|
||||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||||
"Lapp/revanced/integrations/youtube/patches/announcements/AnnouncementsPatch;"
|
"Lapp/revanced/integrations/youtube/patches/announcements/AnnouncementsPatch;"
|
||||||
|
@ -33,16 +31,11 @@ object AnnouncementsPatch : BytecodePatch(
|
||||||
SwitchPreference("revanced_announcements")
|
SwitchPreference("revanced_announcements")
|
||||||
)
|
)
|
||||||
|
|
||||||
val onCreateMethod = MainActivityFingerprint.result?.let {
|
MainActivityOnCreateFingerprint.resultOrThrow().mutableMethod.addInstructions(
|
||||||
it.mutableClass.methods.find { method -> method.name == "onCreate" }
|
// Insert index must be great than the insert index used by GmsCoreSupport,
|
||||||
} ?: throw MainActivityFingerprint.exception
|
// as both patch the same method and GmsCore check should be first.
|
||||||
|
1,
|
||||||
val superCallIndex = onCreateMethod.getInstructions().indexOfFirst { it.opcode == Opcode.INVOKE_SUPER_RANGE }
|
"invoke-static/range { p0 .. p0 }, $INTEGRATIONS_CLASS_DESCRIPTOR->showAnnouncement(Landroid/app/Activity;)V"
|
||||||
|
|
||||||
onCreateMethod.addInstructions(
|
|
||||||
superCallIndex + 1,
|
|
||||||
"invoke-static { v1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->showAnnouncement(Landroid/app/Activity;)V"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import app.revanced.patches.youtube.misc.gms.Constants.YOUTUBE_PACKAGE_NAME
|
||||||
import app.revanced.patches.youtube.misc.gms.GmsCoreSupportResourcePatch.gmsCoreVendorGroupIdOption
|
import app.revanced.patches.youtube.misc.gms.GmsCoreSupportResourcePatch.gmsCoreVendorGroupIdOption
|
||||||
import app.revanced.patches.youtube.misc.gms.fingerprints.*
|
import app.revanced.patches.youtube.misc.gms.fingerprints.*
|
||||||
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
|
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
|
||||||
import app.revanced.patches.youtube.shared.fingerprints.HomeActivityFingerprint
|
import app.revanced.patches.youtube.shared.fingerprints.MainActivityOnCreateFingerprint
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
|
object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
|
||||||
|
@ -23,7 +23,7 @@ object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
|
||||||
CastDynamiteModuleV2Fingerprint,
|
CastDynamiteModuleV2Fingerprint,
|
||||||
CastContextFetchFingerprint,
|
CastContextFetchFingerprint,
|
||||||
),
|
),
|
||||||
mainActivityOnCreateFingerprint = HomeActivityFingerprint,
|
mainActivityOnCreateFingerprint = MainActivityOnCreateFingerprint,
|
||||||
integrationsPatchDependency = IntegrationsPatch::class,
|
integrationsPatchDependency = IntegrationsPatch::class,
|
||||||
dependencies = setOf(
|
dependencies = setOf(
|
||||||
HideCastButtonPatch::class,
|
HideCastButtonPatch::class,
|
||||||
|
@ -57,5 +57,5 @@ object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
|
||||||
PrimeMethodFingerprint,
|
PrimeMethodFingerprint,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
override val gmsCoreVendor by gmsCoreVendorGroupIdOption
|
override val gmsCoreVendorGroupId by gmsCoreVendorGroupIdOption
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package app.revanced.patches.youtube.shared.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
|
|
||||||
|
internal object MainActivityOnCreateFingerprint : MethodFingerprint(
|
||||||
|
returnType = "V",
|
||||||
|
parameters = listOf("Landroid/os/Bundle;"),
|
||||||
|
customFingerprint = { methodDef, classDef ->
|
||||||
|
methodDef.name == "onCreate" &&
|
||||||
|
(classDef.type.endsWith("MainActivity;")
|
||||||
|
// Old versions of YouTube called this class "WatchWhileActivity" instead.
|
||||||
|
|| classDef.type.endsWith("WatchWhileActivity;"))
|
||||||
|
}
|
||||||
|
)
|
|
@ -13,8 +13,12 @@
|
||||||
<string name="revanced_settings_import_failure_parse">Import failed: %s</string>
|
<string name="revanced_settings_import_failure_parse">Import failed: %s</string>
|
||||||
</patch>
|
</patch>
|
||||||
<patch id="misc.gms.BaseGmsCoreSupportResourcePatch">
|
<patch id="misc.gms.BaseGmsCoreSupportResourcePatch">
|
||||||
<string name="gms_core_not_installed_warning">GmsCore is not installed. Please install.</string>
|
<string name="gms_core_toast_not_installed_message">GmsCore is not installed. Install it.</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>
|
<string name="gms_core_toast_not_whitelisted_message">Follow the \"Don\'t kill my app\" guide for GmsCore.</string>
|
||||||
|
<string name="gms_core_dialog_title">Action needed</string>
|
||||||
|
<string name="gms_core_dialog_not_whitelisted_using_battery_optimizations_message">GmsCore is not whitelisted from battery optimization.\n\nFollow the \"Don\'t kill my app\" guide for GmsCore.</string>
|
||||||
|
<string name="gms_core_dialog_not_whitelisted_not_allowed_in_background_message">GmsCore does not have permission to run in the background.\n\nFollow the \"Don\'t kill my app\" guide for GmsCore.</string>
|
||||||
|
<string name="gms_core_dialog_ok_button_text">Open website</string>
|
||||||
</patch>
|
</patch>
|
||||||
</app>
|
</app>
|
||||||
<app id="youtube">
|
<app id="youtube">
|
||||||
|
@ -881,6 +885,7 @@
|
||||||
<string name="revanced_announcements_summary_off">Announcements are not shown on startup</string>
|
<string name="revanced_announcements_summary_off">Announcements are not shown on startup</string>
|
||||||
<string name="revanced_announcements_enabled_summary">Show announcements on startup</string>
|
<string name="revanced_announcements_enabled_summary">Show announcements on startup</string>
|
||||||
<string name="revanced_announcements_connection_failed">Failed connecting to announcements provider</string>
|
<string name="revanced_announcements_connection_failed">Failed connecting to announcements provider</string>
|
||||||
|
<string name="revanced_announcements_dialog_dismiss">Dismiss</string>
|
||||||
</patch>
|
</patch>
|
||||||
<patch id="misc.autorepeat.AutoRepeatPatch">
|
<patch id="misc.autorepeat.AutoRepeatPatch">
|
||||||
<string name="revanced_auto_repeat_title">Enable auto-repeat</string>
|
<string name="revanced_auto_repeat_title">Enable auto-repeat</string>
|
||||||
|
|
Loading…
Reference in a new issue