jbudorick | d79351a | 2015-08-26 06:36:59 +0900 | [diff] [blame] | 1 | // 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 | |
| 5 | package org.chromium.base.multidex; |
| 6 | |
| 7 | import android.content.Context; |
| 8 | import android.os.Build; |
| 9 | import android.os.Process; |
| 10 | import android.support.multidex.MultiDex; |
| 11 | |
| 12 | import org.chromium.base.Log; |
| 13 | import org.chromium.base.VisibleForTesting; |
| 14 | |
| 15 | import java.lang.reflect.InvocationTargetException; |
| 16 | |
| 17 | /** |
| 18 | * Performs multidex installation for non-isolated processes. |
| 19 | */ |
| 20 | public class ChromiumMultiDex { |
| 21 | |
dgn | 894055e | 2015-10-14 19:29:49 +0900 | [diff] [blame] | 22 | private static final String TAG = "base_multidex"; |
jbudorick | d79351a | 2015-08-26 06:36:59 +0900 | [diff] [blame] | 23 | |
| 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 |
jbudorick | 562aab6 | 2015-11-13 09:44:58 +0900 | [diff] [blame^] | 33 | #if defined(CONFIGURATION_NAME_Debug) |
jbudorick | d79351a | 2015-08-26 06:36:59 +0900 | [diff] [blame] | 34 | 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 | } |
jbudorick | 562aab6 | 2015-11-13 09:44:58 +0900 | [diff] [blame^] | 58 | #else |
| 59 | public static void install(Context context) { |
| 60 | } |
| 61 | #endif |
jbudorick | d79351a | 2015-08-26 06:36:59 +0900 | [diff] [blame] | 62 | |
| 63 | } |