Commit 21364214 authored by Rakesh Soma's avatar Rakesh Soma Committed by Commit Bot

Collect and forward OS version to UploadDeviceDetails RPC.

Change-Id: Ib1a6fe5130e16718252af1c92db3d5987261b729
Bug: 1070045
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146210
Commit-Queue: Rakesh Soma <rakeshsoma@google.com>
Reviewed-by: default avatarYusuf Sengul <yusufsn@google.com>
Cr-Commit-Position: refs/heads/master@{#758463}
parent d1a2b1e8
......@@ -2718,7 +2718,8 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) {
std::vector<std::string> mac_addresses;
mac_addresses.push_back("mac_address_1");
mac_addresses.push_back("mac_address_2");
GemDeviceDetailsForTesting g_mac_addresses(mac_addresses);
std::string os_version = "10.1.17134";
GemDeviceDetailsForTesting g_device_details(mac_addresses, os_version);
// Create a fake user associated to a gaia id.
CComBSTR sid;
......@@ -2795,6 +2796,8 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) {
ASSERT_NE(nullptr, request_dict.FindStringKey("user_sid"));
ASSERT_EQ(*request_dict.FindStringKey("user_sid"),
base::UTF16ToUTF8((BSTR)sid));
ASSERT_NE(nullptr, request_dict.FindStringKey("os_edition"));
ASSERT_EQ(*request_dict.FindStringKey("os_edition"), os_version);
ASSERT_TRUE(request_dict.FindBoolKey("is_ad_joined_user").has_value());
ASSERT_EQ(request_dict.FindBoolKey("is_ad_joined_user").value(), true);
ASSERT_TRUE(request_dict.FindKey("wlan_mac_addr")->is_list());
......
......@@ -70,10 +70,17 @@ base::string16 g_test_serial_number = L"";
bool g_use_test_mac_addresses = false;
std::vector<std::string> g_test_mac_addresses;
// Overriden in tests to fake os version.
bool g_use_test_os_version = false;
std::string g_test_os_version = "";
// Overridden in tests to fake installed chrome path.
bool g_use_test_chrome_path = false;
base::FilePath g_test_chrome_path(L"");
const wchar_t kKernelLibFile[] = L"kernel32.dll";
const int kVersionStringSize = 128;
namespace {
// Minimum supported version of Chrome for GCPW.
......@@ -182,13 +189,17 @@ GoogleRegistrationDataForTesting::~GoogleRegistrationDataForTesting() {
// GemDeviceDetailsForTesting //////////////////////////////////////////
GemDeviceDetailsForTesting::GemDeviceDetailsForTesting(
std::vector<std::string>& mac_addresses) {
std::vector<std::string>& mac_addresses,
std::string os_version) {
g_use_test_mac_addresses = true;
g_use_test_os_version = true;
g_test_mac_addresses = mac_addresses;
g_test_os_version = os_version;
}
GemDeviceDetailsForTesting::~GemDeviceDetailsForTesting() {
g_use_test_mac_addresses = false;
g_use_test_os_version = false;
}
// GemDeviceDetailsForTesting //////////////////////////////////////////
......@@ -987,6 +998,36 @@ std::vector<std::string> GetMacAddresses() {
return mac_addresses;
}
// The current solution is based on the version of the "kernel32.dll" file. A
// cleaner alternative would be to use the GetVersionEx API. However, since
// Windows 8.1 the values returned by that API are dependent on how
// the application is manifested, and might not be the actual OS version.
void GetOsVersion(std::string* version) {
if (g_use_test_os_version) {
*version = g_test_os_version;
return;
}
int buffer_size = GetFileVersionInfoSize(kKernelLibFile, nullptr);
if (buffer_size) {
std::vector<wchar_t> buffer(buffer_size, 0);
if (GetFileVersionInfo(kKernelLibFile, 0, buffer_size, buffer.data())) {
UINT size;
void* fixed_version_info_raw;
if (VerQueryValue(buffer.data(), L"\\", &fixed_version_info_raw, &size)) {
VS_FIXEDFILEINFO* fixed_version_info =
static_cast<VS_FIXEDFILEINFO*>(fixed_version_info_raw);
int major = HIWORD(fixed_version_info->dwFileVersionMS);
int minor = LOWORD(fixed_version_info->dwFileVersionMS);
int build = HIWORD(fixed_version_info->dwFileVersionLS);
char version_buffer[kVersionStringSize];
snprintf(version_buffer, kVersionStringSize, "%d.%d.%d", major, minor,
build);
*version = version_buffer;
}
}
}
}
HRESULT GenerateDeviceId(std::string* device_id) {
// Build the json data encapsulating different device ids.
base::Value device_ids_dict(base::Value::Type::DICTIONARY);
......
......@@ -95,7 +95,8 @@ class GoogleRegistrationDataForTesting {
// Class used in tests to set gem device details for testing.
class GemDeviceDetailsForTesting {
public:
explicit GemDeviceDetailsForTesting(std::vector<std::string>& mac_addresses);
explicit GemDeviceDetailsForTesting(std::vector<std::string>& mac_addresses,
std::string os_version);
~GemDeviceDetailsForTesting();
};
......@@ -343,6 +344,10 @@ base::string16 GetSerialNumber();
// Gets the mac addresses of the windows device.
std::vector<std::string> GetMacAddresses();
// Gets the OS version installed on the device. The format is
// "major.minor.build".
void GetOsVersion(std::string* version);
// Gets the obfuscated device_id that is a combination of multiple device
// identifiers.
HRESULT GenerateDeviceId(std::string* device_id);
......
......@@ -49,6 +49,7 @@ const char kIsAdJoinedUserParameterName[] = "is_ad_joined_user";
const char kMacAddressParameterName[] = "wlan_mac_addr";
const char kUploadDeviceDetailsResponseDeviceResourceIdParameterName[] =
"deviceResourceId";
const char kOsVersion[] = "os_edition";
// Maximum number of retries if a HTTP call to the backend fails.
constexpr unsigned int kMaxNumHttpRetries = 3;
......@@ -96,6 +97,11 @@ HRESULT GemDeviceDetailsManager::UploadDeviceDetails(
return hr;
}
std::vector<std::string> mac_addresses = GetMacAddresses();
// Get OS version of the windows device.
std::string version;
GetOsVersion(&version);
base::Value mac_address_value_list(base::Value::Type::LIST);
for (const std::string& mac_address : mac_addresses)
mac_address_value_list.Append(base::Value(mac_address));
......@@ -117,6 +123,7 @@ HRESULT GemDeviceDetailsManager::UploadDeviceDetails(
OSUserManager::Get()->IsUserDomainJoined(sid));
request_dict_->SetKey(kMacAddressParameterName,
std::move(mac_address_value_list));
request_dict_->SetStringKey(kOsVersion, version);
base::string16 known_resource_id = GetUserDeviceResourceId(sid);
if (!known_resource_id.empty()) {
......
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