OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.base.library_loader; | 5 package org.chromium.base.library_loader; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.SystemClock; | 8 import android.os.SystemClock; |
9 import android.util.Log; | 9 import android.util.Log; |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 // One-way switches recording attempts to use Relro sharing in the browser. | 48 // One-way switches recording attempts to use Relro sharing in the browser. |
49 // The flags are used to report UMA stats later. | 49 // The flags are used to report UMA stats later. |
50 private static boolean sIsUsingBrowserSharedRelros = false; | 50 private static boolean sIsUsingBrowserSharedRelros = false; |
51 private static boolean sLoadAtFixedAddressFailed = false; | 51 private static boolean sLoadAtFixedAddressFailed = false; |
52 | 52 |
53 // One-way switch becomes true if the library was loaded from the APK file | 53 // One-way switch becomes true if the library was loaded from the APK file |
54 // directly. | 54 // directly. |
55 private static boolean sLibraryWasLoadedFromApk = false; | 55 private static boolean sLibraryWasLoadedFromApk = false; |
56 | 56 |
57 // One-way switch becomes false if the library was not aligned in the APK | |
58 // file. | |
rmcilroy
2014/10/28 13:07:15
if Linker.isInZipFile.
petrcermak
2014/10/28 13:48:15
Done.
| |
59 private static boolean sLibraryWasAlignedInApk = true; | |
60 | |
57 // One-way switch becomes true if the system library loading failed, | 61 // One-way switch becomes true if the system library loading failed, |
58 // and the right native library was found and loaded by the hack. | 62 // and the right native library was found and loaded by the hack. |
59 // The flag is used to report UMA stats later. | 63 // The flag is used to report UMA stats later. |
60 private static boolean sNativeLibraryHackWasUsed = false; | 64 private static boolean sNativeLibraryHackWasUsed = false; |
61 | 65 |
62 /** | 66 /** |
63 * The same as ensureInitialized(null, false), should only be called | 67 * The same as ensureInitialized(null, false), should only be called |
64 * by non-browser processes. | 68 * by non-browser processes. |
65 * | 69 * |
66 * @throws ProcessInitException | 70 * @throws ProcessInitException |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 assert !sInitialized; | 162 assert !sInitialized; |
159 | 163 |
160 long startTime = SystemClock.uptimeMillis(); | 164 long startTime = SystemClock.uptimeMillis(); |
161 boolean useChromiumLinker = Linker.isUsed(); | 165 boolean useChromiumLinker = Linker.isUsed(); |
162 | 166 |
163 if (useChromiumLinker) { | 167 if (useChromiumLinker) { |
164 // Load libraries using the Chromium linker. | 168 // Load libraries using the Chromium linker. |
165 Linker.prepareLibraryLoad(); | 169 Linker.prepareLibraryLoad(); |
166 | 170 |
167 for (String library : NativeLibraries.LIBRARIES) { | 171 for (String library : NativeLibraries.LIBRARIES) { |
172 // Don't self-load the linker. This is because the build system is | |
173 // not clever enough to understand that all the librarie s packaged | |
174 // in the final .apk don't need to be explicitly loaded. | |
175 if (Linker.isLinkerLibrary(library)) { | |
176 if (Linker.DEBUG) Log.i(TAG, "ignoring self-linker l oad"); | |
rmcilroy
2014/10/28 13:07:15
Don't use Linker.DEBUG here - have a seperate one
petrcermak
2014/10/28 13:48:15
Done (added a separate one).
| |
177 continue; | |
178 } | |
179 | |
168 String zipfile = null; | 180 String zipfile = null; |
169 if (Linker.isInZipFile()) { | 181 if (Linker.isInZipFile()) { |
170 zipfile = context.getApplicationInfo().sourceDir; | 182 zipfile = context.getApplicationInfo().sourceDir; |
183 sLibraryWasAlignedInApk = Linker.checkLibraryAligned InApk( | |
184 zipfile, System.mapLibraryName(library)); | |
171 Log.i(TAG, "Loading " + library + " from within " + zipfile); | 185 Log.i(TAG, "Loading " + library + " from within " + zipfile); |
172 } else { | 186 } else { |
173 Log.i(TAG, "Loading: " + library); | 187 Log.i(TAG, "Loading: " + library); |
174 } | 188 } |
175 | 189 |
176 boolean isLoaded = false; | 190 boolean isLoaded = false; |
177 if (Linker.isUsingBrowserSharedRelros()) { | 191 if (Linker.isUsingBrowserSharedRelros()) { |
178 sIsUsingBrowserSharedRelros = true; | 192 sIsUsingBrowserSharedRelros = true; |
179 try { | 193 try { |
180 if (zipfile != null) { | 194 if (zipfile != null) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 | 333 |
320 // Returns the device's status for loading a library directly from the APK f ile. | 334 // Returns the device's status for loading a library directly from the APK f ile. |
321 // This method can only be called when the Chromium linker is used. | 335 // This method can only be called when the Chromium linker is used. |
322 private static int getLibraryLoadFromApkStatus(Context context) { | 336 private static int getLibraryLoadFromApkStatus(Context context) { |
323 assert Linker.isUsed(); | 337 assert Linker.isUsed(); |
324 | 338 |
325 if (sLibraryWasLoadedFromApk) { | 339 if (sLibraryWasLoadedFromApk) { |
326 return LibraryLoadFromApkStatusCodes.SUCCESSFUL; | 340 return LibraryLoadFromApkStatusCodes.SUCCESSFUL; |
327 } | 341 } |
328 | 342 |
343 if (!sLibraryWasAlignedInApk) { | |
344 return LibraryLoadFromApkStatusCodes.NOT_ALIGNED; | |
345 } | |
346 | |
329 if (context == null) { | 347 if (context == null) { |
330 Log.w(TAG, "Unknown APK filename due to null context"); | 348 Log.w(TAG, "Unknown APK filename due to null context"); |
331 return LibraryLoadFromApkStatusCodes.UNKNOWN; | 349 return LibraryLoadFromApkStatusCodes.UNKNOWN; |
332 } | 350 } |
333 | 351 |
334 return Linker.checkLibraryLoadFromApkSupport(context.getApplicationInfo( ).sourceDir) ? | 352 return Linker.checkLibraryLoadFromApkSupport(context.getApplicationInfo( ).sourceDir) ? |
335 LibraryLoadFromApkStatusCodes.SUPPORTED : | 353 LibraryLoadFromApkStatusCodes.SUPPORTED : |
336 LibraryLoadFromApkStatusCodes.NOT_SUPPORTED; | 354 LibraryLoadFromApkStatusCodes.NOT_SUPPORTED; |
337 } | 355 } |
338 | 356 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 private static native void nativeRegisterChromiumAndroidLinkerRendererHistog ram( | 391 private static native void nativeRegisterChromiumAndroidLinkerRendererHistog ram( |
374 boolean requestedSharedRelro, | 392 boolean requestedSharedRelro, |
375 boolean loadAtFixedAddressFailed); | 393 boolean loadAtFixedAddressFailed); |
376 | 394 |
377 // Get the version of the native library. This is needed so that we can chec k we | 395 // Get the version of the native library. This is needed so that we can chec k we |
378 // have the right version before initializing the (rest of the) JNI. | 396 // have the right version before initializing the (rest of the) JNI. |
379 private static native String nativeGetVersionNumber(); | 397 private static native String nativeGetVersionNumber(); |
380 | 398 |
381 private static native void nativeRecordNativeLibraryHack(boolean usedHack); | 399 private static native void nativeRecordNativeLibraryHack(boolean usedHack); |
382 } | 400 } |
OLD | NEW |