From d2ec2657af93685652634095fd23982615b7a710 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 18 Feb 2026 10:04:19 -0500 Subject: [PATCH 1/2] fix(chimera): resolve package context for renamed GmsCore --- .../gms/chimera/DynamiteContextFactory.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java b/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java index 80580d8342..1697f6ca5d 100644 --- a/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java +++ b/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java @@ -15,6 +15,7 @@ import android.os.Process; import android.util.Log; +import com.google.android.gms.BuildConfig; import com.google.android.gms.chimera.container.DynamiteContext; import com.google.android.gms.chimera.container.DynamiteModuleInfo; import com.google.android.gms.chimera.container.FilteredClassLoader; @@ -34,6 +35,24 @@ public class DynamiteContextFactory { // WeakHashMap cannot be used, and there is a high probability that it will be recycled, causing ClassLoader to be rebuilt private static final Map sClassLoaderCache = new HashMap<>(); + private static Context createGmsPackageContext(Context context) throws PackageManager.NameNotFoundException { + String[] candidates = new String[] { + BuildConfig.APPLICATION_ID, + Constants.USER_MICROG_PACKAGE_NAME, + Constants.GMS_PACKAGE_NAME + }; + + for (String packageName : candidates) { + try { + return context.createPackageContext(packageName, 0); + } catch (PackageManager.NameNotFoundException e) { + Log.d(TAG, "Unable to create package context for " + packageName); + } + } + + throw new PackageManager.NameNotFoundException("No supported GMS package context found"); + } + public static DynamiteContext createDynamiteContext(String moduleId, Context originalContext) { if (originalContext == null) { Log.w(TAG, "create Original context is null"); @@ -49,7 +68,7 @@ public static DynamiteContext createDynamiteContext(String moduleId, Context ori } try { DynamiteModuleInfo moduleInfo = new DynamiteModuleInfo(moduleId); - Context gmsContext = originalContext.createPackageContext(Constants.GMS_PACKAGE_NAME, 0); + Context gmsContext = createGmsPackageContext(originalContext); Context originalAppContext = originalContext.getApplicationContext(); DynamiteContext dynamiteContext; From 9b4ba7139125dd516641f3087a07fd2fcec27193 Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 6 Mar 2026 23:36:46 -0500 Subject: [PATCH 2/2] Fix self-targeting for repackaged GmsCore Stop using GMS_PACKAGE_NAME for call sites that actually mean the installed GmsCore APK and keep the remaining special cases explicit. - auth-api-phone: target the user consent prompt with the runtime package. - play-services-base core: add PackageUtils.getSelfPackageName() for generic Context sites. - auth, credential, folsom, and games service flows: use the runtime self package for internal activity/class launches. - login, account settings, gcm, and games UI/service code: use local packageName/getPackageName() for self broadcasts and intents. - chime registration: read local package info and version from the installed runtime package. - dynamite: resolve the package context directly from BuildConfig.APPLICATION_ID instead of probing fallback candidates. - maps loader: cache the selected remote maps context and expose it through MapsRemoteContextHolder. - mapbox, hms, and vtm backends: build resource/code contexts from the cached remote maps context instead of the embedding app context. - mapbox native loader: stamp extracted libs against the remote maps APK version and code path. --- .../microg/gms/auth/phone/SmsRetrieverCore.kt | 5 ++- .../org/microg/gms/common/PackageUtils.java | 6 ++++ .../gms/chimera/DynamiteContextFactory.java | 18 +--------- .../microg/gms/auth/login/LoginActivity.java | 4 +-- .../microg/gms/games/GamesStubService.java | 2 +- .../java/org/microg/gms/gcm/McsService.java | 2 +- .../gms/accountsettings/ui/MainActivity.kt | 4 +-- .../identity/AuthorizationService.kt | 5 ++- .../gms/auth/folsom/KeyRetrievalService.kt | 4 +-- .../gms/auth/signin/AssistedSignInActivity.kt | 5 ++- .../credential/CredentialManagerService.kt | 5 ++- .../org/microg/gms/games/GamesService.kt | 5 ++- .../microg/gms/games/ui/GamesUiFragment.kt | 5 ++- .../org/microg/gms/gcm/GcmInGmsService.kt | 10 +++--- .../ChimeGmsRegistrationHelper.kt | 5 +-- .../org/microg/gms/ui/AccountsFragment.kt | 3 +- .../microg/gms/maps/hms/utils/MapContext.kt | 5 +-- .../gms/maps/mapbox/utils/MapContext.kt | 4 +-- .../gms/maps/mapbox/utils/MultiArchLoader.kt | 7 ++-- .../maps/vtm/ApplicationContextWrapper.java | 10 ++---- .../microg/gms/maps/MapsContextLoader.java | 6 +++- .../gms/maps/MapsRemoteContextHolder.java | 36 +++++++++++++++++++ 22 files changed, 88 insertions(+), 68 deletions(-) create mode 100644 play-services-maps/src/main/java/org/microg/gms/maps/MapsRemoteContextHolder.java diff --git a/play-services-auth-api-phone/core/src/main/kotlin/org/microg/gms/auth/phone/SmsRetrieverCore.kt b/play-services-auth-api-phone/core/src/main/kotlin/org/microg/gms/auth/phone/SmsRetrieverCore.kt index 1969359ec2..2c87d3a41a 100644 --- a/play-services-auth-api-phone/core/src/main/kotlin/org/microg/gms/auth/phone/SmsRetrieverCore.kt +++ b/play-services-auth-api-phone/core/src/main/kotlin/org/microg/gms/auth/phone/SmsRetrieverCore.kt @@ -41,7 +41,6 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.microg.gms.auth.phone.SmsRetrieverRequestType.RETRIEVER import org.microg.gms.auth.phone.SmsRetrieverRequestType.USER_CONSENT -import org.microg.gms.common.Constants import org.microg.gms.utils.getSignatures import java.nio.charset.StandardCharsets import java.security.MessageDigest @@ -140,7 +139,7 @@ class SmsRetrieverCore(private val context: Context, override val lifecycle: Lif private fun sendUserConsentBroadcast(request: SmsRetrieverRequest, messageBody: String) { val userConsentIntent = Intent(context, UserConsentPromptActivity::class.java) - userConsentIntent.setPackage(Constants.GMS_PACKAGE_NAME) + userConsentIntent.setPackage(context.packageName) userConsentIntent.putExtra(EXTRA_MESSENGER, Messenger(object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { if (Binder.getCallingUid() == Process.myUid()) { @@ -356,4 +355,4 @@ class SmsRetrieverCore(private val context: Context, override val lifecycle: Lif } return deferred.await() } -} \ No newline at end of file +} diff --git a/play-services-base/core/src/main/java/org/microg/gms/common/PackageUtils.java b/play-services-base/core/src/main/java/org/microg/gms/common/PackageUtils.java index 9ae26b1569..89dffff051 100644 --- a/play-services-base/core/src/main/java/org/microg/gms/common/PackageUtils.java +++ b/play-services-base/core/src/main/java/org/microg/gms/common/PackageUtils.java @@ -342,6 +342,12 @@ public static boolean isMainProcess(Context context) { return processName.equals(context.getPackageName()); } + @NonNull + public static String getSelfPackageName(@NonNull Context context) { + Context appContext = context.getApplicationContext(); + return appContext != null ? appContext.getPackageName() : context.getPackageName(); + } + public static void warnIfNotPersistentProcess(Class clazz) { if (!isPersistentProcess()) { Log.w("GmsPackageUtils", clazz.getSimpleName() + " initialized outside persistent process", new RuntimeException()); diff --git a/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java b/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java index 1697f6ca5d..6dc86ce0bb 100644 --- a/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java +++ b/play-services-core/src/main/java/com/google/android/gms/chimera/DynamiteContextFactory.java @@ -20,8 +20,6 @@ import com.google.android.gms.chimera.container.DynamiteModuleInfo; import com.google.android.gms.chimera.container.FilteredClassLoader; -import org.microg.gms.common.Constants; - import java.io.File; import java.util.HashMap; import java.util.Map; @@ -36,21 +34,7 @@ public class DynamiteContextFactory { private static final Map sClassLoaderCache = new HashMap<>(); private static Context createGmsPackageContext(Context context) throws PackageManager.NameNotFoundException { - String[] candidates = new String[] { - BuildConfig.APPLICATION_ID, - Constants.USER_MICROG_PACKAGE_NAME, - Constants.GMS_PACKAGE_NAME - }; - - for (String packageName : candidates) { - try { - return context.createPackageContext(packageName, 0); - } catch (PackageManager.NameNotFoundException e) { - Log.d(TAG, "Unable to create package context for " + packageName); - } - } - - throw new PackageManager.NameNotFoundException("No supported GMS package context found"); + return context.createPackageContext(BuildConfig.APPLICATION_ID, 0); } public static DynamiteContext createDynamiteContext(String moduleId, Context originalContext) { diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java index ec032791f2..8ffbf645b9 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/LoginActivity.java @@ -137,7 +137,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { if (uriPath != null && uriPath.contains("/signup")) { String biz = uri.getQueryParameter("biz"); Intent intent = new Intent(LoginActivity.this, MainActivity.class); - intent.setPackage(GMS_PACKAGE_NAME); + intent.setPackage(getPackageName()); intent.putExtra(EXTRA_URL, biz != null ? GOOGLE_SIGNUP_URL + "?biz=" + biz : GOOGLE_SIGNUP_URL); startActivityForResult(intent, REQUEST_CODE_SIGNUP); return true; @@ -461,7 +461,7 @@ public void onException(Exception exception) { private void notifyGcmGroupUpdate(String accountName) { Intent intent = new Intent(ACTION_GCM_REGISTER_ACCOUNT); - intent.setPackage(Constants.GMS_PACKAGE_NAME); + intent.setPackage(getPackageName()); intent.putExtra(KEY_GCM_REGISTER_ACCOUNT_NAME, accountName); sendBroadcast(intent); } diff --git a/play-services-core/src/main/java/org/microg/gms/games/GamesStubService.java b/play-services-core/src/main/java/org/microg/gms/games/GamesStubService.java index 35b11fd1b4..f2a9a669d0 100644 --- a/play-services-core/src/main/java/org/microg/gms/games/GamesStubService.java +++ b/play-services-core/src/main/java/org/microg/gms/games/GamesStubService.java @@ -50,7 +50,7 @@ public void handleServiceRequest(IGmsCallbacks callback, GetServiceRequest reque } if (packageName == null) packageName = GMS_PACKAGE_NAME; Intent intent = new Intent(ACTION_PLAY_GAMES_UPGRADE); - intent.setPackage(GMS_PACKAGE_NAME); + intent.setPackage(getPackageName()); intent.putExtra(EXTRA_GAME_PACACKE_NAME, packageName); Bundle bundle = new Bundle(); bundle.putParcelable("pendingIntent", PendingIntentCompat.getActivity(this, packageName.hashCode(), intent, FLAG_UPDATE_CURRENT, false)); diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java index 7bce08dbd3..b024ba9ec6 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java @@ -506,7 +506,7 @@ private void handleLoginResponse(LoginResponse loginResponse) { private void notifyGcmConnected() { Intent intent = new Intent(ACTION_GCM_CONNECTED); - intent.setPackage(Constants.GMS_PACKAGE_NAME); + intent.setPackage(getPackageName()); sendBroadcast(intent); } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/accountsettings/ui/MainActivity.kt b/play-services-core/src/main/kotlin/org/microg/gms/accountsettings/ui/MainActivity.kt index b69f8ac8aa..3325cb645a 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/accountsettings/ui/MainActivity.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/accountsettings/ui/MainActivity.kt @@ -332,8 +332,8 @@ class MainActivity : AppCompatActivity() { Log.d(TAG, "updateVerifyNotification: notificationId: $notificationId") if (notificationId == -1) return Intent(ACTION_GCM_NOTIFY_COMPLETE).apply { - setPackage(GMS_PACKAGE_NAME) + setPackage(packageName) putExtra(EXTRA_NOTIFICATION_ACCOUNT, accountName) }.let { sendBroadcast(it) } } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/AuthorizationService.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/AuthorizationService.kt index 286b543485..55fbdad960 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/AuthorizationService.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/AuthorizationService.kt @@ -45,7 +45,6 @@ import org.microg.gms.auth.signin.getServerAuthTokenManager import org.microg.gms.auth.signin.performSignIn import org.microg.gms.auth.signin.scopeUris import org.microg.gms.common.AccountUtils -import org.microg.gms.common.Constants import org.microg.gms.common.GmsService import org.microg.gms.common.PackageUtils import java.util.concurrent.atomic.AtomicInteger @@ -107,7 +106,7 @@ class AuthorizationServiceImpl(val context: Context, val packageName: String, ov defaultAccount?.name?.let { setAccountName(it) } }.build() val intent = Intent(context, AuthSignInActivity::class.java).apply { - `package` = Constants.GMS_PACKAGE_NAME + `package` = PackageUtils.getSelfPackageName(context) putExtra("config", SignInConfiguration(packageName, options)) } AuthorizationResult( @@ -179,4 +178,4 @@ class AuthorizationServiceImpl(val context: Context, val packageName: String, ov runCatching { callback?.onResult(Status.SUCCESS) } } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/folsom/KeyRetrievalService.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/folsom/KeyRetrievalService.kt index 73332793d3..8645feba47 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/folsom/KeyRetrievalService.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/auth/folsom/KeyRetrievalService.kt @@ -35,8 +35,8 @@ import com.google.android.gms.common.internal.GetServiceRequest import com.google.android.gms.common.internal.IGmsCallbacks import org.microg.gms.BaseService import org.microg.gms.auth.folsom.ui.GenericActivity -import org.microg.gms.common.Constants.GMS_PACKAGE_NAME import org.microg.gms.common.GmsService +import org.microg.gms.common.PackageUtils import org.microg.gms.utils.warnOnTransactionIssues private const val TAG = "KeyRetrievalService" @@ -149,7 +149,7 @@ class KeyRetrievalServiceImpl(val context: Context) : IKeyRetrievalService.Stub( callback: IKeyRetrievalCallback?, accountName: String?, type: Int, metadata: ApiMetadata? ) { Log.d(TAG, "Not implemented startUxFlow accountName:$accountName type:$type metadata:$metadata") - val intent = Intent().apply { setClassName(GMS_PACKAGE_NAME, GenericActivity::class.java.name) } + val intent = Intent().apply { setClassName(PackageUtils.getSelfPackageName(context), GenericActivity::class.java.name) } val pendingIntent = PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false) val states = Status(CommonStatusCodes.SUCCESS, "UX flow PendingIntent retrieved.", pendingIntent) callback?.onResult(states) diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInActivity.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInActivity.kt index 15667eae1a..f2f36f92d7 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInActivity.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AssistedSignInActivity.kt @@ -20,7 +20,6 @@ import com.google.android.gms.common.api.CommonStatusCodes import com.google.android.gms.common.api.Status import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer import org.microg.gms.auth.AuthConstants -import org.microg.gms.common.Constants const val ACTION_ASSISTED_SIGN_IN = "com.google.android.gms.auth.api.credentials.ASSISTED_SIGNIN" const val GET_SIGN_IN_INTENT_REQUEST = "get_sign_in_intent_request" @@ -98,7 +97,7 @@ class AssistedSignInActivity : AppCompatActivity() { Log.d(TAG, "prepareSignIn options:$googleSignInOptions") val signInConfiguration = SignInConfiguration(clientPackageName!!, googleSignInOptions!!) val intent = Intent(this, AuthSignInActivity::class.java).apply { - `package` = Constants.GMS_PACKAGE_NAME + `package` = this@AssistedSignInActivity.packageName putExtra("config", signInConfiguration) putExtra("nonce", signInIntentRequest?.nonce) } @@ -166,4 +165,4 @@ class AssistedSignInActivity : AppCompatActivity() { assistedSignInFragment.initView() } } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/credential/CredentialManagerService.kt b/play-services-core/src/main/kotlin/org/microg/gms/credential/CredentialManagerService.kt index f354349108..efdd627b27 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/credential/CredentialManagerService.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/credential/CredentialManagerService.kt @@ -29,7 +29,6 @@ import com.google.android.gms.credential.manager.common.ISettingsCallback import com.google.android.gms.credential.manager.firstparty.internal.ICredentialManagerService import com.google.android.gms.credential.manager.invocationparams.CredentialManagerInvocationParams import org.microg.gms.BaseService -import org.microg.gms.common.Constants import org.microg.gms.common.GmsService import org.microg.gms.common.GooglePackagePermission import org.microg.gms.common.PackageUtils @@ -63,7 +62,7 @@ private class CredentialManagerServiceImpl(private val context: Context, overrid lifecycleScope.launchWhenStarted { runCatching { val intent = Intent().apply { - setClassName(Constants.GMS_PACKAGE_NAME, PASSWORD_MANAGER_CLASS_NAME) + setClassName(PackageUtils.getSelfPackageName(context), PASSWORD_MANAGER_CLASS_NAME) putExtra(EXTRA_KEY_ACCOUNT_NAME, params.account.name) addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } @@ -99,4 +98,4 @@ private class CredentialManagerServiceImpl(private val context: Context, overrid } override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean = warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/games/GamesService.kt b/play-services-core/src/main/kotlin/org/microg/gms/games/GamesService.kt index cd30a1675b..dad72c3418 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/games/GamesService.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/games/GamesService.kt @@ -51,7 +51,6 @@ import org.microg.gms.auth.AuthConstants import org.microg.gms.auth.AuthManager import org.microg.gms.auth.AuthPrefs import org.microg.gms.auth.signin.checkAccountAuthStatus -import org.microg.gms.common.Constants import org.microg.gms.common.GmsService import org.microg.gms.common.PackageUtils import org.microg.gms.games.achievements.AchievementsApiClient @@ -580,7 +579,7 @@ class GamesServiceImpl(val context: Context, override val lifecycle: Lifecycle, private fun getGamesIntent(action: String, block: Intent.() -> Unit = {}) = Intent(action).apply { // Jump to internal page implementation - setPackage(Constants.GMS_PACKAGE_NAME) + setPackage(PackageUtils.getSelfPackageName(context)) putExtra(EXTRA_ACCOUNT_KEY, Integer.toHexString(account.name.hashCode())) putExtra(EXTRA_GAME_PACKAGE_NAME, packageName) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) @@ -793,4 +792,4 @@ class GamesServiceImpl(val context: Context, override val lifecycle: Lifecycle, override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean = warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/games/ui/GamesUiFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/games/ui/GamesUiFragment.kt index 1f25fb1b77..e1f492e212 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/games/ui/GamesUiFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/games/ui/GamesUiFragment.kt @@ -41,7 +41,6 @@ import kotlinx.coroutines.withContext import org.microg.gms.auth.AuthConstants import org.microg.gms.auth.AuthManager import org.microg.gms.auth.signin.SignInConfigurationService -import org.microg.gms.common.Constants import org.microg.gms.games.ACTION_VIEW_ACHIEVEMENTS import org.microg.gms.games.ACTION_VIEW_LEADERBOARDS import org.microg.gms.games.ACTION_VIEW_LEADERBOARDS_SCORES @@ -348,7 +347,7 @@ class GamesUiFragment : BottomSheetDialogFragment() { } }?.adapter = LeaderboardsAdapter(context, loadLeaderboards) { leaderboard -> val intent = Intent(ACTION_VIEW_LEADERBOARDS_SCORES) - intent.setPackage(Constants.GMS_PACKAGE_NAME) + intent.setPackage(context.packageName) intent.putExtra(EXTRA_GAME_PACKAGE_NAME, clientPackageName) intent.putExtra(EXTRA_ACCOUNT_KEY, Integer.toHexString(currentAccount?.name.hashCode())) intent.putExtra(EXTRA_LEADERBOARD_ID, leaderboard.id) @@ -461,4 +460,4 @@ class GamesUiFragment : BottomSheetDialogFragment() { }?.adapter = AchievementsAdapter(context, targetList) } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt b/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt index 36b0c36994..34832c17af 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt @@ -122,7 +122,7 @@ class GcmInGmsService : LifecycleService() { handleIntent(intent) } else { val intent = Intent(ACTION_GCM_RECONNECT).apply { - setPackage(Constants.GMS_PACKAGE_NAME) + setPackage(this@GcmInGmsService.packageName) } sendBroadcast(intent) } @@ -270,7 +270,7 @@ class GcmInGmsService : LifecycleService() { val content = notificationData.content ?: return val intentExtras = notificationData.intentActions?.primaryPayload?.extras ?: return val intent = Intent(this, MainActivity::class.java).apply { - `package` = Constants.GMS_PACKAGE_NAME + `package` = this@GcmInGmsService.packageName flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK intentExtras.forEach { putExtra(it.key, it.value_) } putExtra(KEY_NOTIFICATION_ID, notificationId) @@ -309,9 +309,9 @@ class GcmInGmsService : LifecycleService() { } Log.d(TAG, "updateGroupsWithAccount extras: $extras") val intent = Intent(GcmConstants.ACTION_GCM_SEND).apply { - setPackage(Constants.GMS_PACKAGE_NAME) + setPackage(this@GcmInGmsService.packageName) putExtras(extras) - putExtra(GcmConstants.EXTRA_APP, Intent().apply { setPackage(Constants.GMS_PACKAGE_NAME) }.let { PendingIntentCompat.getBroadcast(this@GcmInGmsService, 0, it, 0, false) }) + putExtra(GcmConstants.EXTRA_APP, Intent().apply { setPackage(this@GcmInGmsService.packageName) }.let { PendingIntentCompat.getBroadcast(this@GcmInGmsService, 0, it, 0, false) }) }.also { it.putExtra(GcmConstants.EXTRA_MESSENGER, Messenger(object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { @@ -387,7 +387,7 @@ class GcmInGmsService : LifecycleService() { } else { Log.d(TAG, "registerGcmInGms: sendBroadcast: ${intent.action}") Intent(intent.action).apply { - setPackage(Constants.GMS_PACKAGE_NAME) + setPackage(this@GcmInGmsService.packageName) putExtras(intent) }.let { sendBroadcast(it) } } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt b/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt index 6131b492d2..39328017b1 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt @@ -33,6 +33,7 @@ import kotlinx.coroutines.withContext import org.microg.gms.auth.AuthConstants import org.microg.gms.checkin.LastCheckinInfo import org.microg.gms.common.Constants +import org.microg.gms.common.PackageUtils import org.microg.gms.common.Utils import org.microg.gms.gcm.GMS_NOTS_BASE_URL import org.microg.gms.gcm.GMS_NOTS_OAUTH_SERVICE @@ -128,7 +129,7 @@ class ChimeGmsRegistrationHelper(val context: Context) { private fun buildDeviceContext() = GmsDeviceContext.build { languageTag = if (SDK_INT >= 24) LocaleList.getDefault().get(0).toLanguageTag() else Locale.getDefault().language gmsDeviceProfile = GmsDeviceProfile.build { - val packageInfo = context.packageManager.getPackageInfo(Constants.GMS_PACKAGE_NAME, 0) + val packageInfo = context.packageManager.getPackageInfo(PackageUtils.getSelfPackageName(context), 0) density = context.resources.displayMetrics.density versionName = packageInfo.versionName release = Build.VERSION.RELEASE @@ -175,4 +176,4 @@ class ChimeGmsRegistrationHelper(val context: Context) { fun resetAllData() { chimeAccountsStore.edit { clear() } } -} \ No newline at end of file +} diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/AccountsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/AccountsFragment.kt index 2be044bd99..b132abb34f 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/AccountsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/AccountsFragment.kt @@ -25,7 +25,6 @@ import com.google.android.gms.R import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.microg.gms.auth.AuthConstants -import org.microg.gms.common.Constants import org.microg.gms.gcm.ACTION_GCM_CONNECTED import org.microg.gms.gcm.ACTION_GCM_REGISTER_ALL_ACCOUNTS import org.microg.gms.people.DatabaseHelper @@ -67,7 +66,7 @@ class AccountsFragment : PreferenceFragmentCompat() { private fun registerGcmInGms() { Intent(ACTION_GCM_REGISTER_ALL_ACCOUNTS).apply { - `package` = Constants.GMS_PACKAGE_NAME + `package` = requireContext().packageName }.let { requireContext().sendBroadcast(it) } } diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/utils/MapContext.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/utils/MapContext.kt index 00cb897918..e4d67aa660 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/utils/MapContext.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/utils/MapContext.kt @@ -14,9 +14,10 @@ import androidx.annotation.RequiresApi import com.huawei.hms.maps.MapClientIdentify import com.huawei.hms.maps.utils.MapClientUtil import org.microg.gms.common.Constants +import org.microg.gms.maps.MapsRemoteContextHolder import java.io.File -class MapContext(private val context: Context) : ContextWrapper(context.createPackageContext(Constants.GMS_PACKAGE_NAME, Context.CONTEXT_INCLUDE_CODE or Context.CONTEXT_IGNORE_SECURITY)) { +class MapContext(private val context: Context) : ContextWrapper(MapsRemoteContextHolder.require()) { private var layoutInflater: LayoutInflater? = null private val appContext: Context get() = context.applicationContext ?: context @@ -77,4 +78,4 @@ class MapContext(private val context: Context) : ContextWrapper(context.createPa companion object { val TAG = "GmsMapContext" } -} \ No newline at end of file +} diff --git a/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MapContext.kt b/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MapContext.kt index f889239647..83b9c6094f 100644 --- a/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MapContext.kt +++ b/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MapContext.kt @@ -21,10 +21,10 @@ import android.content.ContextWrapper import android.content.Intent import android.content.SharedPreferences import android.view.LayoutInflater -import org.microg.gms.common.Constants +import org.microg.gms.maps.MapsRemoteContextHolder import java.io.File -class MapContext(private val context: Context) : ContextWrapper(context.createPackageContext(Constants.GMS_PACKAGE_NAME, Context.CONTEXT_INCLUDE_CODE or Context.CONTEXT_IGNORE_SECURITY)) { +class MapContext(private val context: Context) : ContextWrapper(MapsRemoteContextHolder.require()) { private var layoutInflater: LayoutInflater? = null private val appContext: Context get() = context.applicationContext ?: context diff --git a/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MultiArchLoader.kt b/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MultiArchLoader.kt index 5a37a6d83c..fd1e3cda86 100644 --- a/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MultiArchLoader.kt +++ b/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/MultiArchLoader.kt @@ -21,8 +21,8 @@ import android.content.Context import android.content.pm.ApplicationInfo import android.util.Log import com.mapbox.mapboxsdk.LibraryLoader -import org.microg.gms.common.Constants import org.microg.gms.common.PackageUtils +import org.microg.gms.maps.MapsRemoteContextHolder import java.io.* import java.util.zip.ZipFile @@ -42,8 +42,9 @@ class MultiArchLoader(private val mapContext: Context, private val appContext: C val cacheFileStamp = File("${appContext.cacheDir.absolutePath}/.gmscore/$path.stamp") val cacheVersion = kotlin.runCatching { cacheFileStamp.readText() }.getOrNull() // TODO: Use better version indicator - val mapVersion = PackageUtils.versionName(mapContext, Constants.GMS_PACKAGE_NAME) - val apkFile = File(mapContext.packageCodePath) + val gmsContext = MapsRemoteContextHolder.require() + val mapVersion = PackageUtils.versionName(gmsContext, gmsContext.packageName) + val apkFile = File(gmsContext.packageCodePath) if (!cacheFile.exists() || cacheVersion == null || cacheVersion != mapVersion) { val zipFile = ZipFile(apkFile) val entry = zipFile.getEntry(path) diff --git a/play-services-maps/core/vtm/src/main/java/org/microg/gms/maps/vtm/ApplicationContextWrapper.java b/play-services-maps/core/vtm/src/main/java/org/microg/gms/maps/vtm/ApplicationContextWrapper.java index ebb6caa617..e7e6153599 100644 --- a/play-services-maps/core/vtm/src/main/java/org/microg/gms/maps/vtm/ApplicationContextWrapper.java +++ b/play-services-maps/core/vtm/src/main/java/org/microg/gms/maps/vtm/ApplicationContextWrapper.java @@ -18,9 +18,8 @@ import android.content.Context; import android.content.ContextWrapper; -import android.content.pm.PackageManager; -import org.microg.gms.common.Constants; +import org.microg.gms.maps.MapsRemoteContextHolder; public class ApplicationContextWrapper extends ContextWrapper { private Context applicationContext; @@ -31,12 +30,7 @@ public ApplicationContextWrapper(Context base, Context applicationContext) { } public static ApplicationContextWrapper gmsContextWithAttachedApplicationContext(Context applicationContext) { - try { - Context context = applicationContext.createPackageContext(Constants.GMS_PACKAGE_NAME, CONTEXT_INCLUDE_CODE & CONTEXT_IGNORE_SECURITY); - return new ApplicationContextWrapper(context, applicationContext); - } catch (PackageManager.NameNotFoundException e) { - throw new RuntimeException(e); - } + return new ApplicationContextWrapper(MapsRemoteContextHolder.require(), applicationContext); } public static ApplicationContextWrapper matchingApplicationContext(Context context) { diff --git a/play-services-maps/src/main/java/org/microg/gms/maps/MapsContextLoader.java b/play-services-maps/src/main/java/org/microg/gms/maps/MapsContextLoader.java index 4577b3d4a3..d66f05ae82 100644 --- a/play-services-maps/src/main/java/org/microg/gms/maps/MapsContextLoader.java +++ b/play-services-maps/src/main/java/org/microg/gms/maps/MapsContextLoader.java @@ -58,15 +58,19 @@ private static Context getMapsContext(Context context, @Nullable MapsInitializer } MapsContextLoader.mapsContext = mapsContext; } + MapsRemoteContextHolder.set(MapsContextLoader.mapsContext); return mapsContext; } public static ICreator getCreator(Context context, @Nullable MapsInitializer.Renderer preferredRenderer) { Log.d(TAG, "preferredRenderer: " + preferredRenderer); + Context mapsContext = getMapsContext(context, preferredRenderer); if (creator == null) { Log.d(TAG, "Making Creator dynamically"); try { - Context mapsContext = getMapsContext(context, preferredRenderer); + if (mapsContext == null) { + throw new IllegalStateException("Unable to obtain remote maps context"); + } Class clazz = mapsContext.getClassLoader().loadClass("com.google.android.gms.maps.internal.CreatorImpl"); creator = ICreator.Stub.asInterface((IBinder) clazz.newInstance()); creator.initV2(ObjectWrapper.wrap(mapsContext.getResources()), Constants.GMS_VERSION_CODE); diff --git a/play-services-maps/src/main/java/org/microg/gms/maps/MapsRemoteContextHolder.java b/play-services-maps/src/main/java/org/microg/gms/maps/MapsRemoteContextHolder.java new file mode 100644 index 0000000000..66140f1a1f --- /dev/null +++ b/play-services-maps/src/main/java/org/microg/gms/maps/MapsRemoteContextHolder.java @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2026 microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.microg.gms.maps; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class MapsRemoteContextHolder { + private static volatile Context remoteContext; + + private MapsRemoteContextHolder() { + } + + public static void set(@Nullable Context context) { + remoteContext = context; + } + + @Nullable + public static Context get() { + return remoteContext; + } + + @NonNull + public static Context require() { + Context context = remoteContext; + if (context == null) { + throw new IllegalStateException("Maps remote context has not been initialized"); + } + return context; + } +}