Chromium Code Reviews| 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) { | |
|
nyquist
2015/08/26 05:23:54
Optional nit: Care to add a comment as to when the
agrieve
2015/08/28 14:43:29
Going to skip on this for now just because I don't
| |
| 32 List<File> dirsAsList = (List<File>) currentDirs; | |
| 33 dirsAsList.add(nativeLibDir); | |
| 34 } else { | |
| 35 File[] dirsAsArray = (File[]) currentDirs; | |
| 36 File[] newDirs = new File[] { | |
| 37 nativeLibDir | |
| 38 }; | |
| 39 Reflect.setField(dexPathList, "nativeLibraryDirectories", | |
| 40 Reflect.concatArrays(dirsAsArray, newDirs)); | |
| 41 } | |
| 42 } catch (NoSuchFieldException e) { | |
| 43 throw new RuntimeException(e); | |
| 44 } | |
| 45 } | |
| 46 } | |
| OLD | NEW |