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.os.Bundle; | 7 import android.os.Bundle; |
8 import android.os.Parcel; | 8 import android.os.Parcel; |
9 import android.os.ParcelFileDescriptor; | 9 import android.os.ParcelFileDescriptor; |
10 import android.os.Parcelable; | 10 import android.os.Parcelable; |
11 import android.util.Log; | 11 import android.util.Log; |
12 | 12 |
13 import org.chromium.base.AccessedByNative; | 13 import org.chromium.base.AccessedByNative; |
14 import org.chromium.base.CalledByNative; | 14 import org.chromium.base.CalledByNative; |
15 import org.chromium.base.SysUtils; | 15 import org.chromium.base.SysUtils; |
16 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
17 | 17 |
18 import java.io.FileNotFoundException; | 18 import java.io.FileNotFoundException; |
19 import java.util.Arrays; | |
19 import java.util.HashMap; | 20 import java.util.HashMap; |
21 import java.util.HashSet; | |
22 import java.util.List; | |
20 import java.util.Locale; | 23 import java.util.Locale; |
21 import java.util.Map; | 24 import java.util.Map; |
25 import java.util.Set; | |
22 | 26 |
23 import javax.annotation.Nullable; | 27 import javax.annotation.Nullable; |
24 | 28 |
25 /* | 29 /* |
26 * Technical note: | 30 * Technical note: |
27 * | 31 * |
28 * The point of this class is to provide an alternative to System.loadLibrary() | 32 * The point of this class is to provide an alternative to System.loadLibrary() |
29 * to load native shared libraries. One specific feature that it supports is the | 33 * to load native shared libraries. One specific feature that it supports is the |
30 * ability to save RAM by sharing the ELF RELRO sections between renderer | 34 * ability to save RAM by sharing the ELF RELRO sections between renderer |
31 * processes. | 35 * processes. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 // NORMAL -> This is not a low-memory device. | 187 // NORMAL -> This is not a low-memory device. |
184 public static final int MEMORY_DEVICE_CONFIG_INIT = 0; | 188 public static final int MEMORY_DEVICE_CONFIG_INIT = 0; |
185 public static final int MEMORY_DEVICE_CONFIG_LOW = 1; | 189 public static final int MEMORY_DEVICE_CONFIG_LOW = 1; |
186 public static final int MEMORY_DEVICE_CONFIG_NORMAL = 2; | 190 public static final int MEMORY_DEVICE_CONFIG_NORMAL = 2; |
187 | 191 |
188 // Indicates if this is a low-memory device or not. The default is to | 192 // Indicates if this is a low-memory device or not. The default is to |
189 // determine this by probing the system at runtime, but this can be forced | 193 // determine this by probing the system at runtime, but this can be forced |
190 // for testing by calling setMemoryDeviceConfig(). | 194 // for testing by calling setMemoryDeviceConfig(). |
191 private static int sMemoryDeviceConfig = MEMORY_DEVICE_CONFIG_INIT; | 195 private static int sMemoryDeviceConfig = MEMORY_DEVICE_CONFIG_INIT; |
192 | 196 |
197 // List of devices for which we suppress the test for support for mapping | |
198 // the APK file with executable permission. This test triggers a warning | |
199 // on some devices. Devices must be listed in all uppercase only, on the | |
200 // working assumption that no two distinct actual devices would have model | |
201 // strings that differ only in character case. | |
202 // | |
203 // For more, see: | |
204 // https://code.google.com/p/chromium/issues/detail?id=448084 | |
205 private static final String[] MAP_CHECK_BLACKLIST = { | |
206 "SCH-P709", "GT-I9158", "GT-I9152", "GT-I9150", "GT-I9200X", | |
207 "SGH-M819N", "SCH-R960", "SPH-L600", "SGH-I527M", "SGH-I527", | |
208 "SCH-P729", "SHV-E310L", "SHV-E310S", "SHV-E310K", "GT-I9208", | |
209 "GT-I9205", "GT-I9200"}; | |
210 | |
211 // The blacklist is only used if the OS version code indicates that it | |
212 // pre-dates an expiry version code. | |
213 private static final int MAP_CHECK_BLACKLIST_EXPIRY = | |
214 android.os.Build.VERSION_CODES.KITKAT; | |
Andrew Hayden (chromium.org)
2015/01/23 14:59:51
I don't think you can use this on ICS, right? How
simonb (inactive)
2015/01/23 16:03:19
Compile-time constants should be okay. From:
htt
| |
215 | |
216 // Lookup set, lazy-initialized from the MAP_CHECK_BLACKLIST array. | |
217 private static Set<String> sMapCheckBlacklist = null; | |
218 | |
193 // Becomes true after linker initialization. | 219 // Becomes true after linker initialization. |
194 private static boolean sInitialized = false; | 220 private static boolean sInitialized = false; |
195 | 221 |
196 // Set to true to indicate that the system supports safe sharing of RELRO se ctions. | 222 // Set to true to indicate that the system supports safe sharing of RELRO se ctions. |
197 private static boolean sRelroSharingSupported = false; | 223 private static boolean sRelroSharingSupported = false; |
198 | 224 |
199 // Set to true if this runs in the browser process. Disabled by initServiceP rocess(). | 225 // Set to true if this runs in the browser process. Disabled by initServiceP rocess(). |
200 // TODO(petrcermak): This flag can be incorrectly set to false (even though this might run in | 226 // TODO(petrcermak): This flag can be incorrectly set to false (even though this might run in |
201 // the browser process) on low-memory devices. | 227 // the browser process) on low-memory devices. |
202 private static boolean sInBrowserProcess = true; | 228 private static boolean sInBrowserProcess = true; |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 | 865 |
840 /** | 866 /** |
841 * Check whether the device supports mapping the APK file with executable pe rmission. | 867 * Check whether the device supports mapping the APK file with executable pe rmission. |
842 * | 868 * |
843 * @param apkFile Filename of the APK. | 869 * @param apkFile Filename of the APK. |
844 * @return true if supported. | 870 * @return true if supported. |
845 */ | 871 */ |
846 public static boolean checkMapExecSupport(String apkFile) { | 872 public static boolean checkMapExecSupport(String apkFile) { |
847 assert apkFile != null; | 873 assert apkFile != null; |
848 | 874 |
849 // https://code.google.com/p/chromium/issues/detail?id=448084 | 875 // If the android build version is before a known good release, check |
850 // Do not check if the device is Samsung Mega. | 876 // the blacklist for the build model. If the model is listed then |
877 // we skip the check for mmap exec support and return false. This avoids | |
878 // triggering a warning on these devices. The version check is included | |
879 // because these devices do not show the warning on later OS builds. | |
880 // | |
881 // Uses a case-insensitive lookup to ensure nothing is missed. No two | |
882 // devices will differ in model character case only. We ensure that the | |
883 // blacklist is populated with uppercased device names. | |
884 // | |
885 // For more, see: | |
886 // https://code.google.com/p/chromium/issues/detail?id=448084 | |
851 final String model = android.os.Build.MODEL; | 887 final String model = android.os.Build.MODEL; |
852 if (model != null && model.equals("GT-I9205")) { | 888 final int version = android.os.Build.VERSION.SDK_INT; |
853 if (DEBUG) Log.i(TAG, "checkMapExecSupport: model is '" + model | 889 |
854 + "', returning false"); | 890 if (model != null && version < MAP_CHECK_BLACKLIST_EXPIRY) { |
855 return false; | 891 synchronized (Linker.class) { |
892 // Initialize the blacklist lookup set before first use. | |
893 if (sMapCheckBlacklist == null) { | |
894 if (DEBUG) Log.i(TAG, "checkMapExecSupport: initializing bla cklist"); | |
895 final List<String> list = Arrays.asList(MAP_CHECK_BLACKLIST) ; | |
896 sMapCheckBlacklist = new HashSet<String>(list); | |
897 } | |
898 } | |
899 | |
900 // Search the blacklist for the model reported by the OS. | |
901 if (sMapCheckBlacklist.contains(model.toUpperCase())) { | |
902 if (DEBUG) Log.i(TAG, "checkMapExecSupport: " + model | |
903 + ": model is blacklisted, returning false"); | |
904 return false; | |
905 } | |
856 } | 906 } |
857 | 907 |
858 synchronized (Linker.class) { | 908 synchronized (Linker.class) { |
859 ensureInitializedLocked(); | 909 ensureInitializedLocked(); |
860 | 910 |
861 if (DEBUG) Log.i(TAG, "checkMapExecSupport: " + apkFile); | 911 if (DEBUG) Log.i(TAG, "checkMapExecSupport: " + apkFile); |
862 boolean supported = nativeCheckMapExecSupport(apkFile); | 912 boolean supported = nativeCheckMapExecSupport(apkFile); |
863 if (DEBUG) Log.i(TAG, "Mapping the APK file with executable permissi on " | 913 if (DEBUG) Log.i(TAG, "Mapping the APK file with executable permissi on " |
864 + (supported ? "" : "NOT ") + "supported"); | 914 + (supported ? "" : "NOT ") + "supported"); |
865 return supported; | 915 return supported; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 } | 1193 } |
1144 } | 1194 } |
1145 | 1195 |
1146 // The map of libraries that are currently loaded in this process. | 1196 // The map of libraries that are currently loaded in this process. |
1147 private static HashMap<String, LibInfo> sLoadedLibraries = null; | 1197 private static HashMap<String, LibInfo> sLoadedLibraries = null; |
1148 | 1198 |
1149 // Used to pass the shared RELRO Bundle through Binder. | 1199 // Used to pass the shared RELRO Bundle through Binder. |
1150 public static final String EXTRA_LINKER_SHARED_RELROS = | 1200 public static final String EXTRA_LINKER_SHARED_RELROS = |
1151 "org.chromium.base.android.linker.shared_relros"; | 1201 "org.chromium.base.android.linker.shared_relros"; |
1152 } | 1202 } |
OLD | NEW |