From 82acb84b5f6ff0722a2eb080b53da9dd3622502f Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 6 Apr 2024 22:45:59 +0400 Subject: [PATCH] fix(YouTube - GmsCore support): Prompt to disable battery optimizations, if not done already (#2958) Co-authored-by: oSumAtrIX --- .../patches/music/misc/gms/GmsCoreSupportPatch.kt | 3 +-- .../MusicActivityOnCreateFingerprint.kt | 11 +++++++++++ .../shared/misc/gms/BaseGmsCoreSupportPatch.kt | 4 ++-- src/main/resources/addresources/values/strings.xml | 13 ++++++------- 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/misc/gms/fingerprints/MusicActivityOnCreateFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt index 060d3447c7..3c99992fce 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/gms/GmsCoreSupportPatch.kt @@ -5,7 +5,6 @@ import app.revanced.patches.music.misc.gms.Constants.REVANCED_MUSIC_PACKAGE_NAME import app.revanced.patches.music.misc.gms.GmsCoreSupportResourcePatch.gmsCoreVendorGroupIdOption import app.revanced.patches.music.misc.gms.fingerprints.* import app.revanced.patches.music.misc.integrations.IntegrationsPatch -import app.revanced.patches.music.misc.integrations.fingerprints.ApplicationInitFingerprint import app.revanced.patches.shared.fingerprints.CastContextFetchFingerprint import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch @@ -21,7 +20,7 @@ object GmsCoreSupportPatch : BaseGmsCoreSupportPatch( CastDynamiteModuleV2Fingerprint, CastContextFetchFingerprint, ), - mainActivityOnCreateFingerprint = ApplicationInitFingerprint, + mainActivityOnCreateFingerprint = MusicActivityOnCreateFingerprint, integrationsPatchDependency = IntegrationsPatch::class, gmsCoreSupportResourcePatch = GmsCoreSupportResourcePatch, compatiblePackages = setOf(CompatiblePackage("com.google.android.apps.youtube.music")), diff --git a/src/main/kotlin/app/revanced/patches/music/misc/gms/fingerprints/MusicActivityOnCreateFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/gms/fingerprints/MusicActivityOnCreateFingerprint.kt new file mode 100644 index 0000000000..2e46df2d96 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/gms/fingerprints/MusicActivityOnCreateFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.music.misc.gms.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object MusicActivityOnCreateFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("Landroid/os/Bundle;"), + customFingerprint = { methodDef, classDef -> + methodDef.name == "onCreate" && classDef.type.endsWith("/MusicActivity;") + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/misc/gms/BaseGmsCoreSupportPatch.kt b/src/main/kotlin/app/revanced/patches/shared/misc/gms/BaseGmsCoreSupportPatch.kt index 9d2544b7e8..dd3fa0b599 100644 --- a/src/main/kotlin/app/revanced/patches/shared/misc/gms/BaseGmsCoreSupportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/gms/BaseGmsCoreSupportPatch.kt @@ -98,9 +98,9 @@ abstract class BaseGmsCoreSupportPatch( // Verify GmsCore is installed and whitelisted for power optimizations and background usage. mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstructions( - 1, // Hack to not disturb other patches (such as the YTMusic integrations patch). + 0, "invoke-static/range { p0 .. p0 }, Lapp/revanced/integrations/shared/GmsCoreSupport;->" + - "checkGmsCore(Landroid/content/Context;)V", + "checkGmsCore(Landroid/app/Activity;)V", ) ?: throw mainActivityOnCreateFingerprint.exception // Change the vendor of GmsCore in ReVanced Integrations. diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index a96bf59e6e..0cf574e57e 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -42,13 +42,12 @@ - GmsCore is not installed. Install it. - - Follow the \"Don\'t kill my app\" guide for GmsCore. + MicroG GmsCore is not installed. Install it. Action needed - GmsCore is not whitelisted from battery optimization.\n\nFollow the \"Don\'t kill my app\" guide for GmsCore. - GmsCore does not have permission to run in the background.\n\nFollow the \"Don\'t kill my app\" guide for GmsCore. - Open website + MicroG GmsCore does not have permission to run in the background.\n\nFollow the \"Don\'t kill my app\" guide for your phone, and apply the instructions to your MicroG installation.\n\nThis is required for the app to work. + Open website + MicroG GmsCore battery optimizations must be disabled to prevent issues.\n\nTap on the continue button and disable battery optimizations. + Continue @@ -573,7 +572,7 @@ Hide subscribe button when paused Subscribe button is hidden Subscribe button is shown - Hide thanks button Thanks button is hidden