Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f981bb7 authored by Gaurav Shah's avatar Gaurav Shah Committed by Android Git Automerger
Browse files

am fb44650a: am dc15f4cd: Merge "metrics: Enable for non-official builds."

* commit 'fb44650a':
  metrics: Enable for non-official builds.
parents 1b4be16f fb44650a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events";
static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID";
static const char kMetricsServer[] = "http://clients4.google.com/uma/v2";
static const char kConsentFilePath[] = "/data/misc/metrics/enabled";
static const char kDefaultVersion[] = "0.0.0.0";
}  // namespace metrics

#endif  // METRICS_CONSTANTS_H_
+11 −25
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
#include <base/sys_info.h>
#include <dbus/dbus.h>
#include <dbus/message.h>

#include "constants.h"
#include "uploader/upload_service.h"

using base::FilePath;
@@ -44,10 +46,6 @@ const char kCrashReporterUserCrashSignal[] = "UserCrash";
const char kCrashReporterMatchRule[] =
    "type='signal',interface='%s',path='/',member='%s'";

// Build type of an official build.
// See src/third_party/chromiumos-overlay/chromeos/scripts/cros_set_lsb_release.
const char kOfficialBuild[] = "Official Build";

const int kSecondsPerMinute = 60;
const int kMinutesPerHour = 60;
const int kHoursPerDay = 24;
@@ -199,24 +197,17 @@ uint32_t MetricsDaemon::GetOsVersionHash() {
  if (version_hash_is_cached)
    return cached_version_hash;
  version_hash_is_cached = true;
  std::string version;
  if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) {
  std::string version = metrics::kDefaultVersion;
  // The version might not be set for development devices. In this case, use the
  // zero version.
  base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version);
  cached_version_hash = base::Hash(version);
  } else if (testing_) {
  if (testing_) {
    cached_version_hash = 42;  // return any plausible value for the hash
  } else {
    LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION";
  }
  return cached_version_hash;
}

bool MetricsDaemon::IsOnOfficialBuild() const {
  std::string build_type;
  return (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE",
                                            &build_type) &&
          build_type == kOfficialBuild);
}

void MetricsDaemon::Init(bool testing,
                         bool uploader_active,
                         MetricsLibraryInterface* metrics_lib,
@@ -317,14 +308,9 @@ int MetricsDaemon::OnInit() {
  }

  if (uploader_active_) {
    if (IsOnOfficialBuild()) {
      LOG(INFO) << "uploader enabled";
    upload_service_.reset(
        new UploadService(new SystemProfileCache(), metrics_lib_, server_));
    upload_service_->Init(upload_interval_, metrics_file_);
    } else {
      LOG(INFO) << "uploader disabled on non-official build";
    }
  }

  return EX_OK;
+0 −3
Original line number Diff line number Diff line
@@ -268,9 +268,6 @@ class MetricsDaemon : public chromeos::DBusDaemon {
  // to a unsigned 32-bit int.
  uint32_t GetOsVersionHash();

  // Returns true if the system is using an official build.
  bool IsOnOfficialBuild() const;

  // Updates stats, additionally sending them to UMA if enough time has elapsed
  // since the last report.
  void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time);
+11 −4
Original line number Diff line number Diff line
@@ -61,15 +61,22 @@ bool SystemProfileCache::Initialize() {
  CHECK(!initialized_)
      << "this should be called only once in the metrics_daemon lifetime.";

  std::string channel;
  if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) ||
      !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version) ||
      !base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID",
  if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID",
                                         &profile_.build_target_id)) {
    LOG(ERROR) << "Could not initialize system profile.";
    return false;
  }

  std::string channel;
  if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) ||
      !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version)) {
    // 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" :
      GetPersistentGUID(metrics::kMetricsGUIDFilePath);