update_engine: Enterprise channel downgrade

Powerwash and roll back when an enrolled user downgrades the channel:
- If the admin downgrades channel, check for ChannelDowngradebehavior
policy.
- If the user downgrades the channel, powerwash based on given boolean.

Add the "rollback" flag to the powerwash file to try to preserve some
data.

Note that this change is not affecting users yet: The
ChannelDowngradeBehavior policy is not available in DPanel and the UI
does not support chosing powerwash on channel downgrade for enrolled
users.

BUG=chromium:1122531
TEST=FEATURES=test emerge-amd64-generic update_engine
TEST=Set policy with YAPS and test on device

Change-Id: I2f02a6e752eed083b57484766f8e7ecc2eed7aca
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2397890
Tested-by: Miriam Polzer <mpolzer@google.com>
Commit-Queue: Miriam Polzer <mpolzer@google.com>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/update_attempter.cc b/update_attempter.cc
index 24562e2..14d5837 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -252,6 +252,7 @@
                              bool rollback_allowed,
                              bool rollback_data_save_requested,
                              int rollback_allowed_milestones,
+                             bool rollback_on_channel_downgrade,
                              bool obey_proxies,
                              bool interactive) {
   // This is normally called frequently enough so it's appropriate to use as a
@@ -290,6 +291,7 @@
                              rollback_allowed,
                              rollback_data_save_requested,
                              rollback_allowed_milestones,
+                             rollback_on_channel_downgrade,
                              obey_proxies,
                              interactive)) {
     return;
@@ -366,6 +368,7 @@
                                             bool rollback_allowed,
                                             bool rollback_data_save_requested,
                                             int rollback_allowed_milestones,
+                                            bool rollback_on_channel_downgrade,
                                             bool obey_proxies,
                                             bool interactive) {
   http_response_code_ = 0;
@@ -424,11 +427,9 @@
     LOG(INFO) << "No target channel mandated by policy.";
   } else {
     LOG(INFO) << "Setting target channel as mandated: " << target_channel;
-    // Pass in false for powerwash_allowed until we add it to the policy
-    // protobuf.
     string error_message;
     if (!omaha_request_params_->SetTargetChannel(
-            target_channel, false, &error_message)) {
+            target_channel, rollback_on_channel_downgrade, &error_message)) {
       LOG(ERROR) << "Setting the channel failed: " << error_message;
     }
 
@@ -1114,6 +1115,7 @@
            params.rollback_allowed,
            params.rollback_data_save_requested,
            params.rollback_allowed_milestones,
+           params.rollback_on_channel_downgrade,
            /*obey_proxies=*/false,
            params.interactive);
     // Always clear the forced app_version and omaha_url after an update attempt