From f1aa372f77e5a9d8a7726c38259418d99c0b4dac Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Fri, 22 Jan 2016 13:15:54 -0800 Subject: [PATCH] metricsd: Add more assert clause. This CL adds two more checks: * When populating a closed log with the metadata, make sure the SystemProfileSetter is not null. * When using the update engine client library, check if the update engine client object was created correctly. The returning object can be null if update engine's binder service is not running. Bug: 26731548 Change-Id: I8a615c87f33e15a163d56ccfa3a932a0908aac5f --- metricsd/uploader/metrics_log.cc | 1 + metricsd/uploader/system_profile_cache.cc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/metricsd/uploader/metrics_log.cc b/metricsd/uploader/metrics_log.cc index 39655e637..fcaa8c13c 100644 --- a/metricsd/uploader/metrics_log.cc +++ b/metricsd/uploader/metrics_log.cc @@ -85,5 +85,6 @@ void MetricsLog::IncrementUncleanShutdownCount(unsigned int count) { } bool MetricsLog::PopulateSystemProfile(SystemProfileSetter* profile_setter) { + CHECK(profile_setter); return profile_setter->Populate(uma_proto()); } diff --git a/metricsd/uploader/system_profile_cache.cc b/metricsd/uploader/system_profile_cache.cc index 70f6afd50..e6f661702 100644 --- a/metricsd/uploader/system_profile_cache.cc +++ b/metricsd/uploader/system_profile_cache.cc @@ -80,6 +80,10 @@ bool SystemProfileCache::Initialize() { } else { reader.Load(); auto client = update_engine::UpdateEngineClient::CreateInstance(); + if (!client) { + LOG(ERROR) << "failed to create the update engine client"; + return false; + } if (!client->GetChannel(&channel)) { LOG(ERROR) << "failed to read the current channel from update engine."; return false;