crash_reporter: Set Version and Product ID

Read in the ro.build.id property for version, and
ro.product.product_id for the Product ID.

Bug: 22874192
Change-Id: I9a3fbf375d49d04fc7bf6700c5987cb9e435c318
diff --git a/crash_reporter/Android.mk b/crash_reporter/Android.mk
index e797022..8756956 100644
--- a/crash_reporter/Android.mk
+++ b/crash_reporter/Android.mk
@@ -117,6 +117,7 @@
 LOCAL_CPP_EXTENSION := $(crash_reporter_cpp_extension)
 LOCAL_SHARED_LIBRARIES := libchrome \
     libchromeos \
+    libcutils \
     libdbus \
     libpcrecpp
 LOCAL_SRC_FILES := $(crash_reporter_test_src)
diff --git a/crash_reporter/crash_collector.cc b/crash_reporter/crash_collector.cc
index b81a936..ae56b4c 100644
--- a/crash_reporter/crash_collector.cc
+++ b/crash_reporter/crash_collector.cc
@@ -53,9 +53,6 @@
 const char kUploadVarPrefix[] = "upload_var_";
 const char kUploadFilePrefix[] = "upload_file_";
 
-// Key of the lsb-release entry containing the OS version.
-const char kLsbVersionKey[] = "CHROMEOS_RELEASE_VERSION";
-
 // Normally this path is not used.  Unfortunately, there are a few edge cases
 // where we need this.  Any process that runs as kDefaultUserName that crashes
 // is consider a "user crash".  That includes the initial Chrome browser that
@@ -387,27 +384,14 @@
 void CrashCollector::WriteCrashMetaData(const FilePath &meta_path,
                                         const std::string &exec_name,
                                         const std::string &payload_path) {
-  chromeos::KeyValueStore store;
-  if (!store.Load(FilePath(lsb_release_))) {
-    LOG(ERROR) << "Problem parsing " << lsb_release_;
-    // Even though there was some failure, take as much as we could read.
-  }
-
-  std::string version("unknown");
-  if (!store.GetString(kLsbVersionKey, &version)) {
-    LOG(ERROR) << "Unable to read " << kLsbVersionKey << " from "
-               << lsb_release_;
-  }
   int64_t payload_size = -1;
   base::GetFileSize(FilePath(payload_path), &payload_size);
   std::string meta_data = StringPrintf("%sexec_name=%s\n"
-                                       "ver=%s\n"
                                        "payload=%s\n"
                                        "payload_size=%" PRId64 "\n"
                                        "done=1\n",
                                        extra_metadata_.c_str(),
                                        exec_name.c_str(),
-                                       version.c_str(),
                                        payload_path.c_str(),
                                        payload_size);
   // We must use WriteNewFile instead of base::WriteFile as we
diff --git a/crash_reporter/user_collector.cc b/crash_reporter/user_collector.cc
index 61ccc37..a9522cc 100644
--- a/crash_reporter/user_collector.cc
+++ b/crash_reporter/user_collector.cc
@@ -55,6 +55,13 @@
 const char *UserCollector::kUserId = "Uid:\t";
 const char *UserCollector::kGroupId = "Gid:\t";
 
+// The property containing the OS version.
+const char kVersionProperty[] = "ro.build.id";
+
+// The property containing the product id.
+const char kProductIDProperty[] = "ro.product.product_id";
+
+
 using base::FilePath;
 using base::StringPrintf;
 
@@ -455,6 +462,12 @@
   if (GetLogContents(FilePath(log_config_path_), exec, log_path))
     AddCrashMetaData("log", log_path.value());
 
+  char value[PROPERTY_VALUE_MAX];
+  property_get(kVersionProperty, value, "undefined");
+  AddCrashMetaUploadData("ver", value);
+  property_get(kProductIDProperty, value, "undefined");
+  AddCrashMetaUploadData("prod", value);
+
   ErrorType error_type =
       ConvertCoreToMinidump(pid, container_dir, core_path, minidump_path);
   if (error_type != kErrorNone) {