@@ -2,7 +2,7 @@ package app.revanced.patches.shared.misc.gms
22
33import app.revanced.patcher.PatchClass
44import app.revanced.patcher.data.BytecodeContext
5- import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
66import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
77import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
88import app.revanced.patcher.fingerprint.MethodFingerprint
@@ -12,7 +12,7 @@ import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.AC
1212import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.AUTHORITIES
1313import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch.Constants.PERMISSIONS
1414import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint
15- import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint.GET_GMS_CORE_VENDOR_METHOD_NAME
15+ import app.revanced.patches.shared.misc.gms.fingerprints.GmsCoreSupportFingerprint.GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME
1616import app.revanced.util.exception
1717import app.revanced.util.getReference
1818import app.revanced.util.returnEarly
@@ -32,7 +32,7 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
3232 * @param toPackageName The package name to fall back to if no custom package name is specified in patch options.
3333 * @param primeMethodFingerprint The fingerprint of the "prime" method that needs to be patched.
3434 * @param earlyReturnFingerprints The fingerprints of methods that need to be returned early.
35- * @param mainActivityOnCreateFingerprint The fingerprint of the main activity's onCreate method.
35+ * @param mainActivityOnCreateFingerprint The fingerprint of the main activity onCreate method.
3636 * @param integrationsPatchDependency The patch responsible for the integrations.
3737 * @param gmsCoreSupportResourcePatch The corresponding resource patch that is used to patch the resources.
3838 * @param dependencies Additional dependencies of this patch.
@@ -60,15 +60,18 @@ abstract class BaseGmsCoreSupportPatch(
6060 integrationsPatchDependency,
6161 ) + dependencies,
6262 compatiblePackages = compatiblePackages,
63- fingerprints = setOf(GmsCoreSupportFingerprint , mainActivityOnCreateFingerprint) + fingerprints,
63+ fingerprints = setOf(
64+ GmsCoreSupportFingerprint ,
65+ mainActivityOnCreateFingerprint,
66+ ) + fingerprints,
6467 requiresIntegrations = true ,
6568) {
6669 init {
6770 // Manually register all options of the resource patch so that they are visible in the patch API.
6871 gmsCoreSupportResourcePatch.options.values.forEach(options::register)
6972 }
7073
71- internal abstract val gmsCoreVendor : String?
74+ internal abstract val gmsCoreVendorGroupId : String?
7275
7376 override fun execute (context : BytecodeContext ) {
7477 val packageName = ChangePackageNamePatch .setOrGetFallbackPackageName(toPackageName)
@@ -93,16 +96,17 @@ abstract class BaseGmsCoreSupportPatch(
9396 // Return these methods early to prevent the app from crashing.
9497 earlyReturnFingerprints.toList().returnEarly()
9598
96- // Check the availability of GmsCore.
97- mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstruction(
98- 1 , // Hack to not disturb other patches (such as the integrations patch).
99- " invoke-static {}, Lapp/revanced/integrations/shared/GmsCoreSupport;->checkAvailability()V" ,
99+ // Verify GmsCore is installed and whitelisted for power optimizations and background usage.
100+ mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstructions(
101+ 1 , // Hack to not disturb other patches (such as the YTMusic integrations patch).
102+ " invoke-static/range { p0 .. p0 }, Lapp/revanced/integrations/shared/GmsCoreSupport;->" +
103+ " checkGmsCore(Landroid/content/Context;)V" ,
100104 ) ? : throw mainActivityOnCreateFingerprint.exception
101105
102106 // Change the vendor of GmsCore in ReVanced Integrations.
103107 GmsCoreSupportFingerprint .result?.mutableClass?.methods
104- ?.single { it.name == GET_GMS_CORE_VENDOR_METHOD_NAME }
105- ?.replaceInstruction(0 , " const-string v0, \" $gmsCoreVendor \" " )
108+ ?.single { it.name == GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME }
109+ ?.replaceInstruction(0 , " const-string v0, \" $gmsCoreVendorGroupId \" " )
106110 ? : throw GmsCoreSupportFingerprint .exception
107111 }
108112
@@ -146,10 +150,10 @@ abstract class BaseGmsCoreSupportPatch(
146150 in PERMISSIONS ,
147151 in ACTIONS ,
148152 in AUTHORITIES ,
149- -> referencedString.replace(" com.google" , gmsCoreVendor !! )
153+ -> referencedString.replace(" com.google" , gmsCoreVendorGroupId !! )
150154
151155 // No vendor prefix for whatever reason...
152- " subscribedfeeds" -> " $gmsCoreVendor .subscribedfeeds"
156+ " subscribedfeeds" -> " $gmsCoreVendorGroupId .subscribedfeeds"
153157 else -> null
154158 }
155159
@@ -162,15 +166,15 @@ abstract class BaseGmsCoreSupportPatch(
162166 if (str.startsWith(uriPrefix)) {
163167 return str.replace(
164168 uriPrefix,
165- " content://${authority.replace(" com.google" , gmsCoreVendor !! )} " ,
169+ " content://${authority.replace(" com.google" , gmsCoreVendorGroupId !! )} " ,
166170 )
167171 }
168172 }
169173
170174 // gms also has a 'subscribedfeeds' authority, check for that one too
171175 val subFeedsUriPrefix = " content://subscribedfeeds"
172176 if (str.startsWith(subFeedsUriPrefix)) {
173- return str.replace(subFeedsUriPrefix, " content://$gmsCoreVendor .subscribedfeeds" )
177+ return str.replace(subFeedsUriPrefix, " content://$gmsCoreVendorGroupId .subscribedfeeds" )
174178 }
175179 }
176180
0 commit comments