Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6648)

Unified Diff: base/android/java/templates/ChromiumMultiDex.template

Issue 1469803007: Extend the multidex logic to only kick in for the main browser application. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/public/android/java/src/org/chromium/content/common/SurfaceWrapper.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/templates/ChromiumMultiDex.template
diff --git a/base/android/java/templates/ChromiumMultiDex.template b/base/android/java/templates/ChromiumMultiDex.template
index 5761a454541079045caf4e26fcd5a386e1513e6f..0edf3b51e74b592bdfc906888137c9bc605a75c4 100644
--- a/base/android/java/templates/ChromiumMultiDex.template
+++ b/base/android/java/templates/ChromiumMultiDex.template
@@ -4,6 +4,8 @@
package org.chromium.base.multidex;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.os.Build;
import android.os.Process;
@@ -13,6 +15,7 @@ import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
/**
* Performs multidex installation for non-isolated processes.
@@ -38,28 +41,48 @@ public class ChromiumMultiDex {
@VisibleForTesting
#if defined(MULTIDEX_CONFIGURATION_Debug)
public static void install(Context context) {
+ // TODO(jbudorick): Back out this version check once support for K & below works.
+ // http://crbug.com/512357
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
+ && !isBrowserApplicationProcess(context)) {
+ Log.i(TAG, "Skipping multidex installation: inside non browser process.");
+ } else {
+ MultiDex.install(context);
+ Log.i(TAG, "Completed multidex installation.");
+ }
+ }
+
+ // Determines whether the current context is for the main browser application.
+ private static boolean isBrowserApplicationProcess(Context context) {
try {
- // TODO(jbudorick): Back out this version check once support for K & below works.
- // http://crbug.com/512357
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && processIsIsolated()) {
- Log.i(TAG, "Skipping multidex installation: inside isolated process.");
- } else {
- MultiDex.install(context);
- Log.i(TAG, "Completed multidex installation.");
+ Method isIsolatedMethod =
+ android.os.Process.class.getMethod("isIsolated");
+ Object retVal = isIsolatedMethod.invoke(null);
+ if (retVal != null && retVal instanceof Boolean && ((Boolean) retVal)) {
+ return false;
}
- } catch (NoSuchMethodException e) {
- Log.wtf(TAG, "Failed multidex installation", e);
- } catch (IllegalAccessException e) {
- Log.wtf(TAG, "Failed multidex installation", e);
- } catch (InvocationTargetException e) {
- Log.wtf(TAG, "Failed multidex installation", e);
+ } catch (IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | NoSuchMethodException e) {
+ // Ignore and fall back to checking the app processes.
}
- }
- // Calls Process.isIsolated, a private Android API.
- private static boolean processIsIsolated()
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- return (boolean) Process.class.getMethod("isIsolated").invoke(null);
+ try {
nyquist 2015/11/25 00:12:52 Nit: Could you extract most of this block out to a
+ String currentProcessName = null;
+ int pid = android.os.Process.myPid();
+
+ ActivityManager manager =
+ (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ for (RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
+ if (processInfo.pid == pid) {
+ currentProcessName = processInfo.processName;
+ break;
+ }
+ }
+
+ return currentProcessName != null && !currentProcessName.contains(":");
nyquist 2015/11/25 00:12:52 Could you add a comment explaining the significanc
+ } catch (SecurityException ex) {
+ return false;
+ }
}
#else
public static void install(Context context) {
« no previous file with comments | « no previous file | content/public/android/java/src/org/chromium/content/common/SurfaceWrapper.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698