diff --git a/metricsd/Android.mk b/metricsd/Android.mk index 9fd8edaa2..89fa222d1 100644 --- a/metricsd/Android.mk +++ b/metricsd/Android.mk @@ -110,6 +110,7 @@ LOCAL_SHARED_LIBRARIES := $(metrics_shared_libraries) \ libprotobuf-cpp-lite \ libchromeos-http \ libchromeos-dbus \ + libcutils \ libdbus LOCAL_SRC_FILES := $(metrics_daemon_sources) LOCAL_STATIC_LIBRARIES := metrics_daemon_protos diff --git a/metricsd/constants.h b/metricsd/constants.h index 56dac0db2..15c15d90d 100644 --- a/metricsd/constants.h +++ b/metricsd/constants.h @@ -24,6 +24,11 @@ static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsServer[] = "https://clients4.google.com/uma/v2"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; static const char kDefaultVersion[] = "0.0.0.0"; + +// System properties used. +static const char kBuildTargetIdProperty[] = "ro.product.build_target_id"; +static const char kChannelProperty[] = "ro.product.channel"; +static const char kProductVersionProperty[] = "ro.product.version"; } // namespace metrics #endif // METRICS_CONSTANTS_H_ diff --git a/metricsd/metrics_daemon.cc b/metricsd/metrics_daemon.cc index 069f68e25..5855cee5d 100644 --- a/metricsd/metrics_daemon.cc +++ b/metricsd/metrics_daemon.cc @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -209,10 +209,13 @@ uint32_t MetricsDaemon::GetOsVersionHash() { if (version_hash_is_cached) return cached_version_hash; version_hash_is_cached = true; - std::string version = metrics::kDefaultVersion; + + char version[PROPERTY_VALUE_MAX]; // The version might not be set for development devices. In this case, use the // zero version. - base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version); + property_get(metrics::kProductVersionProperty, version, + metrics::kDefaultVersion); + cached_version_hash = base::Hash(version); if (testing_) { cached_version_hash = 42; // return any plausible value for the hash diff --git a/metricsd/uploader/system_profile_cache.cc b/metricsd/uploader/system_profile_cache.cc index 7dd0323a7..21ec22902 100644 --- a/metricsd/uploader/system_profile_cache.cc +++ b/metricsd/uploader/system_profile_cache.cc @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -73,21 +73,28 @@ bool SystemProfileCache::Initialize() { CHECK(!initialized_) << "this should be called only once in the metrics_daemon lifetime."; - if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", - &profile_.build_target_id)) { - LOG(ERROR) << "BRILLO_BUILD_TARGET_ID is not set in /etc/lsb-release."; + char property_value[PROPERTY_VALUE_MAX]; + property_get(metrics::kBuildTargetIdProperty, property_value, ""); + profile_.build_target_id = std::string(property_value); + + if (profile_.build_target_id.empty()) { + LOG(ERROR) << "System property " << metrics::kBuildTargetIdProperty + << " is not set."; return false; } - std::string channel; - if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || - !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version)) { + property_get(metrics::kChannelProperty, property_value, ""); + std::string channel(property_value); + + property_get(metrics::kProductVersionProperty, property_value, ""); + profile_.version = std::string(property_value); + + if (channel.empty() || profile_.version.empty()) { // If the channel or version is missing, the image is not official. // In this case, set the channel to unknown and the version to 0.0.0.0 to // avoid polluting the production data. channel = ""; profile_.version = metrics::kDefaultVersion; - } profile_.client_id = testing_ ? "client_id_test" :