Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: apk/hijack/org/chromium/deconstructed/NativeInstaller.java

Issue 949803002: Deconstructed APK prototyping Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package org.chromium.deconstructed;
2
3 import android.content.Context;
4 import android.content.pm.ApplicationInfo;
5 import android.util.Log;
6
7 import java.io.File;
8 import java.io.FileInputStream;
9 import java.io.FileOutputStream;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.io.OutputStream;
13 import java.lang.reflect.InvocationTargetException;
14
15 public class NativeInstaller {
16 private static final String TAG = "org.chromium.deconstructed.NativeInstalle r";
17 private static final String NATIVE_LIB_DIR_NAME =
18 "code_cache" + File.separator + "lib";
19
20 public static void install(Context context, File nativeDir)
21 throws IOException, NoSuchFieldException {
22 File[] nativeLibs = nativeDir.listFiles();
23 for (File f : nativeLibs) {
24 if (!isValidLib(f)) {
25 return;
26 }
27 }
28 ApplicationInfo appInfo = context.getApplicationInfo();
29 File installDir = new File(appInfo.dataDir, NATIVE_LIB_DIR_NAME);
30 installDir.mkdirs();
31 android.util.Log.e(TAG, installDir.toString());
32 for (File f : nativeLibs) {
33 File e = new File(installDir, f.getName());
34 copyFile(f, e);
35 e.setExecutable(true);
36 }
37
38 injectNativeLibDir(context.getClassLoader(), installDir);
39 }
40
41 private static boolean isValidLib(File f) {
42 // TODO
43 return true;
44 }
45
46 private static void copyFile(File in, File out) throws IOException {
47 InputStream src = null;
48 OutputStream dst = null;
49 try {
50 src = new FileInputStream(in);
51 dst = new FileOutputStream(out);
52 byte[] buf = new byte[1 << 14]; // 16k
53 int len;
54 while ((len = src.read(buf)) > 0) {
55 dst.write(buf, 0, len);
56 }
57 } finally {
58 // TODO: blegh
59 if (src != null) {
60 src.close();
61 }
62 if (dst != null) {
63 dst.close();
64 }
65 }
66
67 }
68
69 private static void injectNativeLibDir(ClassLoader loader, File nativeLibDir ) throws NoSuchFieldException {
70 Object dexPathList = Reflect.getField(loader, "pathList");
71 Object[] currentDirs = (Object[]) Reflect.getField(dexPathList, "nativeL ibraryDirectories");
72 Object[] newDirs = new Object[] {nativeLibDir};
73 Reflect.setField(dexPathList, "nativeLibraryDirectories", Reflect.concat Arrays(currentDirs, newDirs));
74 }
75 }
OLDNEW
« no previous file with comments | « apk/hijack/org/chromium/deconstructed/JavaInstaller.java ('k') | apk/hijack/org/chromium/deconstructed/Reflect.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698