am c3f866f6: Merge "metricsd: Use system properties to store build time metadata."

* commit 'c3f866f60cedc7eade674a7a8eec740dd938264f':
  metricsd: Use system properties to store build time metadata.
This commit is contained in:
Bertrand Simonnet 2015-08-27 18:01:45 +00:00 committed by Android Git Automerger
commit 414f6226fc
4 changed files with 27 additions and 11 deletions

View file

@ -110,6 +110,7 @@ LOCAL_SHARED_LIBRARIES := $(metrics_shared_libraries) \
libprotobuf-cpp-lite \ libprotobuf-cpp-lite \
libchromeos-http \ libchromeos-http \
libchromeos-dbus \ libchromeos-dbus \
libcutils \
libdbus libdbus
LOCAL_SRC_FILES := $(metrics_daemon_sources) LOCAL_SRC_FILES := $(metrics_daemon_sources)
LOCAL_STATIC_LIBRARIES := metrics_daemon_protos LOCAL_STATIC_LIBRARIES := metrics_daemon_protos

View file

@ -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 kMetricsServer[] = "https://clients4.google.com/uma/v2";
static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled";
static const char kDefaultVersion[] = "0.0.0.0"; 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 } // namespace metrics
#endif // METRICS_CONSTANTS_H_ #endif // METRICS_CONSTANTS_H_

View file

@ -32,7 +32,7 @@
#include <base/strings/string_split.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/sys_info.h> #include <cutils/properties.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/message.h> #include <dbus/message.h>
@ -209,10 +209,13 @@ uint32_t MetricsDaemon::GetOsVersionHash() {
if (version_hash_is_cached) if (version_hash_is_cached)
return cached_version_hash; return cached_version_hash;
version_hash_is_cached = true; 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 // The version might not be set for development devices. In this case, use the
// zero version. // zero version.
base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version); property_get(metrics::kProductVersionProperty, version,
metrics::kDefaultVersion);
cached_version_hash = base::Hash(version); cached_version_hash = base::Hash(version);
if (testing_) { if (testing_) {
cached_version_hash = 42; // return any plausible value for the hash cached_version_hash = 42; // return any plausible value for the hash

View file

@ -21,7 +21,7 @@
#include <base/logging.h> #include <base/logging.h>
#include <base/strings/string_number_conversions.h> #include <base/strings/string_number_conversions.h>
#include <base/strings/string_util.h> #include <base/strings/string_util.h>
#include <base/sys_info.h> #include <cutils/properties.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -73,21 +73,28 @@ bool SystemProfileCache::Initialize() {
CHECK(!initialized_) CHECK(!initialized_)
<< "this should be called only once in the metrics_daemon lifetime."; << "this should be called only once in the metrics_daemon lifetime.";
if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", char property_value[PROPERTY_VALUE_MAX];
&profile_.build_target_id)) { property_get(metrics::kBuildTargetIdProperty, property_value, "");
LOG(ERROR) << "BRILLO_BUILD_TARGET_ID is not set in /etc/lsb-release."; 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; return false;
} }
std::string channel; property_get(metrics::kChannelProperty, property_value, "");
if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || std::string channel(property_value);
!base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version)) {
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. // 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 // In this case, set the channel to unknown and the version to 0.0.0.0 to
// avoid polluting the production data. // avoid polluting the production data.
channel = ""; channel = "";
profile_.version = metrics::kDefaultVersion; profile_.version = metrics::kDefaultVersion;
} }
profile_.client_id = profile_.client_id =
testing_ ? "client_id_test" : testing_ ? "client_id_test" :