OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/client/core/settings/user_agent.h" | |
6 #include "base/macros.h" | |
7 #include "base/strings/stringprintf.h" | |
8 #include "base/sys_info.h" | |
9 | |
10 #if defined(OS_POSIX) && !defined(OS_ANDROID) | |
11 #include <sys/utsname.h> | |
12 #endif | |
13 | |
14 namespace blimp { | |
15 namespace client { | |
16 | |
17 /** | |
18 * Returns a string for building user agent such as : | |
19 * Linux; Android 5.1.1; Nexus 6 Build/LMY49C | |
20 */ | |
21 std::string GetOSVersionInfoForUserAgent() { | |
22 std::string os_cpu; | |
23 | |
24 #if defined(OS_ANDROID) | |
25 int32_t os_major_version = 0; | |
26 int32_t os_minor_version = 0; | |
27 int32_t os_bugfix_version = 0; | |
28 base::SysInfo::OperatingSystemVersionNumbers( | |
29 &os_major_version, &os_minor_version, &os_bugfix_version); | |
30 #endif | |
31 | |
32 #if defined(OS_POSIX) && !defined(OS_ANDROID) | |
33 // Should work on any Posix system. | |
34 struct utsname unixinfo; | |
35 uname(&unixinfo); | |
36 | |
37 std::string cputype; | |
38 // special case for biarch systems | |
39 if (strcmp(unixinfo.machine, "x86_64") == 0 && | |
40 sizeof(void*) == sizeof(int32_t)) { // NOLINT | |
41 cputype.assign("i686 (x86_64)"); | |
42 } else { | |
43 cputype.assign(unixinfo.machine); | |
44 } | |
45 #endif | |
46 | |
47 #if defined(OS_ANDROID) | |
48 std::string android_version_str; | |
49 base::StringAppendF(&android_version_str, "%d.%d", os_major_version, | |
50 os_minor_version); | |
51 if (os_bugfix_version != 0) | |
52 base::StringAppendF(&android_version_str, ".%d", os_bugfix_version); | |
53 | |
54 std::string android_info_str; | |
55 | |
56 // Send information about the device. | |
57 bool semicolon_inserted = false; | |
58 std::string android_build_codename = base::SysInfo::GetAndroidBuildCodename(); | |
59 std::string android_device_name = base::SysInfo::HardwareModelName(); | |
60 if ("REL" == android_build_codename && android_device_name.size() > 0) { | |
61 android_info_str += "; " + android_device_name; | |
62 semicolon_inserted = true; | |
63 } | |
64 | |
65 // Append the build ID. | |
66 std::string android_build_id = base::SysInfo::GetAndroidBuildID(); | |
67 if (android_build_id.size() > 0) { | |
68 if (!semicolon_inserted) { | |
69 android_info_str += ";"; | |
70 } | |
71 android_info_str += " Build/" + android_build_id; | |
72 } | |
73 #endif | |
74 | |
75 base::StringAppendF(&os_cpu, | |
76 #if defined(OS_ANDROID) | |
77 "Android %s%s", android_version_str.c_str(), | |
78 android_info_str.c_str() | |
79 #else | |
80 "%s %s", | |
81 unixinfo.sysname, // e.g. Linux | |
82 cputype.c_str() // e.g. i686 | |
83 #endif | |
84 ); // NOLINT | |
85 | |
86 os_cpu = "Linux; " + os_cpu; | |
87 | |
88 return os_cpu; | |
89 } | |
90 | |
91 } // namespace client | |
92 } // namespace blimp | |
OLD | NEW |