update_engine: Make policy UpdateCheckParams processing easier
Currently there are a ton of arguments from UpdateCheckParams that is
passed around in the udpate_attampter.cc. With this CL UpdateCheckParams
is directy passed and this simplies the logic.
BUG=b:171829801
TEST=cros_workon_make --board reef --test update_enigne
Change-Id: If454f6393fc6e28d41fa5d14d184f0db32e8bd19
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2504453
Commit-Queue: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/omaha_request_params.cc b/omaha_request_params.cc
index 8a2e3dc..79d19e8 100644
--- a/omaha_request_params.cc
+++ b/omaha_request_params.cc
@@ -37,9 +37,11 @@
#include "update_engine/common/platform_constants.h"
#include "update_engine/common/utils.h"
#include "update_engine/system_state.h"
+#include "update_engine/update_manager/policy.h"
#define CALL_MEMBER_FN(object, member) ((object).*(member))
+using chromeos_update_manager::UpdateCheckParams;
using std::string;
namespace chromeos_update_engine {
@@ -59,9 +61,9 @@
test::SetImagePropertiesRootPrefix(nullptr);
}
-bool OmahaRequestParams::Init(const string& in_app_version,
- const string& in_update_url,
- bool in_interactive) {
+bool OmahaRequestParams::Init(const string& app_version,
+ const string& update_url,
+ const UpdateCheckParams& params) {
LOG(INFO) << "Initializing parameters for this update attempt";
image_props_ = LoadImageProperties(system_state_);
mutable_image_props_ = LoadMutableImageProperties(system_state_);
@@ -77,15 +79,15 @@
os_platform_ = constants::kOmahaPlatformName;
if (!image_props_.system_version.empty()) {
- if (in_app_version == "ForcedUpdate") {
- image_props_.system_version = in_app_version;
+ if (app_version == "ForcedUpdate") {
+ image_props_.system_version = app_version;
}
os_version_ = image_props_.system_version;
} else {
os_version_ = OmahaRequestParams::kOsVersion;
}
- if (!in_app_version.empty())
- image_props_.version = in_app_version;
+ if (!app_version.empty())
+ image_props_.version = app_version;
os_sp_ = image_props_.version + "_" + GetMachineType();
app_lang_ = "en-US";
@@ -115,17 +117,51 @@
delta_okay_ = false;
}
- if (in_update_url.empty())
+ if (update_url.empty())
update_url_ = image_props_.omaha_url;
else
- update_url_ = in_update_url;
+ update_url_ = update_url;
// Set the interactive flag accordingly.
- interactive_ = in_interactive;
+ interactive_ = params.interactive;
dlc_apps_params_.clear();
// Set false so it will do update by default.
is_install_ = false;
+
+ target_version_prefix_ = params.target_version_prefix;
+
+ lts_tag_ = params.lts_tag;
+
+ rollback_allowed_ = params.rollback_allowed;
+
+ // Set whether saving data over rollback is requested.
+ rollback_data_save_requested_ = params.rollback_data_save_requested;
+
+ // Set how many milestones of rollback are allowed.
+ rollback_allowed_milestones_ = params.rollback_allowed_milestones;
+
+ // Set the target channel, if one was provided.
+ if (params.target_channel.empty()) {
+ LOG(INFO) << "No target channel mandated by policy.";
+ } else {
+ LOG(INFO) << "Setting target channel as mandated: "
+ << params.target_channel;
+ string error_message;
+ if (!SetTargetChannel(params.target_channel,
+ params.rollback_on_channel_downgrade,
+ &error_message)) {
+ LOG(ERROR) << "Setting the channel failed: " << error_message;
+ }
+
+ // Since this is the beginning of a new attempt, update the download
+ // channel. The download channel won't be updated until the next attempt,
+ // even if target channel changes meanwhile, so that how we'll know if we
+ // should cancel the current download attempt if there's such a change in
+ // target channel.
+ UpdateDownloadChannel();
+ }
+
return true;
}