update_engine: Barebone Omaha Request for DLC(s)

No need to maintain certain attributes for DLC update/install request to Omaha.

The list of uneccessary attributes for DLC AppIDs:
 - lang
 - fw_version
 - ec_version
 - requisition

BUG=chromium:1039898
TEST=FEATURES=test emerge-$B update_engine

Change-Id: I40efc3435d4c359470464f2dc6e32470cc629938
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1992192
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/omaha_request_builder_xml.cc b/omaha_request_builder_xml.cc
index 95fb183..823894e 100644
--- a/omaha_request_builder_xml.cc
+++ b/omaha_request_builder_xml.cc
@@ -309,14 +309,18 @@
       product_components_args +
       fingerprint_arg +
       buildtype_arg +
-      "lang=\"" + XmlEncodeWithDefault(params_->app_lang(), "en-US") + "\" " +
       "board=\"" + XmlEncodeWithDefault(params_->os_board()) + "\" " +
       "hardware_class=\"" + XmlEncodeWithDefault(params_->hwid()) + "\" " +
-      "delta_okay=\"" + delta_okay_str + "\" "
+      "delta_okay=\"" + delta_okay_str + "\" " +
+      install_date_in_days_str +
+
+      // DLC excluded for installs and updates.
+      (app_data.is_dlc ? "" :
+      "lang=\"" + XmlEncodeWithDefault(params_->app_lang(), "en-US") + "\" " +
       "fw_version=\"" + XmlEncodeWithDefault(params_->fw_version()) + "\" " +
       "ec_version=\"" + XmlEncodeWithDefault(params_->ec_version()) + "\" " +
-      install_date_in_days_str +
-      requisition_arg +
+      requisition_arg) +
+
       ">\n" +
          app_body +
       "    </app>\n";
@@ -363,12 +367,14 @@
       .version = params_->app_version(),
       .product_components = params_->product_components(),
       // Skips updatecheck for platform app in case of an install operation.
-      .skip_update = params_->is_install()};
+      .skip_update = params_->is_install(),
+      .is_dlc = false};
   app_xml += GetApp(product_app);
   if (!params_->system_app_id().empty()) {
     OmahaAppData system_app = {.id = params_->system_app_id(),
                                .version = params_->system_version(),
-                               .skip_update = false};
+                               .skip_update = false,
+                               .is_dlc = false};
     app_xml += GetApp(system_app);
   }
   // Create APP ID according to |dlc_module_id| (sticking the current AppID to
@@ -377,7 +383,8 @@
     OmahaAppData dlc_module_app = {
         .id = params_->GetAppId() + "_" + dlc_module_id,
         .version = params_->app_version(),
-        .skip_update = false};
+        .skip_update = false,
+        .is_dlc = true};
     app_xml += GetApp(dlc_module_app);
   }
   return app_xml;
diff --git a/omaha_request_builder_xml.h b/omaha_request_builder_xml.h
index 495ddd7..488be8a 100644
--- a/omaha_request_builder_xml.h
+++ b/omaha_request_builder_xml.h
@@ -85,6 +85,7 @@
   std::string version;
   std::string product_components;
   bool skip_update;
+  bool is_dlc;
 };
 
 // Encodes XML entities in a given string. Input must be ASCII-7 valid. If
@@ -139,6 +140,9 @@
   std::string GetRequest() const override;
 
  private:
+  FRIEND_TEST(OmahaRequestBuilderXmlTest, PlatformGetAppTest);
+  FRIEND_TEST(OmahaRequestBuilderXmlTest, DlcGetAppTest);
+
   // Returns an XML that corresponds to the entire <os> node of the Omaha
   // request based on the member variables.
   std::string GetOs() const;
diff --git a/omaha_request_builder_xml_unittest.cc b/omaha_request_builder_xml_unittest.cc
index 4375bed..ecab0e0 100644
--- a/omaha_request_builder_xml_unittest.cc
+++ b/omaha_request_builder_xml_unittest.cc
@@ -80,6 +80,56 @@
   EXPECT_EQ("<not escaped>", XmlEncodeWithDefault("\xc2", "<not escaped>"));
 }
 
+TEST_F(OmahaRequestBuilderXmlTest, PlatformGetAppTest) {
+  OmahaRequestParams omaha_request_params{&fake_system_state_};
+  omaha_request_params.set_device_requisition("device requisition");
+  OmahaRequestBuilderXml omaha_request{nullptr,
+                                       &omaha_request_params,
+                                       false,
+                                       false,
+                                       0,
+                                       0,
+                                       0,
+                                       fake_system_state_.prefs(),
+                                       ""};
+  OmahaAppData dlc_module_app = {.id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
+                                 .version = "",
+                                 .skip_update = false,
+                                 .is_dlc = false};
+
+  // Verify that the attributes that shouldn't be missing for Platform AppID are
+  // in fact present in the <app ...></app>.
+  const string app = omaha_request.GetApp(dlc_module_app);
+  EXPECT_NE(string::npos, app.find("lang="));
+  EXPECT_NE(string::npos, app.find("fw_version="));
+  EXPECT_NE(string::npos, app.find("ec_version="));
+  EXPECT_NE(string::npos, app.find("requisition="));
+}
+
+TEST_F(OmahaRequestBuilderXmlTest, DlcGetAppTest) {
+  OmahaRequestParams omaha_request_params{&fake_system_state_};
+  omaha_request_params.set_device_requisition("device requisition");
+  OmahaRequestBuilderXml omaha_request{nullptr,
+                                       &omaha_request_params,
+                                       false,
+                                       false,
+                                       0,
+                                       0,
+                                       0,
+                                       fake_system_state_.prefs(),
+                                       ""};
+  OmahaAppData dlc_module_app = {
+      .id = "_dlc_id", .version = "", .skip_update = false, .is_dlc = true};
+
+  // Verify that the attributes that should be missing for DLC AppIDs are in
+  // fact not present in the <app ...></app>.
+  const string app = omaha_request.GetApp(dlc_module_app);
+  EXPECT_EQ(string::npos, app.find("lang="));
+  EXPECT_EQ(string::npos, app.find("fw_version="));
+  EXPECT_EQ(string::npos, app.find("ec_version="));
+  EXPECT_EQ(string::npos, app.find("requisition="));
+}
+
 TEST_F(OmahaRequestBuilderXmlTest, GetRequestXmlRequestIdTest) {
   OmahaEvent omaha_event;
   OmahaRequestParams omaha_request_params{&fake_system_state_};