OLD | NEW |
(Empty) | |
| 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; |
| 6 |
| 7 import android.content.Context; |
| 8 |
| 9 import java.io.File; |
| 10 import java.util.List; |
| 11 |
| 12 /** |
| 13 * Contains hooks for making Incremental Install work. Incremental Install is |
| 14 * where native libraries and (TODO) .dex files are pushed out-of-band to |
| 15 * external storage rather than packaged with the app. |
| 16 */ |
| 17 public final class IncrementalInstall { |
| 18 private static final String MANAGED_DIR_PREFIX = "/data/local/tmp/incrementa
l-app-"; |
| 19 |
| 20 public static void initialize(Context context) { |
| 21 File incrementalAppDir = new File(MANAGED_DIR_PREFIX + context.getPackag
eName()); |
| 22 File incrementalLibDir = new File(incrementalAppDir, "lib"); |
| 23 injectNativeLibDir(context.getClassLoader(), incrementalLibDir); |
| 24 } |
| 25 |
| 26 @SuppressWarnings("unchecked") |
| 27 private static void injectNativeLibDir(ClassLoader loader, File nativeLibDir
) { |
| 28 try { |
| 29 Object dexPathList = Reflect.getField(loader, "pathList"); |
| 30 Object currentDirs = Reflect.getField(dexPathList, "nativeLibraryDir
ectories"); |
| 31 if (currentDirs instanceof List) { |
| 32 List<File> dirsAsList = (List<File>) currentDirs; |
| 33 dirsAsList.add(nativeLibDir); |
| 34 } else { |
| 35 File[] dirsAsArray = (File[]) currentDirs; |
| 36 File[] newDirs = new File[] {nativeLibDir}; |
| 37 Reflect.setField(dexPathList, "nativeLibraryDirectories", |
| 38 Reflect.concatArrays(dirsAsArray, newDirs)); |
| 39 } |
| 40 } catch (NoSuchFieldException e) { |
| 41 throw new RuntimeException(e); |
| 42 } |
| 43 } |
| 44 } |
OLD | NEW |