Chromium Code Reviews| Index: base/sys_info_android.cc |
| diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc |
| index c288ae2fe87f7ce3e68edb513bd2c5c45849ef83..fd158e3b4d776c2cd6dd8f0228d8454877faf356 100644 |
| --- a/base/sys_info_android.cc |
| +++ b/base/sys_info_android.cc |
| @@ -4,55 +4,13 @@ |
| #include "base/sys_info.h" |
| -#include <dlfcn.h> |
| -#include <sys/system_properties.h> |
| - |
| +#include "base/android/build_info.h" |
| #include "base/android/sys_utils.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| -#include "base/strings/string_piece.h" |
| -#include "base/strings/stringprintf.h" |
| #include "base/sys_info_internal.h" |
| -#if (__ANDROID_API__ >= 21 /* 5.0 - Lollipop */) |
| - |
| -namespace { |
| - |
| -typedef int (SystemPropertyGetFunction)(const char*, char*); |
| - |
| -SystemPropertyGetFunction* DynamicallyLoadRealSystemPropertyGet() { |
| - // libc.so should already be open, get a handle to it. |
| - void* handle = dlopen("libc.so", RTLD_NOLOAD); |
| - if (!handle) { |
| - LOG(FATAL) << "Cannot dlopen libc.so: " << dlerror(); |
| - } |
| - SystemPropertyGetFunction* real_system_property_get = |
| - reinterpret_cast<SystemPropertyGetFunction*>( |
| - dlsym(handle, "__system_property_get")); |
| - if (!real_system_property_get) { |
| - LOG(FATAL) << "Cannot resolve __system_property_get(): " << dlerror(); |
| - } |
| - return real_system_property_get; |
| -} |
| - |
| -static base::LazyInstance<base::internal::LazySysInfoValue< |
| - SystemPropertyGetFunction*, DynamicallyLoadRealSystemPropertyGet> >::Leaky |
| - g_lazy_real_system_property_get = LAZY_INSTANCE_INITIALIZER; |
| - |
| -} // namespace |
| - |
| -// Android 'L' removes __system_property_get from the NDK, however it is still |
| -// a hidden symbol in libc. Until we remove all calls of __system_property_get |
| -// from Chrome we work around this by defining a weak stub here, which uses |
| -// dlsym to but ensures that Chrome uses the real system |
| -// implementatation when loaded. http://crbug.com/392191. |
| -BASE_EXPORT int __system_property_get(const char* name, char* value) { |
| - return g_lazy_real_system_property_get.Get().value()(name, value); |
| -} |
| - |
| -#endif |
| - |
| namespace { |
| // Default version of Android to fall back to when actual version numbers |
| @@ -87,68 +45,16 @@ void ParseOSVersionNumbers(const char* os_version_str, |
| *bugfix_version = kDefaultAndroidBugfixVersion; |
| } |
| -// Parses a system property (specified with unit 'k','m' or 'g'). |
| -// Returns a value in bytes. |
| -// Returns -1 if the string could not be parsed. |
| -int64 ParseSystemPropertyBytes(const base::StringPiece& str) { |
| - const int64 KB = 1024; |
| - const int64 MB = 1024 * KB; |
| - const int64 GB = 1024 * MB; |
| - if (str.size() == 0u) |
| - return -1; |
| - int64 unit_multiplier = 1; |
| - size_t length = str.size(); |
| - if (str[length - 1] == 'k') { |
| - unit_multiplier = KB; |
| - length--; |
| - } else if (str[length - 1] == 'm') { |
| - unit_multiplier = MB; |
| - length--; |
| - } else if (str[length - 1] == 'g') { |
| - unit_multiplier = GB; |
| - length--; |
| - } |
| - int64 result = 0; |
| - bool parsed = base::StringToInt64(str.substr(0, length), &result); |
| - bool negative = result <= 0; |
| - bool overflow = result >= std::numeric_limits<int64>::max() / unit_multiplier; |
| - if (!parsed || negative || overflow) |
| - return -1; |
| - return result * unit_multiplier; |
| -} |
| - |
| int GetDalvikHeapSizeMB() { |
| - char heap_size_str[PROP_VALUE_MAX]; |
| - __system_property_get("dalvik.vm.heapsize", heap_size_str); |
| - // dalvik.vm.heapsize property is writable by a root user. |
| - // Clamp it to reasonable range as a sanity check, |
| - // a typical android device will never have less than 48MB. |
| - const int64 MB = 1024 * 1024; |
| - int64 result = ParseSystemPropertyBytes(heap_size_str); |
| + // See developer.android.com/reference/android/app/ActivityManager.html for |
| + // how "large memory class" relates to the Dalvik heap size. |
| + int result = base::android::BuildInfo::GetInstance()->large_memory_class(); |
| if (result == -1) { |
| // We should consider not exposing these values if they are not reliable. |
| - LOG(ERROR) << "Can't parse dalvik.vm.heapsize: " << heap_size_str; |
| + LOG(ERROR) << "Invalid large memory class: " << result; |
|
Lei Zhang
2015/08/05 00:28:24
nit: outputting |result| isn't helpful. We already
jdduke (slow)
2015/08/05 15:32:09
Done.
|
| result = base::SysInfo::AmountOfPhysicalMemoryMB() / 3; |
| } |
| - result = std::min<int64>(std::max<int64>(32 * MB, result), 1024 * MB) / MB; |
| - return static_cast<int>(result); |
| -} |
| - |
| -int GetDalvikHeapGrowthLimitMB() { |
| - char heap_size_str[PROP_VALUE_MAX]; |
| - __system_property_get("dalvik.vm.heapgrowthlimit", heap_size_str); |
| - // dalvik.vm.heapgrowthlimit property is writable by a root user. |
| - // Clamp it to reasonable range as a sanity check, |
| - // a typical android device will never have less than 24MB. |
| - const int64 MB = 1024 * 1024; |
| - int64 result = ParseSystemPropertyBytes(heap_size_str); |
| - if (result == -1) { |
| - // We should consider not exposing these values if they are not reliable. |
| - LOG(ERROR) << "Can't parse dalvik.vm.heapgrowthlimit: " << heap_size_str; |
| - result = base::SysInfo::AmountOfPhysicalMemoryMB() / 6; |
| - } |
| - result = std::min<int64>(std::max<int64>(16 * MB, result), 512 * MB) / MB; |
| - return static_cast<int>(result); |
| + return std::min(std::max(32, result), 1024); |
| } |
| } // anonymous namespace |
| @@ -156,9 +62,7 @@ int GetDalvikHeapGrowthLimitMB() { |
| namespace base { |
| std::string SysInfo::HardwareModelName() { |
| - char device_model_str[PROP_VALUE_MAX]; |
| - __system_property_get("ro.product.model", device_model_str); |
| - return std::string(device_model_str); |
| + return android::BuildInfo::GetInstance()->model(); |
| } |
| std::string SysInfo::OperatingSystemName() { |
| @@ -166,17 +70,14 @@ std::string SysInfo::OperatingSystemName() { |
| } |
| std::string SysInfo::OperatingSystemVersion() { |
| - int32 major, minor, bugfix; |
| - OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| - return StringPrintf("%d.%d.%d", major, minor, bugfix); |
| + return android::BuildInfo::GetInstance()->build_version_release(); |
| } |
| void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
| int32* minor_version, |
| int32* bugfix_version) { |
| - // Read the version number string out from the properties. |
| - char os_version_str[PROP_VALUE_MAX]; |
| - __system_property_get("ro.build.version.release", os_version_str); |
| + const char* os_version_str = |
| + android::BuildInfo::GetInstance()->build_version_release(); |
| // Parse out the numbers. |
| ParseOSVersionNumbers(os_version_str, major_version, minor_version, |
| @@ -184,15 +85,11 @@ void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
| } |
| std::string SysInfo::GetAndroidBuildCodename() { |
| - char os_version_codename_str[PROP_VALUE_MAX]; |
| - __system_property_get("ro.build.version.codename", os_version_codename_str); |
| - return std::string(os_version_codename_str); |
| + return android::BuildInfo::GetInstance()->build_version_codename(); |
| } |
| std::string SysInfo::GetAndroidBuildID() { |
| - char os_build_id_str[PROP_VALUE_MAX]; |
| - __system_property_get("ro.build.id", os_build_id_str); |
| - return std::string(os_build_id_str); |
| + return android::BuildInfo::GetInstance()->build_id(); |
| } |
| int SysInfo::DalvikHeapSizeMB() { |
| @@ -200,11 +97,6 @@ int SysInfo::DalvikHeapSizeMB() { |
| return heap_size; |
| } |
| -int SysInfo::DalvikHeapGrowthLimitMB() { |
| - static int heap_growth_limit = GetDalvikHeapGrowthLimitMB(); |
| - return heap_growth_limit; |
| -} |
| - |
| static base::LazyInstance< |
| base::internal::LazySysInfoValue<bool, |
| android::SysUtils::IsLowEndDeviceFromJni> >::Leaky |