blob: 6cd9ab80b3ecf0415a68232a4372e52f95ea2afe [file] [log] [blame]
Amin Hassani7fca2862019-03-28 16:09:22 -07001//
2// Copyright (C) 2019 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/cros/omaha_request_builder_xml.h"
Amin Hassani7fca2862019-03-28 16:09:22 -070018
19#include <inttypes.h>
20
21#include <string>
22
Jae Hoon Kim6ada5912019-06-14 10:11:34 -070023#include <base/guid.h>
Amin Hassani7fca2862019-03-28 16:09:22 -070024#include <base/logging.h>
25#include <base/strings/string_number_conversions.h>
26#include <base/strings/string_util.h>
27#include <base/strings/stringprintf.h>
28#include <base/time/time.h>
29
30#include "update_engine/common/constants.h"
Amin Hassani9ed2cee2020-11-13 18:40:35 -080031#include "update_engine/common/system_state.h"
Amin Hassani7fca2862019-03-28 16:09:22 -070032#include "update_engine/common/utils.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070033#include "update_engine/cros/omaha_request_params.h"
Amin Hassani7fca2862019-03-28 16:09:22 -070034
35using std::string;
36
37namespace chromeos_update_engine {
38
Jae Hoon Kim5fc00a22020-01-08 20:15:42 -080039const char kNoVersion[] = "0.0.0.0";
Andrewe045aef2020-01-08 16:29:22 -080040const int kPingNeverPinged = -1;
41const int kPingUnknownValue = -2;
42const int kPingActiveValue = 1;
43const int kPingInactiveValue = 0;
Amin Hassani7fca2862019-03-28 16:09:22 -070044
45bool XmlEncode(const string& input, string* output) {
46 if (std::find_if(input.begin(), input.end(), [](const char c) {
47 return c & 0x80;
48 }) != input.end()) {
49 LOG(WARNING) << "Invalid ASCII-7 string passed to the XML encoder:";
50 utils::HexDumpString(input);
51 return false;
52 }
53 output->clear();
54 // We need at least input.size() space in the output, but the code below will
55 // handle it if we need more.
56 output->reserve(input.size());
57 for (char c : input) {
58 switch (c) {
59 case '\"':
60 output->append("&quot;");
61 break;
62 case '\'':
63 output->append("&apos;");
64 break;
65 case '&':
66 output->append("&amp;");
67 break;
68 case '<':
69 output->append("&lt;");
70 break;
71 case '>':
72 output->append("&gt;");
73 break;
74 default:
75 output->push_back(c);
76 }
77 }
78 return true;
79}
80
81string XmlEncodeWithDefault(const string& input, const string& default_value) {
82 string output;
83 if (XmlEncode(input, &output))
84 return output;
85 return default_value;
86}
87
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -070088string OmahaRequestBuilderXml::GetPing() const {
89 // Returns an XML ping element attribute assignment with attribute
90 // |name| and value |ping_days| if |ping_days| has a value that needs
91 // to be sent, or an empty string otherwise.
92 auto GetPingAttribute = [](const char* name, int ping_days) -> string {
Andrewe045aef2020-01-08 16:29:22 -080093 if (ping_days > 0 || ping_days == kPingNeverPinged)
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -070094 return base::StringPrintf(" %s=\"%d\"", name, ping_days);
95 return "";
96 };
Amin Hassani7fca2862019-03-28 16:09:22 -070097
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -070098 string ping_active = GetPingAttribute("a", ping_active_days_);
99 string ping_roll_call = GetPingAttribute("r", ping_roll_call_days_);
Amin Hassani7fca2862019-03-28 16:09:22 -0700100 if (!ping_active.empty() || !ping_roll_call.empty()) {
101 return base::StringPrintf(" <ping active=\"1\"%s%s></ping>\n",
102 ping_active.c_str(),
103 ping_roll_call.c_str());
104 }
105 return "";
106}
107
Andrewe045aef2020-01-08 16:29:22 -0800108string OmahaRequestBuilderXml::GetPingDateBased(
109 const OmahaRequestParams::AppParams& app_params) const {
110 if (!app_params.send_ping)
111 return "";
112 string ping_active = "";
113 string ping_ad = "";
114 if (app_params.ping_active == kPingActiveValue) {
115 ping_active =
116 base::StringPrintf(" active=\"%" PRId64 "\"", app_params.ping_active);
117 ping_ad = base::StringPrintf(" ad=\"%" PRId64 "\"",
118 app_params.ping_date_last_active);
119 }
120
121 string ping_rd = base::StringPrintf(" rd=\"%" PRId64 "\"",
122 app_params.ping_date_last_rollcall);
123
124 return base::StringPrintf(" <ping%s%s%s></ping>\n",
125 ping_active.c_str(),
126 ping_ad.c_str(),
127 ping_rd.c_str());
128}
129
130string OmahaRequestBuilderXml::GetAppBody(const OmahaAppData& app_data) const {
Amin Hassani7fca2862019-03-28 16:09:22 -0700131 string app_body;
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700132 if (event_ == nullptr) {
Andrewe045aef2020-01-08 16:29:22 -0800133 if (app_data.app_params.send_ping) {
134 switch (app_data.app_params.active_counting_type) {
135 case OmahaRequestParams::kDayBased:
136 app_body = GetPing();
137 break;
138 case OmahaRequestParams::kDateBased:
139 app_body = GetPingDateBased(app_data.app_params);
140 break;
141 default:
142 NOTREACHED();
143 }
144 }
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700145 if (!ping_only_) {
Andrewe045aef2020-01-08 16:29:22 -0800146 if (!app_data.skip_update) {
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800147 const auto* params = SystemState::Get()->request_params();
Amin Hassani7fca2862019-03-28 16:09:22 -0700148 app_body += " <updatecheck";
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800149 if (!params->target_version_prefix().empty()) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700150 app_body += base::StringPrintf(
151 " targetversionprefix=\"%s\"",
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800152 XmlEncodeWithDefault(params->target_version_prefix()).c_str());
Amin Hassani7fca2862019-03-28 16:09:22 -0700153 // Rollback requires target_version_prefix set.
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800154 if (params->rollback_allowed()) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700155 app_body += " rollback_allowed=\"true\"";
156 }
157 }
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800158 if (!params->lts_tag().empty()) {
Amin Hassani37b67232020-08-13 09:29:48 -0700159 app_body += base::StringPrintf(
160 " ltstag=\"%s\"",
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800161 XmlEncodeWithDefault(params->lts_tag()).c_str());
Amin Hassani37b67232020-08-13 09:29:48 -0700162 }
Amin Hassani7fca2862019-03-28 16:09:22 -0700163 app_body += "></updatecheck>\n";
164 }
165
166 // If this is the first update check after a reboot following a previous
167 // update, generate an event containing the previous version number. If
168 // the previous version preference file doesn't exist the event is still
169 // generated with a previous version of 0.0.0.0 -- this is relevant for
170 // older clients or new installs. The previous version event is not sent
171 // for ping-only requests because they come before the client has
172 // rebooted. The previous version event is also not sent if it was already
173 // sent for this new version with a previous updatecheck.
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800174 auto* prefs = SystemState::Get()->prefs();
Amin Hassani7fca2862019-03-28 16:09:22 -0700175 string prev_version;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800176 if (!prefs->GetString(kPrefsPreviousVersion, &prev_version)) {
Jae Hoon Kim5fc00a22020-01-08 20:15:42 -0800177 prev_version = kNoVersion;
Amin Hassani7fca2862019-03-28 16:09:22 -0700178 }
179 // We only store a non-empty previous version value after a successful
180 // update in the previous boot. After reporting it back to the server,
181 // we clear the previous version value so it doesn't get reported again.
182 if (!prev_version.empty()) {
183 app_body += base::StringPrintf(
184 " <event eventtype=\"%d\" eventresult=\"%d\" "
185 "previousversion=\"%s\"></event>\n",
186 OmahaEvent::kTypeRebootedAfterUpdate,
187 OmahaEvent::kResultSuccess,
Jae Hoon Kim5fc00a22020-01-08 20:15:42 -0800188 XmlEncodeWithDefault(prev_version, kNoVersion).c_str());
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800189 LOG_IF(WARNING, !prefs->SetString(kPrefsPreviousVersion, ""))
Amin Hassani7fca2862019-03-28 16:09:22 -0700190 << "Unable to reset the previous version.";
191 }
192 }
193 } else {
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -0700194 int event_result = event_->result;
Amin Hassani7fca2862019-03-28 16:09:22 -0700195 // The error code is an optional attribute so append it only if the result
196 // is not success.
197 string error_code;
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -0700198 if (event_result != OmahaEvent::kResultSuccess) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700199 error_code = base::StringPrintf(" errorcode=\"%d\"",
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700200 static_cast<int>(event_->error_code));
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -0700201 } else if (app_data.is_dlc && !app_data.app_params.updated) {
202 // On a |OmahaEvent::kResultSuccess|, if the event is for an update
203 // completion and the App is a DLC, send error for excluded DLCs as they
204 // did not update.
205 event_result = OmahaEvent::Result::kResultError;
206 error_code = base::StringPrintf(
207 " errorcode=\"%d\"",
208 static_cast<int>(ErrorCode::kPackageExcludedFromUpdate));
Amin Hassani7fca2862019-03-28 16:09:22 -0700209 }
210 app_body = base::StringPrintf(
211 " <event eventtype=\"%d\" eventresult=\"%d\"%s></event>\n",
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700212 event_->type,
Jae Hoon Kim3e69b4c2020-06-16 09:23:39 -0700213 event_result,
Amin Hassani7fca2862019-03-28 16:09:22 -0700214 error_code.c_str());
215 }
216
217 return app_body;
218}
219
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800220string OmahaRequestBuilderXml::GetCohortArg(
221 const string& arg_name,
222 const string& prefs_key,
223 const string& override_value) const {
Amin Hassani7fca2862019-03-28 16:09:22 -0700224 string cohort_value;
Askar Aitzhan18fff842019-06-21 23:24:37 +0200225 if (!override_value.empty()) {
226 // |override_value| take precedence over pref value.
227 cohort_value = override_value;
228 } else {
229 // There's nothing wrong with not having a given cohort setting, so we check
230 // existence first to avoid the warning log message.
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800231 const auto* prefs = SystemState::Get()->prefs();
232 if (!prefs->Exists(prefs_key))
Askar Aitzhan18fff842019-06-21 23:24:37 +0200233 return "";
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800234 if (!prefs->GetString(prefs_key, &cohort_value) || cohort_value.empty())
Askar Aitzhan18fff842019-06-21 23:24:37 +0200235 return "";
236 }
Kelvin Zhangebd5e252020-07-22 18:27:06 -0400237 // This is a validity check to avoid sending a huge XML file back to Ohama due
Amin Hassani7fca2862019-03-28 16:09:22 -0700238 // to a compromised stateful partition making the update check fail in low
239 // network environments envent after a reboot.
240 if (cohort_value.size() > 1024) {
241 LOG(WARNING) << "The omaha cohort setting " << arg_name
242 << " has a too big value, which must be an error or an "
243 "attacker trying to inhibit updates.";
244 return "";
245 }
246
247 string escaped_xml_value;
248 if (!XmlEncode(cohort_value, &escaped_xml_value)) {
249 LOG(WARNING) << "The omaha cohort setting " << arg_name
250 << " is ASCII-7 invalid, ignoring it.";
251 return "";
252 }
253
254 return base::StringPrintf(
255 "%s=\"%s\" ", arg_name.c_str(), escaped_xml_value.c_str());
256}
257
258bool IsValidComponentID(const string& id) {
259 for (char c : id) {
260 if (!isalnum(c) && c != '-' && c != '_' && c != '.')
261 return false;
262 }
263 return true;
264}
265
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700266string OmahaRequestBuilderXml::GetApp(const OmahaAppData& app_data) const {
Andrewe045aef2020-01-08 16:29:22 -0800267 string app_body = GetAppBody(app_data);
Amin Hassani7fca2862019-03-28 16:09:22 -0700268 string app_versions;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800269 const auto* params = SystemState::Get()->request_params();
Amin Hassani7fca2862019-03-28 16:09:22 -0700270
271 // If we are downgrading to a more stable channel and we are allowed to do
272 // powerwash, then pass 0.0.0.0 as the version. This is needed to get the
273 // highest-versioned payload on the destination channel.
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800274 if (params->ShouldPowerwash()) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700275 LOG(INFO) << "Passing OS version as 0.0.0.0 as we are set to powerwash "
276 << "on downgrading to the version in the more stable channel";
Jae Hoon Kim5fc00a22020-01-08 20:15:42 -0800277 app_versions = "version=\"" + string(kNoVersion) + "\" from_version=\"" +
278 XmlEncodeWithDefault(app_data.version, kNoVersion) + "\" ";
Amin Hassani7fca2862019-03-28 16:09:22 -0700279 } else {
280 app_versions = "version=\"" +
Jae Hoon Kim5fc00a22020-01-08 20:15:42 -0800281 XmlEncodeWithDefault(app_data.version, kNoVersion) + "\" ";
Amin Hassani7fca2862019-03-28 16:09:22 -0700282 }
283
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800284 string download_channel = params->download_channel();
Amin Hassani7fca2862019-03-28 16:09:22 -0700285 string app_channels =
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700286 "track=\"" + XmlEncodeWithDefault(download_channel) + "\" ";
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800287 if (params->current_channel() != download_channel) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700288 app_channels += "from_track=\"" +
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800289 XmlEncodeWithDefault(params->current_channel()) + "\" ";
Amin Hassani7fca2862019-03-28 16:09:22 -0700290 }
291
Jae Hoon Kim5fc00a22020-01-08 20:15:42 -0800292 string delta_okay_str =
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800293 params->delta_okay() && !params->is_install() ? "true" : "false";
Amin Hassani7fca2862019-03-28 16:09:22 -0700294
295 // If install_date_days is not set (e.g. its value is -1 ), don't
296 // include the attribute.
297 string install_date_in_days_str = "";
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700298 if (install_date_in_days_ >= 0) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700299 install_date_in_days_str =
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700300 base::StringPrintf("installdate=\"%d\" ", install_date_in_days_);
Amin Hassani7fca2862019-03-28 16:09:22 -0700301 }
302
303 string app_cohort_args;
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800304 string cohort_key = kPrefsOmahaCohort;
305 string cohortname_key = kPrefsOmahaCohortName;
306 string cohorthint_key = kPrefsOmahaCohortHint;
Amin Hassani7fca2862019-03-28 16:09:22 -0700307
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800308 // Override the cohort keys for DLC App IDs.
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800309 const auto& dlc_apps_params = params->dlc_apps_params();
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800310 auto itr = dlc_apps_params.find(app_data.id);
311 if (itr != dlc_apps_params.end()) {
312 auto dlc_id = itr->second.name;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800313 const auto* prefs = SystemState::Get()->prefs();
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800314 cohort_key =
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800315 prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohort});
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800316 cohortname_key =
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800317 prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohortName});
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800318 cohorthint_key =
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800319 prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohortHint});
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800320 }
321
322 app_cohort_args += GetCohortArg("cohort", cohort_key);
323 app_cohort_args += GetCohortArg("cohortname", cohortname_key);
Askar Aitzhan18fff842019-06-21 23:24:37 +0200324 // Policy provided value overrides pref.
Jae Hoon Kime2cac612020-11-02 18:30:29 -0800325 app_cohort_args +=
326 GetCohortArg("cohorthint",
327 cohorthint_key,
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800328 params->autoupdate_token() /* override_value */);
Askar Aitzhan18fff842019-06-21 23:24:37 +0200329
Amin Hassani7fca2862019-03-28 16:09:22 -0700330 string fingerprint_arg;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800331 if (!params->os_build_fingerprint().empty()) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700332 fingerprint_arg = "fingerprint=\"" +
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800333 XmlEncodeWithDefault(params->os_build_fingerprint()) +
Amin Hassani7fca2862019-03-28 16:09:22 -0700334 "\" ";
335 }
336
337 string buildtype_arg;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800338 if (!params->os_build_type().empty()) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700339 buildtype_arg = "os_build_type=\"" +
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800340 XmlEncodeWithDefault(params->os_build_type()) + "\" ";
Amin Hassani7fca2862019-03-28 16:09:22 -0700341 }
342
343 string product_components_args;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800344 if (!params->ShouldPowerwash() && !app_data.product_components.empty()) {
Amin Hassani7fca2862019-03-28 16:09:22 -0700345 brillo::KeyValueStore store;
346 if (store.LoadFromString(app_data.product_components)) {
347 for (const string& key : store.GetKeys()) {
348 if (!IsValidComponentID(key)) {
349 LOG(ERROR) << "Invalid component id: " << key;
350 continue;
351 }
352 string version;
353 if (!store.GetString(key, &version)) {
354 LOG(ERROR) << "Failed to get version for " << key
355 << " in product_components.";
356 continue;
357 }
358 product_components_args +=
359 base::StringPrintf("_%s.version=\"%s\" ",
360 key.c_str(),
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700361 XmlEncodeWithDefault(version).c_str());
Amin Hassani7fca2862019-03-28 16:09:22 -0700362 }
363 } else {
364 LOG(ERROR) << "Failed to parse product_components:\n"
365 << app_data.product_components;
366 }
367 }
368
Matt Ziegelbaumaa8e1a42019-05-09 21:41:58 -0400369 string requisition_arg;
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800370 if (!params->device_requisition().empty()) {
Matt Ziegelbaumaa8e1a42019-05-09 21:41:58 -0400371 requisition_arg = "requisition=\"" +
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800372 XmlEncodeWithDefault(params->device_requisition()) +
Matt Ziegelbaumaa8e1a42019-05-09 21:41:58 -0400373 "\" ";
374 }
375
Amin Hassani7fca2862019-03-28 16:09:22 -0700376 // clang-format off
377 string app_xml = " <app "
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700378 "appid=\"" + XmlEncodeWithDefault(app_data.id) + "\" " +
Amin Hassani7fca2862019-03-28 16:09:22 -0700379 app_cohort_args +
380 app_versions +
381 app_channels +
382 product_components_args +
383 fingerprint_arg +
384 buildtype_arg +
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800385 "board=\"" + XmlEncodeWithDefault(params->os_board()) + "\" " +
386 "hardware_class=\"" + XmlEncodeWithDefault(params->hwid()) + "\" " +
Jae Hoon Kim37d15372020-01-08 18:11:26 -0800387 "delta_okay=\"" + delta_okay_str + "\" " +
388 install_date_in_days_str +
389
390 // DLC excluded for installs and updates.
391 (app_data.is_dlc ? "" :
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800392 "lang=\"" + XmlEncodeWithDefault(params->app_lang(), "en-US") + "\" " +
Jae Hoon Kim37d15372020-01-08 18:11:26 -0800393 requisition_arg) +
394
Amin Hassani7fca2862019-03-28 16:09:22 -0700395 ">\n" +
396 app_body +
397 " </app>\n";
398 // clang-format on
399 return app_xml;
400}
401
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700402string OmahaRequestBuilderXml::GetOs() const {
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800403 const auto* params = SystemState::Get()->request_params();
Amin Hassani7fca2862019-03-28 16:09:22 -0700404 string os_xml =
405 " <os "
406 "version=\"" +
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800407 XmlEncodeWithDefault(params->os_version()) + "\" " + "platform=\"" +
408 XmlEncodeWithDefault(params->os_platform()) + "\" " + "sp=\"" +
409 XmlEncodeWithDefault(params->os_sp()) +
Amin Hassani7fca2862019-03-28 16:09:22 -0700410 "\">"
411 "</os>\n";
412 return os_xml;
413}
414
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700415string OmahaRequestBuilderXml::GetRequest() const {
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800416 const auto* params = SystemState::Get()->request_params();
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700417 string os_xml = GetOs();
418 string app_xml = GetApps();
Amin Hassani7fca2862019-03-28 16:09:22 -0700419
420 string request_xml = base::StringPrintf(
421 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Jae Hoon Kimedb65502019-06-14 11:52:17 -0700422 "<request requestid=\"%s\" sessionid=\"%s\""
Jae Hoon Kim6ada5912019-06-14 10:11:34 -0700423 " protocol=\"3.0\" updater=\"%s\" updaterversion=\"%s\""
Amin Hassani7fca2862019-03-28 16:09:22 -0700424 " installsource=\"%s\" ismachine=\"1\">\n%s%s</request>\n",
Jae Hoon Kim6ada5912019-06-14 10:11:34 -0700425 base::GenerateGUID().c_str() /* requestid */,
Jae Hoon Kimedb65502019-06-14 11:52:17 -0700426 session_id_.c_str(),
Amin Hassani7fca2862019-03-28 16:09:22 -0700427 constants::kOmahaUpdaterID,
428 kOmahaUpdaterVersion,
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800429 params->interactive() ? "ondemandupdate" : "scheduler",
Amin Hassani7fca2862019-03-28 16:09:22 -0700430 os_xml.c_str(),
431 app_xml.c_str());
432
433 return request_xml;
434}
435
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700436string OmahaRequestBuilderXml::GetApps() const {
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800437 const auto* params = SystemState::Get()->request_params();
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700438 string app_xml = "";
439 OmahaAppData product_app = {
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800440 .id = params->GetAppId(),
441 .version = params->app_version(),
442 .product_components = params->product_components(),
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700443 // Skips updatecheck for platform app in case of an install operation.
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800444 .skip_update = params->is_install(),
Andrewe045aef2020-01-08 16:29:22 -0800445 .is_dlc = false,
446
447 .app_params = {.active_counting_type = OmahaRequestParams::kDayBased,
448 .send_ping = include_ping_}};
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700449 app_xml += GetApp(product_app);
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800450 for (const auto& it : params->dlc_apps_params()) {
Amin Hassani2b68e6b2020-04-17 10:49:12 -0700451 OmahaAppData dlc_app_data = {
Andrewe045aef2020-01-08 16:29:22 -0800452 .id = it.first,
Amin Hassani9ed2cee2020-11-13 18:40:35 -0800453 .version = params->is_install() ? kNoVersion : params->app_version(),
Jae Hoon Kim37d15372020-01-08 18:11:26 -0800454 .skip_update = false,
Andrewe045aef2020-01-08 16:29:22 -0800455 .is_dlc = true,
456 .app_params = it.second};
Amin Hassani2b68e6b2020-04-17 10:49:12 -0700457 app_xml += GetApp(dlc_app_data);
Jae Hoon Kimb7ee3872019-06-06 14:59:03 -0700458 }
459 return app_xml;
460}
461
Amin Hassani7fca2862019-03-28 16:09:22 -0700462} // namespace chromeos_update_engine