OLD | NEW |
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, 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( |
170 dexPathList, "nativeLibraryPathElements", | 170 dexPathList, "nativeLibraryPathElements", |
171 Reflect.concatArrays(nativeLibraryPathElements, additionalElemen
ts)); | 171 Reflect.concatArrays(additionalElements, nativeLibraryPathElemen
ts)); |
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 Loading... |
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 } |
OLD | NEW |