blob: 18b3c77dfb9dd86423c80410ab76df43e5a4015e [file] [log] [blame]
jbudorickd79351a2015-08-26 06:36:59 +09001// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.base.multidex;
6
7import android.content.Context;
8import android.os.Build;
9import android.os.Process;
10import android.support.multidex.MultiDex;
11
12import org.chromium.base.Log;
13import org.chromium.base.VisibleForTesting;
14
15import java.lang.reflect.InvocationTargetException;
16
17/**
18 * Performs multidex installation for non-isolated processes.
19 */
20public class ChromiumMultiDex {
21
dgn894055e2015-10-14 19:29:49 +090022 private static final String TAG = "base_multidex";
jbudorickd79351a2015-08-26 06:36:59 +090023
24 /**
25 * Installs secondary dexes if possible.
26 *
27 * Isolated processes (e.g. renderer processes) can't load secondary dex files on
28 * K and below, so we don't even try in that case.
29 *
30 * @param context The application context.
31 */
32 @VisibleForTesting
jbudorick562aab62015-11-13 09:44:58 +090033#if defined(CONFIGURATION_NAME_Debug)
jbudorickd79351a2015-08-26 06:36:59 +090034 public static void install(Context context) {
35 try {
36 // TODO(jbudorick): Back out this version check once support for K & below works.
37 // http://crbug.com/512357
38 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && processIsIsolated()) {
39 Log.i(TAG, "Skipping multidex installation: inside isolated process.");
40 } else {
41 MultiDex.install(context);
42 Log.i(TAG, "Completed multidex installation.");
43 }
44 } catch (NoSuchMethodException e) {
45 Log.wtf(TAG, "Failed multidex installation", e);
46 } catch (IllegalAccessException e) {
47 Log.wtf(TAG, "Failed multidex installation", e);
48 } catch (InvocationTargetException e) {
49 Log.wtf(TAG, "Failed multidex installation", e);
50 }
51 }
52
53 // Calls Process.isIsolated, a private Android API.
54 private static boolean processIsIsolated()
55 throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
56 return (boolean) Process.class.getMethod("isIsolated").invoke(null);
57 }
jbudorick562aab62015-11-13 09:44:58 +090058#else
59 public static void install(Context context) {
60 }
61#endif
jbudorickd79351a2015-08-26 06:36:59 +090062
63}