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

Side by Side Diff: build/android/incremental_install/java/org/chromium/incrementalinstall/ClassLoaderPatcher.java

Issue 1729973002: Reland of Add increment install native libraries first in lookup paths (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed Created 4 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
« no previous file with comments | « no previous file | build/android/incremental_install/java/org/chromium/incrementalinstall/Reflect.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.incrementalinstall; 5 package org.chromium.incrementalinstall;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.Build; 8 import android.os.Build;
9 import android.util.Log; 9 import android.util.Log;
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 Log.i(TAG, "Code cache dir: " + optimizedDir); 89 Log.i(TAG, "Code cache dir: " + optimizedDir);
90 // TODO(agrieve): Might need to record classpath ordering if we ever hav e duplicate 90 // TODO(agrieve): Might need to record classpath ordering if we ever hav e duplicate
91 // class names (since then order will matter here). 91 // class names (since then order will matter here).
92 Log.i(TAG, "Loading " + dexFilesArr.length + " dex files"); 92 Log.i(TAG, "Loading " + dexFilesArr.length + " dex files");
93 93
94 Object dexPathList = Reflect.getField(mClassLoader, "pathList"); 94 Object dexPathList = Reflect.getField(mClassLoader, "pathList");
95 Object[] dexElements = (Object[]) Reflect.getField(dexPathList, "dexElem ents"); 95 Object[] dexElements = (Object[]) Reflect.getField(dexPathList, "dexElem ents");
96 Object[] additionalElements = makeDexElements(dexFilesArr, optimizedDir) ; 96 Object[] additionalElements = makeDexElements(dexFilesArr, optimizedDir) ;
97 Reflect.setField( 97 Reflect.setField(dexPathList, "dexElements",
98 dexPathList, "dexElements", Reflect.concatArrays(dexElements, ad ditionalElements)); 98 Reflect.concatArrays(dexElements, dexElements, additionalElement s));
99 } 99 }
100 100
101 /** 101 /**
102 * Sets up all libraries within |libDir| to be loadable by System.loadLibrar y(). 102 * Sets up all libraries within |libDir| to be loadable by System.loadLibrar y().
103 */ 103 */
104 void importNativeLibs(File libDir) throws ReflectiveOperationException, IOEx ception { 104 void importNativeLibs(File libDir) throws ReflectiveOperationException, IOEx ception {
105 Log.i(TAG, "Importing native libraries from: " + libDir); 105 Log.i(TAG, "Importing native libraries from: " + libDir);
106 if (!libDir.exists()) { 106 if (!libDir.exists()) {
107 Log.i(TAG, "No native libs exist."); 107 Log.i(TAG, "No native libs exist.");
108 return; 108 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 144
145 @SuppressWarnings("unchecked") 145 @SuppressWarnings("unchecked")
146 private void addNativeLibrarySearchPath(File nativeLibDir) throws Reflective OperationException { 146 private void addNativeLibrarySearchPath(File nativeLibDir) throws Reflective OperationException {
147 Object dexPathList = Reflect.getField(mClassLoader, "pathList"); 147 Object dexPathList = Reflect.getField(mClassLoader, "pathList");
148 Object currentDirs = Reflect.getField(dexPathList, "nativeLibraryDirecto ries"); 148 Object currentDirs = Reflect.getField(dexPathList, "nativeLibraryDirecto ries");
149 File[] newDirs = new File[] { nativeLibDir }; 149 File[] newDirs = new File[] { nativeLibDir };
150 // Switched from an array to an ArrayList in Lollipop. 150 // Switched from an array to an ArrayList in Lollipop.
151 if (currentDirs instanceof List) { 151 if (currentDirs instanceof List) {
152 List<File> dirsAsList = (List<File>) currentDirs; 152 List<File> dirsAsList = (List<File>) currentDirs;
153 dirsAsList.add(nativeLibDir); 153 dirsAsList.add(0, nativeLibDir);
154 } else { 154 } else {
155 File[] dirsAsArray = (File[]) currentDirs; 155 File[] dirsAsArray = (File[]) currentDirs;
156 Reflect.setField(dexPathList, "nativeLibraryDirectories", 156 Reflect.setField(dexPathList, "nativeLibraryDirectories",
157 Reflect.concatArrays(dirsAsArray, newDirs)); 157 Reflect.concatArrays(newDirs, newDirs, dirsAsArray));
158 } 158 }
159 159
160 Object[] nativeLibraryPathElements; 160 Object[] nativeLibraryPathElements;
161 try { 161 try {
162 nativeLibraryPathElements = 162 nativeLibraryPathElements =
163 (Object[]) Reflect.getField(dexPathList, "nativeLibraryPathE lements"); 163 (Object[]) Reflect.getField(dexPathList, "nativeLibraryPathE lements");
164 } catch (NoSuchFieldException e) { 164 } catch (NoSuchFieldException e) {
165 // This field doesn't exist pre-M. 165 // This field doesn't exist pre-M.
166 return; 166 return;
167 } 167 }
168 Object[] additionalElements = makeNativePathElements(newDirs); 168 Object[] additionalElements = makeNativePathElements(newDirs);
169 Reflect.setField( 169 Reflect.setField(dexPathList, "nativeLibraryPathElements",
170 dexPathList, "nativeLibraryPathElements", 170 Reflect.concatArrays(nativeLibraryPathElements, additionalElemen ts,
171 Reflect.concatArrays(nativeLibraryPathElements, additionalElemen ts)); 171 nativeLibraryPathElements));
172 } 172 }
173 173
174 private static void copyChangedFiles(File srcDir, File dstDir) throws IOExce ption { 174 private static void copyChangedFiles(File srcDir, File dstDir) throws IOExce ption {
175 // No need to delete stale libs since libraries are loaded explicitly. 175 // No need to delete stale libs since libraries are loaded explicitly.
176 int numNotChanged = 0; 176 int numNotChanged = 0;
177 for (File f : srcDir.listFiles()) { 177 for (File f : srcDir.listFiles()) {
178 // Note: Tried using hardlinks, but resulted in EACCES exceptions. 178 // Note: Tried using hardlinks, but resulted in EACCES exceptions.
179 File dest = new File(dstDir, f.getName()); 179 File dest = new File(dstDir, f.getName());
180 if (!copyIfModified(f, dest)) { 180 if (!copyIfModified(f, dest)) {
181 numNotChanged++; 181 numNotChanged++;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 Object[] entries = new Object[files.length]; 229 Object[] entries = new Object[files.length];
230 File emptyDir = new File(""); 230 File emptyDir = new File("");
231 for (int i = 0; i < files.length; ++i) { 231 for (int i = 0; i < files.length; ++i) {
232 File file = files[i]; 232 File file = files[i];
233 Object dexFile = Reflect.invokeMethod(clazz, "loadDexFile", file, op timizedDirectory); 233 Object dexFile = Reflect.invokeMethod(clazz, "loadDexFile", file, op timizedDirectory);
234 entries[i] = Reflect.newInstance(entryClazz, emptyDir, false, file, dexFile); 234 entries[i] = Reflect.newInstance(entryClazz, emptyDir, false, file, dexFile);
235 } 235 }
236 return entries; 236 return entries;
237 } 237 }
238 } 238 }
OLDNEW
« no previous file with comments | « no previous file | build/android/incremental_install/java/org/chromium/incrementalinstall/Reflect.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698