Commit cb83aaf9 authored by Julian Pastarmov's avatar Julian Pastarmov Committed by Commit Bot

[SC] Fix the linux version identification to follow the native host

The code used to read the version string as provided by the uname
command but the native host reads the string from the /etc/os-release
file. This CL unifies the API implementation with the native host but
preserves the uname approach as a fallback in case the file is not
present or does not follow the expected format.

BUG=1114196
TEST=unit_tests:EnterpriseReportingPrivateGetDeviceInfoTest.GetDeviceInfo

Change-Id: Ie07314ef4cdbdbbbc8b1abf0784b8e54d454217a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339631Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Commit-Queue: Julian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795990}
parent ea802f5d
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/nix/xdg_util.h" #include "base/nix/xdg_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
...@@ -35,6 +36,20 @@ std::string GetDeviceModel() { ...@@ -35,6 +36,20 @@ std::string GetDeviceModel() {
} }
std::string GetOsVersion() { std::string GetOsVersion() {
base::FilePath os_release_file("/etc/os-release");
std::string release_info;
base::StringPairs values;
if (base::PathExists(os_release_file) &&
base::ReadFileToStringWithMaxSize(os_release_file, &release_info, 8192) &&
base::SplitStringIntoKeyValuePairs(release_info, '=', '\n', &values)) {
auto version_id = std::find_if(values.begin(), values.end(), [](auto v) {
return v.first == "VERSION_ID";
});
if (version_id != values.end()) {
return base::TrimString(version_id->second, "\"", base::TRIM_ALL)
.as_string();
}
}
return base::SysInfo::OperatingSystemVersion(); return base::SysInfo::OperatingSystemVersion();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment