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

Side by Side Diff: base/sys_info_android.cc

Issue 10832235: Move Android user agent generation to native code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed unnecessary include Created 8 years, 4 months 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.h ('k') | content/app/android/app_jni_registrar.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 <sys/system_properties.h> 7 #include <sys/system_properties.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_piece.h" 11 #include "base/string_piece.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Default version of Android to fall back to when actual version numbers
16 // cannot be acquired.
17 // TODO(dfalcantara): Keep this reasonably up to date with the latest publicly
18 // available version of Android.
19 static const int kDefaultAndroidMajorVersion = 4;
20 static const int kDefaultAndroidMinorVersion = 0;
21 static const int kDefaultAndroidBugfixVersion = 3;
22
23 // Parse out the OS version numbers from the system properties.
24 void ParseOSVersionNumbers(const char* os_version_str,
25 int32 *major_version,
26 int32 *minor_version,
27 int32 *bugfix_version) {
28 if (strlen(os_version_str) > 0) {
willchan no longer on Chromium 2012/08/20 23:07:42 How about: if (os_version_str[0])? No need to wast
gone 2012/08/21 18:46:46 This change got lost in my last shuffle. Fixed.
29 // Try to parse out the version numbers from the string.
30 int num_read = sscanf(os_version_str, "%d.%d.%d", major_version,
31 minor_version, bugfix_version);
32
33 if (num_read > 0) {
34 // If we don't have a full set of version numbers, make the extras 0.
35 if (num_read < 2) *minor_version = 0;
36 if (num_read < 3) *bugfix_version = 0;
37 return;
38 }
39 }
40
41 // For some reason, we couldn't parse the version number string.
42 *major_version = kDefaultAndroidMajorVersion;
43 *minor_version = kDefaultAndroidMinorVersion;
44 *bugfix_version = kDefaultAndroidBugfixVersion;
45 }
46
15 int ParseHeapSize(const base::StringPiece& str) { 47 int ParseHeapSize(const base::StringPiece& str) {
16 const int64 KB = 1024; 48 const int64 KB = 1024;
17 const int64 MB = 1024 * KB; 49 const int64 MB = 1024 * KB;
18 const int64 GB = 1024 * MB; 50 const int64 GB = 1024 * MB;
19 CHECK_GT(str.size(), 0u); 51 CHECK_GT(str.size(), 0u);
20 int64 factor = 1; 52 int64 factor = 1;
21 size_t length = str.size(); 53 size_t length = str.size();
22 if (str[length - 1] == 'k') { 54 if (str[length - 1] == 'k') {
23 factor = KB; 55 factor = KB;
24 length--; 56 length--;
(...skipping 19 matching lines...) Expand all
44 int GetDalvikHeapSizeMB() { 76 int GetDalvikHeapSizeMB() {
45 char heap_size_str[PROP_VALUE_MAX]; 77 char heap_size_str[PROP_VALUE_MAX];
46 __system_property_get("dalvik.vm.heapsize", heap_size_str); 78 __system_property_get("dalvik.vm.heapsize", heap_size_str);
47 return ParseHeapSize(heap_size_str); 79 return ParseHeapSize(heap_size_str);
48 } 80 }
49 81
50 } // anonymous namespace 82 } // anonymous namespace
51 83
52 namespace base { 84 namespace base {
53 85
86 std::string SysInfo::GetAndroidBuildCodename() {
87 char os_version_codename_str[PROP_VALUE_MAX];
Yaron 2012/08/20 23:13:10 Would be good to reconcile these with build/androi
gone 2012/08/21 18:46:46 Yeah, need to figure out if the strings are access
88 __system_property_get("ro.build.version.codename", os_version_codename_str);
89 return std::string(os_version_codename_str);
90 }
91
92 std::string SysInfo::GetAndroidBuildID() {
93 char os_build_id_str[PROP_VALUE_MAX];
94 __system_property_get("ro.build.id", os_build_id_str);
95 return std::string(os_build_id_str);
96 }
97
98 std::string SysInfo::GetDeviceName() {
99 char device_model_str[PROP_VALUE_MAX];
100 __system_property_get("ro.product.model", device_model_str);
101 return std::string(device_model_str);
102 }
103
104 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
105 int32* minor_version,
106 int32* bugfix_version) {
107 // Read the version number string out from the properties.
108 char os_version_str[PROP_VALUE_MAX];
109 __system_property_get("ro.build.version.release", os_version_str);
110
111 // Parse out the numbers.
112 ParseOSVersionNumbers(os_version_str, major_version, minor_version,
113 bugfix_version);
114 }
115
54 int SysInfo::DalvikHeapSizeMB() { 116 int SysInfo::DalvikHeapSizeMB() {
55 static int heap_size = GetDalvikHeapSizeMB(); 117 static int heap_size = GetDalvikHeapSizeMB();
56 return heap_size; 118 return heap_size;
57 } 119 }
58 120
59 } // namespace base 121 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info.h ('k') | content/app/android/app_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698