Extract new system version from Omaha responses

When processing an Omaha response, line up the app elements for the main
product and system apps, by their appid fields.  This allows the (product)
version and system version to be differentiated and recorded in the
InstallPlan.

Bug: 65422956
Test:  Unit-tests, and using a live OTA
Change-Id: I5217b7ac6fbf6f7ae595c1cec6fbc329051925eb
(cherry picked from commit 19ef6db4885387a5e3fbd2affcbd57a9a40d8b9b)
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index c3bbf9d..cce4287 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -392,6 +392,7 @@
   string daystart_elapsed_seconds;
 
   struct App {
+    string id;
     vector<string> url_codebase;
     string manifest_version;
     map<string, string> action_postinstall_attrs;
@@ -430,6 +431,9 @@
 
   if (data->current_path == "/response/app") {
     data->apps.emplace_back();
+    if (attrs.find("appid") != attrs.end()) {
+      data->apps.back().id = attrs["appid"];
+    }
     if (attrs.find("cohort") != attrs.end()) {
       data->app_cohort_set = true;
       data->app_cohort = attrs["cohort"];
@@ -983,10 +987,18 @@
                                      ScopedActionCompleter* completer) {
   map<string, string> attrs;
   for (auto& app : parser_data->apps) {
-    if (!app.manifest_version.empty() && output_object->version.empty())
+    if (app.id == params_->GetAppId()) {
+      // this is the app (potentially the only app)
       output_object->version = app.manifest_version;
-    if (!app.action_postinstall_attrs.empty() && attrs.empty())
+    } else if (!params_->system_app_id().empty() &&
+               app.id == params_->system_app_id()) {
+      // this is the system app (this check is intentionally skipped if there is
+      // no system_app_id set)
+      output_object->system_version = app.manifest_version;
+    }
+    if (!app.action_postinstall_attrs.empty() && attrs.empty()) {
       attrs = app.action_postinstall_attrs;
+    }
   }
   if (output_object->version.empty()) {
     LOG(ERROR) << "Omaha Response does not have version in manifest!";