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

Side by Side Diff: base/sys_info_android.cc

Issue 1498003003: Remove kint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: INT64_MAX Created 5 years 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 | « base/sys_info.cc ('k') | base/sys_info_chromeos.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <sys/system_properties.h> 8 #include <sys/system_properties.h>
9 9
10 #include "base/android/sys_utils.h" 10 #include "base/android/sys_utils.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // Default version of Android to fall back to when actual version numbers 58 // Default version of Android to fall back to when actual version numbers
59 // cannot be acquired. Use the latest Android release with a higher bug fix 59 // cannot be acquired. Use the latest Android release with a higher bug fix
60 // version to avoid unnecessarily comparison errors with the latest release. 60 // version to avoid unnecessarily comparison errors with the latest release.
61 // This should be manually kept up-to-date on each Android release. 61 // This should be manually kept up-to-date on each Android release.
62 const int kDefaultAndroidMajorVersion = 6; 62 const int kDefaultAndroidMajorVersion = 6;
63 const int kDefaultAndroidMinorVersion = 0; 63 const int kDefaultAndroidMinorVersion = 0;
64 const int kDefaultAndroidBugfixVersion = 99; 64 const int kDefaultAndroidBugfixVersion = 99;
65 65
66 // Parse out the OS version numbers from the system properties. 66 // Parse out the OS version numbers from the system properties.
67 void ParseOSVersionNumbers(const char* os_version_str, 67 void ParseOSVersionNumbers(const char* os_version_str,
68 int32 *major_version, 68 int32_t* major_version,
69 int32 *minor_version, 69 int32_t* minor_version,
70 int32 *bugfix_version) { 70 int32_t* bugfix_version) {
71 if (os_version_str[0]) { 71 if (os_version_str[0]) {
72 // Try to parse out the version numbers from the string. 72 // Try to parse out the version numbers from the string.
73 int num_read = sscanf(os_version_str, "%d.%d.%d", major_version, 73 int num_read = sscanf(os_version_str, "%d.%d.%d", major_version,
74 minor_version, bugfix_version); 74 minor_version, bugfix_version);
75 75
76 if (num_read > 0) { 76 if (num_read > 0) {
77 // If we don't have a full set of version numbers, make the extras 0. 77 // If we don't have a full set of version numbers, make the extras 0.
78 if (num_read < 2) *minor_version = 0; 78 if (num_read < 2) *minor_version = 0;
79 if (num_read < 3) *bugfix_version = 0; 79 if (num_read < 3) *bugfix_version = 0;
80 return; 80 return;
81 } 81 }
82 } 82 }
83 83
84 // For some reason, we couldn't parse the version number string. 84 // For some reason, we couldn't parse the version number string.
85 *major_version = kDefaultAndroidMajorVersion; 85 *major_version = kDefaultAndroidMajorVersion;
86 *minor_version = kDefaultAndroidMinorVersion; 86 *minor_version = kDefaultAndroidMinorVersion;
87 *bugfix_version = kDefaultAndroidBugfixVersion; 87 *bugfix_version = kDefaultAndroidBugfixVersion;
88 } 88 }
89 89
90 // Parses a system property (specified with unit 'k','m' or 'g'). 90 // Parses a system property (specified with unit 'k','m' or 'g').
91 // Returns a value in bytes. 91 // Returns a value in bytes.
92 // Returns -1 if the string could not be parsed. 92 // Returns -1 if the string could not be parsed.
93 int64 ParseSystemPropertyBytes(const base::StringPiece& str) { 93 int64_t ParseSystemPropertyBytes(const base::StringPiece& str) {
94 const int64 KB = 1024; 94 const int64_t KB = 1024;
95 const int64 MB = 1024 * KB; 95 const int64_t MB = 1024 * KB;
96 const int64 GB = 1024 * MB; 96 const int64_t GB = 1024 * MB;
97 if (str.size() == 0u) 97 if (str.size() == 0u)
98 return -1; 98 return -1;
99 int64 unit_multiplier = 1; 99 int64_t unit_multiplier = 1;
100 size_t length = str.size(); 100 size_t length = str.size();
101 if (str[length - 1] == 'k') { 101 if (str[length - 1] == 'k') {
102 unit_multiplier = KB; 102 unit_multiplier = KB;
103 length--; 103 length--;
104 } else if (str[length - 1] == 'm') { 104 } else if (str[length - 1] == 'm') {
105 unit_multiplier = MB; 105 unit_multiplier = MB;
106 length--; 106 length--;
107 } else if (str[length - 1] == 'g') { 107 } else if (str[length - 1] == 'g') {
108 unit_multiplier = GB; 108 unit_multiplier = GB;
109 length--; 109 length--;
110 } 110 }
111 int64 result = 0; 111 int64_t result = 0;
112 bool parsed = base::StringToInt64(str.substr(0, length), &result); 112 bool parsed = base::StringToInt64(str.substr(0, length), &result);
113 bool negative = result <= 0; 113 bool negative = result <= 0;
114 bool overflow = result >= std::numeric_limits<int64>::max() / unit_multiplier; 114 bool overflow =
115 result >= std::numeric_limits<int64_t>::max() / unit_multiplier;
115 if (!parsed || negative || overflow) 116 if (!parsed || negative || overflow)
116 return -1; 117 return -1;
117 return result * unit_multiplier; 118 return result * unit_multiplier;
118 } 119 }
119 120
120 int GetDalvikHeapSizeMB() { 121 int GetDalvikHeapSizeMB() {
121 char heap_size_str[PROP_VALUE_MAX]; 122 char heap_size_str[PROP_VALUE_MAX];
122 __system_property_get("dalvik.vm.heapsize", heap_size_str); 123 __system_property_get("dalvik.vm.heapsize", heap_size_str);
123 // dalvik.vm.heapsize property is writable by a root user. 124 // dalvik.vm.heapsize property is writable by a root user.
124 // Clamp it to reasonable range as a sanity check, 125 // Clamp it to reasonable range as a sanity check,
125 // a typical android device will never have less than 48MB. 126 // a typical android device will never have less than 48MB.
126 const int64 MB = 1024 * 1024; 127 const int64_t MB = 1024 * 1024;
127 int64 result = ParseSystemPropertyBytes(heap_size_str); 128 int64_t result = ParseSystemPropertyBytes(heap_size_str);
128 if (result == -1) { 129 if (result == -1) {
129 // We should consider not exposing these values if they are not reliable. 130 // We should consider not exposing these values if they are not reliable.
130 LOG(ERROR) << "Can't parse dalvik.vm.heapsize: " << heap_size_str; 131 LOG(ERROR) << "Can't parse dalvik.vm.heapsize: " << heap_size_str;
131 result = base::SysInfo::AmountOfPhysicalMemoryMB() / 3; 132 result = base::SysInfo::AmountOfPhysicalMemoryMB() / 3;
132 } 133 }
133 result = std::min<int64>(std::max<int64>(32 * MB, result), 1024 * MB) / MB; 134 result =
135 std::min<int64_t>(std::max<int64_t>(32 * MB, result), 1024 * MB) / MB;
134 return static_cast<int>(result); 136 return static_cast<int>(result);
135 } 137 }
136 138
137 int GetDalvikHeapGrowthLimitMB() { 139 int GetDalvikHeapGrowthLimitMB() {
138 char heap_size_str[PROP_VALUE_MAX]; 140 char heap_size_str[PROP_VALUE_MAX];
139 __system_property_get("dalvik.vm.heapgrowthlimit", heap_size_str); 141 __system_property_get("dalvik.vm.heapgrowthlimit", heap_size_str);
140 // dalvik.vm.heapgrowthlimit property is writable by a root user. 142 // dalvik.vm.heapgrowthlimit property is writable by a root user.
141 // Clamp it to reasonable range as a sanity check, 143 // Clamp it to reasonable range as a sanity check,
142 // a typical android device will never have less than 24MB. 144 // a typical android device will never have less than 24MB.
143 const int64 MB = 1024 * 1024; 145 const int64_t MB = 1024 * 1024;
144 int64 result = ParseSystemPropertyBytes(heap_size_str); 146 int64_t result = ParseSystemPropertyBytes(heap_size_str);
145 if (result == -1) { 147 if (result == -1) {
146 // We should consider not exposing these values if they are not reliable. 148 // We should consider not exposing these values if they are not reliable.
147 LOG(ERROR) << "Can't parse dalvik.vm.heapgrowthlimit: " << heap_size_str; 149 LOG(ERROR) << "Can't parse dalvik.vm.heapgrowthlimit: " << heap_size_str;
148 result = base::SysInfo::AmountOfPhysicalMemoryMB() / 6; 150 result = base::SysInfo::AmountOfPhysicalMemoryMB() / 6;
149 } 151 }
150 result = std::min<int64>(std::max<int64>(16 * MB, result), 512 * MB) / MB; 152 result = std::min<int64_t>(std::max<int64_t>(16 * MB, result), 512 * MB) / MB;
151 return static_cast<int>(result); 153 return static_cast<int>(result);
152 } 154 }
153 155
154 } // anonymous namespace 156 } // anonymous namespace
155 157
156 namespace base { 158 namespace base {
157 159
158 std::string SysInfo::HardwareModelName() { 160 std::string SysInfo::HardwareModelName() {
159 char device_model_str[PROP_VALUE_MAX]; 161 char device_model_str[PROP_VALUE_MAX];
160 __system_property_get("ro.product.model", device_model_str); 162 __system_property_get("ro.product.model", device_model_str);
161 return std::string(device_model_str); 163 return std::string(device_model_str);
162 } 164 }
163 165
164 std::string SysInfo::OperatingSystemName() { 166 std::string SysInfo::OperatingSystemName() {
165 return "Android"; 167 return "Android";
166 } 168 }
167 169
168 std::string SysInfo::OperatingSystemVersion() { 170 std::string SysInfo::OperatingSystemVersion() {
169 int32 major, minor, bugfix; 171 int32_t major, minor, bugfix;
170 OperatingSystemVersionNumbers(&major, &minor, &bugfix); 172 OperatingSystemVersionNumbers(&major, &minor, &bugfix);
171 return StringPrintf("%d.%d.%d", major, minor, bugfix); 173 return StringPrintf("%d.%d.%d", major, minor, bugfix);
172 } 174 }
173 175
174 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, 176 void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
175 int32* minor_version, 177 int32_t* minor_version,
176 int32* bugfix_version) { 178 int32_t* bugfix_version) {
177 // Read the version number string out from the properties. 179 // Read the version number string out from the properties.
178 char os_version_str[PROP_VALUE_MAX]; 180 char os_version_str[PROP_VALUE_MAX];
179 __system_property_get("ro.build.version.release", os_version_str); 181 __system_property_get("ro.build.version.release", os_version_str);
180 182
181 // Parse out the numbers. 183 // Parse out the numbers.
182 ParseOSVersionNumbers(os_version_str, major_version, minor_version, 184 ParseOSVersionNumbers(os_version_str, major_version, minor_version,
183 bugfix_version); 185 bugfix_version);
184 } 186 }
185 187
186 std::string SysInfo::GetAndroidBuildCodename() { 188 std::string SysInfo::GetAndroidBuildCodename() {
(...skipping 22 matching lines...) Expand all
209 base::internal::LazySysInfoValue<bool, 211 base::internal::LazySysInfoValue<bool,
210 android::SysUtils::IsLowEndDeviceFromJni> >::Leaky 212 android::SysUtils::IsLowEndDeviceFromJni> >::Leaky
211 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER; 213 g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;
212 214
213 bool SysInfo::IsLowEndDevice() { 215 bool SysInfo::IsLowEndDevice() {
214 return g_lazy_low_end_device.Get().value(); 216 return g_lazy_low_end_device.Get().value();
215 } 217 }
216 218
217 219
218 } // namespace base 220 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info.cc ('k') | base/sys_info_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698