Index: base/android/java/debug_src/org/chromium/base/ManagedInstall.java |
diff --git a/base/android/java/debug_src/org/chromium/base/ManagedInstall.java b/base/android/java/debug_src/org/chromium/base/ManagedInstall.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26050db495f5a109bbc9f4a11c47f6ab4a90a4fe |
--- /dev/null |
+++ b/base/android/java/debug_src/org/chromium/base/ManagedInstall.java |
@@ -0,0 +1,46 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.base; |
+ |
+import android.content.Context; |
+ |
+import java.io.File; |
+import java.util.List; |
+ |
+/** |
+ * Contains hooks for making Managed Install work. Managed Install is where |
+ * native libraries and (TODO) .dex files are pushed out-of-band to external |
+ * storage rather than packaged with the app. |
+ */ |
+public final class ManagedInstall { |
+ private static final String MANAGED_DIR_PREFIX = "/data/local/tmp/managed-app-"; |
+ |
+ public static void initialize(Context context) { |
+ File managedAppDir = new File(MANAGED_DIR_PREFIX + context.getPackageName()); |
+ File managedLibDir = new File(managedAppDir, "lib"); |
+ injectNativeLibDir(context.getClassLoader(), managedLibDir); |
+ } |
+ |
+ @SuppressWarnings("unchecked") |
+ private static void injectNativeLibDir(ClassLoader loader, File nativeLibDir) { |
+ try { |
+ Object dexPathList = Reflect.getField(loader, "pathList"); |
+ Object currentDirs = Reflect.getField(dexPathList, "nativeLibraryDirectories"); |
+ if (currentDirs instanceof List) { |
+ List<File> dirsAsList = (List<File>) currentDirs; |
+ dirsAsList.add(nativeLibDir); |
+ } else { |
+ File[] dirsAsArray = (File[]) currentDirs; |
+ File[] newDirs = new File[] { |
+ nativeLibDir |
+ }; |
+ Reflect.setField(dexPathList, "nativeLibraryDirectories", |
+ Reflect.concatArrays(dirsAsArray, newDirs)); |
+ } |
+ } catch (NoSuchFieldException e) { |
+ throw new RuntimeException(e); |
+ } |
+ } |
+} |