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