Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@PublicApi
public class GooglePlayServicesUtil {
private static final String TAG = "GooglePlayServicesUtil";
private static final int PACKAGE_CONTEXT_FLAGS = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY;

public static final String GMS_ERROR_DIALOG = "GooglePlayServicesErrorDialog";

Expand All @@ -59,6 +60,13 @@ public class GooglePlayServicesUtil {
*/
public static final String GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending";

private static String[] getGmsPackageCandidates() {
return new String[] {
Constants.USER_MICROG_PACKAGE_NAME,
Constants.GMS_PACKAGE_NAME
};
}

/**
* Returns a dialog to address the provided errorCode. The returned dialog displays a localized
* message about the error and upon user confirmation (by tapping on dialog) will direct them
Expand Down Expand Up @@ -136,11 +144,13 @@ public static String getOpenSourceSoftwareLicenseInfo(Context context) {
* @return The Context object of the Buddy APK or null if the Buddy APK is not installed on the device.
*/
public static Context getRemoteContext(Context context) {
try {
return context.createPackageContext(Constants.GMS_PACKAGE_NAME, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
} catch (PackageManager.NameNotFoundException unused) {
return null;
for (String packageName : getGmsPackageCandidates()) {
try {
return context.createPackageContext(packageName, PACKAGE_CONTEXT_FLAGS);
} catch (PackageManager.NameNotFoundException ignored) {
}
}
return null;
}

/**
Expand All @@ -149,11 +159,13 @@ public static Context getRemoteContext(Context context) {
* @return The Resources object of the Buddy APK or null if the Buddy APK is not installed on the device.
*/
public static Resources getRemoteResources(Context context) {
try {
return context.getPackageManager().getResourcesForApplication(Constants.GMS_PACKAGE_NAME);
} catch (PackageManager.NameNotFoundException unused) {
return null;
for (String packageName : getGmsPackageCandidates()) {
try {
return context.getPackageManager().getResourcesForApplication(packageName);
} catch (PackageManager.NameNotFoundException ignored) {
}
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, ClassLoader> 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 <DynamiteContext> Original context is null");
Expand All @@ -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;
Expand Down