Loading metricsd/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -69,11 +69,11 @@ metrics_daemon_shared_libraries := $(libmetrics_shared_libraries) \ libchrome-dbus \ libchromeos-http \ libchromeos-dbus \ libcutils \ libdbus \ libmetrics \ libprotobuf-cpp-lite \ librootdev \ libupdate_engine_client \ libweaved \ # Shared library for metrics. Loading metricsd/constants.h +3 −4 Original line number Diff line number Diff line Loading @@ -27,10 +27,9 @@ static const char kStagedLogName[] = "staged_log"; static const char kFailedUploadCountName[] = "failed_upload_count"; static const char kDefaultVersion[] = "0.0.0.0"; // System properties used. static const char kProductIdProperty[] = "ro.product.product_id"; static const char kChannelProperty[] = "ro.product.channel"; static const char kProductVersionProperty[] = "ro.product.version"; // Build time properties name. static const char kProductId[] = "product_id"; static const char kProductVersion[] = "product_version"; } // namespace metrics #endif // METRICS_CONSTANTS_H_ metricsd/metrics_daemon.cc +12 −16 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ #include <base/strings/string_split.h> #include <base/strings/string_util.h> #include <base/strings/stringprintf.h> #include <cutils/properties.h> #include <brillo/osrelease_reader.h> #include <dbus/dbus.h> #include <dbus/message.h> Loading Loading @@ -153,23 +153,19 @@ void MetricsDaemon::RunUploaderTest() { } uint32_t MetricsDaemon::GetOsVersionHash() { static uint32_t cached_version_hash = 0; static bool version_hash_is_cached = false; if (version_hash_is_cached) return cached_version_hash; version_hash_is_cached = true; char version[PROPERTY_VALUE_MAX]; // The version might not be set for development devices. In this case, use the // zero version. property_get(metrics::kProductVersionProperty, version, metrics::kDefaultVersion); cached_version_hash = base::Hash(version); brillo::OsReleaseReader reader; reader.Load(); string version; if (!reader.GetString(metrics::kProductVersion, &version)) { LOG(ERROR) << "failed to read the product version."; version = metrics::kDefaultVersion; } uint32_t version_hash = base::Hash(version); if (testing_) { cached_version_hash = 42; // return any plausible value for the hash version_hash = 42; // return any plausible value for the hash } return cached_version_hash; return version_hash; } void MetricsDaemon::Init(bool testing, Loading metricsd/uploader/system_profile_cache.cc +19 −19 Original line number Diff line number Diff line Loading @@ -21,8 +21,9 @@ #include <base/logging.h> #include <base/strings/string_number_conversions.h> #include <base/strings/string_util.h> #include <cutils/properties.h> #include <brillo/osrelease_reader.h> #include <string> #include <update_engine/client.h> #include <vector> #include "constants.h" Loading Loading @@ -73,16 +74,27 @@ bool SystemProfileCache::Initialize() { CHECK(!initialized_) << "this should be called only once in the metrics_daemon lifetime."; profile_.product_id = GetProperty(metrics::kProductIdProperty); brillo::OsReleaseReader reader; std::string channel; if (testing_) { reader.LoadTestingOnly(metrics_directory_); channel = "unknown"; } else { reader.Load(); auto client = update_engine::UpdateEngineClient::CreateInstance(); if (!client->GetChannel(&channel)) { LOG(ERROR) << "failed to read the current channel from update engine."; } } if (profile_.product_id.empty()) { LOG(ERROR) << "System property " << metrics::kProductIdProperty << " is not set."; if (!reader.GetString(metrics::kProductId, &profile_.product_id)) { LOG(ERROR) << "product_id is not set."; return false; } std::string channel = GetProperty(metrics::kChannelProperty); profile_.version = GetProperty(metrics::kProductVersionProperty); if (!reader.GetString(metrics::kProductVersion, &profile_.version)) { LOG(ERROR) << "failed to read the product version"; } if (channel.empty() || profile_.version.empty()) { // If the channel or version is missing, the image is not official. Loading Loading @@ -154,18 +166,6 @@ std::string SystemProfileCache::GetPersistentGUID( return guid; } std::string SystemProfileCache::GetProperty(const std::string& name) { if (testing_) { std::string content; base::ReadFileToString(metrics_directory_.Append(name), &content); return content; } else { char value[PROPERTY_VALUE_MAX]; property_get(name.data(), value, ""); return std::string(value); } } metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString( const std::string& channel) { if (channel == "stable") { Loading metricsd/uploader/system_profile_cache.h +0 −5 Original line number Diff line number Diff line Loading @@ -76,11 +76,6 @@ class SystemProfileCache : public SystemProfileSetter { // Initializes |profile_| only if it has not been yet initialized. bool InitializeOrCheck(); // Gets a system property as a string. // When |testing_| is true, reads the value from |metrics_directory_|/|name| // instead. std::string GetProperty(const std::string& name); bool initialized_; bool testing_; base::FilePath metrics_directory_; Loading Loading
metricsd/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -69,11 +69,11 @@ metrics_daemon_shared_libraries := $(libmetrics_shared_libraries) \ libchrome-dbus \ libchromeos-http \ libchromeos-dbus \ libcutils \ libdbus \ libmetrics \ libprotobuf-cpp-lite \ librootdev \ libupdate_engine_client \ libweaved \ # Shared library for metrics. Loading
metricsd/constants.h +3 −4 Original line number Diff line number Diff line Loading @@ -27,10 +27,9 @@ static const char kStagedLogName[] = "staged_log"; static const char kFailedUploadCountName[] = "failed_upload_count"; static const char kDefaultVersion[] = "0.0.0.0"; // System properties used. static const char kProductIdProperty[] = "ro.product.product_id"; static const char kChannelProperty[] = "ro.product.channel"; static const char kProductVersionProperty[] = "ro.product.version"; // Build time properties name. static const char kProductId[] = "product_id"; static const char kProductVersion[] = "product_version"; } // namespace metrics #endif // METRICS_CONSTANTS_H_
metricsd/metrics_daemon.cc +12 −16 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ #include <base/strings/string_split.h> #include <base/strings/string_util.h> #include <base/strings/stringprintf.h> #include <cutils/properties.h> #include <brillo/osrelease_reader.h> #include <dbus/dbus.h> #include <dbus/message.h> Loading Loading @@ -153,23 +153,19 @@ void MetricsDaemon::RunUploaderTest() { } uint32_t MetricsDaemon::GetOsVersionHash() { static uint32_t cached_version_hash = 0; static bool version_hash_is_cached = false; if (version_hash_is_cached) return cached_version_hash; version_hash_is_cached = true; char version[PROPERTY_VALUE_MAX]; // The version might not be set for development devices. In this case, use the // zero version. property_get(metrics::kProductVersionProperty, version, metrics::kDefaultVersion); cached_version_hash = base::Hash(version); brillo::OsReleaseReader reader; reader.Load(); string version; if (!reader.GetString(metrics::kProductVersion, &version)) { LOG(ERROR) << "failed to read the product version."; version = metrics::kDefaultVersion; } uint32_t version_hash = base::Hash(version); if (testing_) { cached_version_hash = 42; // return any plausible value for the hash version_hash = 42; // return any plausible value for the hash } return cached_version_hash; return version_hash; } void MetricsDaemon::Init(bool testing, Loading
metricsd/uploader/system_profile_cache.cc +19 −19 Original line number Diff line number Diff line Loading @@ -21,8 +21,9 @@ #include <base/logging.h> #include <base/strings/string_number_conversions.h> #include <base/strings/string_util.h> #include <cutils/properties.h> #include <brillo/osrelease_reader.h> #include <string> #include <update_engine/client.h> #include <vector> #include "constants.h" Loading Loading @@ -73,16 +74,27 @@ bool SystemProfileCache::Initialize() { CHECK(!initialized_) << "this should be called only once in the metrics_daemon lifetime."; profile_.product_id = GetProperty(metrics::kProductIdProperty); brillo::OsReleaseReader reader; std::string channel; if (testing_) { reader.LoadTestingOnly(metrics_directory_); channel = "unknown"; } else { reader.Load(); auto client = update_engine::UpdateEngineClient::CreateInstance(); if (!client->GetChannel(&channel)) { LOG(ERROR) << "failed to read the current channel from update engine."; } } if (profile_.product_id.empty()) { LOG(ERROR) << "System property " << metrics::kProductIdProperty << " is not set."; if (!reader.GetString(metrics::kProductId, &profile_.product_id)) { LOG(ERROR) << "product_id is not set."; return false; } std::string channel = GetProperty(metrics::kChannelProperty); profile_.version = GetProperty(metrics::kProductVersionProperty); if (!reader.GetString(metrics::kProductVersion, &profile_.version)) { LOG(ERROR) << "failed to read the product version"; } if (channel.empty() || profile_.version.empty()) { // If the channel or version is missing, the image is not official. Loading Loading @@ -154,18 +166,6 @@ std::string SystemProfileCache::GetPersistentGUID( return guid; } std::string SystemProfileCache::GetProperty(const std::string& name) { if (testing_) { std::string content; base::ReadFileToString(metrics_directory_.Append(name), &content); return content; } else { char value[PROPERTY_VALUE_MAX]; property_get(name.data(), value, ""); return std::string(value); } } metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString( const std::string& channel) { if (channel == "stable") { Loading
metricsd/uploader/system_profile_cache.h +0 −5 Original line number Diff line number Diff line Loading @@ -76,11 +76,6 @@ class SystemProfileCache : public SystemProfileSetter { // Initializes |profile_| only if it has not been yet initialized. bool InitializeOrCheck(); // Gets a system property as a string. // When |testing_| is true, reads the value from |metrics_directory_|/|name| // instead. std::string GetProperty(const std::string& name); bool initialized_; bool testing_; base::FilePath metrics_directory_; Loading