update_engine: add variable for DeviceQuickFixBuildToken policy

This CL makes DeviceQuickFixBuildToken policy visible in update_manager
which would be used in a follow up CL to skip applying
DeviceAutoUpdateTimeRestrictions when a quick fix build token is set.
This CL also adds quick fix token in UpdateCheckParams which is used
by UpdateAttempter to pass the token in OmahaRequestParams.

BUG=chromium:1117450
TEST=FEATURES=test emerge-${BOARD} update_engine

Change-Id: If43ad8cd2955bbeb1cbd1dcacac79742fa0a6a20
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2521189
Commit-Queue: Saurabh Nijhara <snijhara@google.com>
Tested-by: Saurabh Nijhara <snijhara@google.com>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/omaha_request_params.cc b/cros/omaha_request_params.cc
index 0d69b24..adcfc75 100644
--- a/cros/omaha_request_params.cc
+++ b/cros/omaha_request_params.cc
@@ -122,6 +122,8 @@
 
   lts_tag_ = params.lts_tag;
 
+  autoupdate_token_ = params.quick_fix_build_token;
+
   rollback_allowed_ = params.rollback_allowed;
 
   // Set whether saving data over rollback is requested.
diff --git a/cros/omaha_request_params_unittest.cc b/cros/omaha_request_params_unittest.cc
index fbcd1a3..fdbb834 100644
--- a/cros/omaha_request_params_unittest.cc
+++ b/cros/omaha_request_params_unittest.cc
@@ -290,4 +290,9 @@
   EXPECT_EQ(expected_dlc_app_id, params_.GetDlcAppId(kDlcId));
 }
 
+TEST_F(OmahaRequestParamsTest, AutoUpdateTokenTest) {
+  EXPECT_TRUE(params_.Init("", "", {.quick_fix_build_token = "foo-token"}));
+  EXPECT_EQ("foo-token", params_.autoupdate_token());
+}
+
 }  // namespace chromeos_update_engine
diff --git a/cros/update_attempter.cc b/cros/update_attempter.cc
index 745272c..0291199 100644
--- a/cros/update_attempter.cc
+++ b/cros/update_attempter.cc
@@ -409,16 +409,6 @@
   // |omaha_request_params_| shall be made below this line.
   CalculateDlcParams();
 
-  // Set Quick Fix Build token if policy is set and the device is enterprise
-  // enrolled.
-  string token;
-  if (SystemState::Get()->device_policy()) {
-    if (!SystemState::Get()->device_policy()->GetDeviceQuickFixBuildToken(
-            &token))
-      token.clear();
-  }
-  omaha_request_params_->set_autoupdate_token(token);
-
   LOG(INFO) << "target_version_prefix = "
             << omaha_request_params_->target_version_prefix()
             << ", rollback_allowed = "
diff --git a/cros/update_attempter.h b/cros/update_attempter.h
index 09e613f..3678707 100644
--- a/cros/update_attempter.h
+++ b/cros/update_attempter.h
@@ -289,6 +289,7 @@
   FRIEND_TEST(UpdateAttempterTest, UpdateDeferredByPolicyTest);
   FRIEND_TEST(UpdateAttempterTest, UpdateIsNotRunningWhenUpdateAvailable);
   FRIEND_TEST(UpdateAttempterTest, GetSuccessfulDlcIds);
+  FRIEND_TEST(UpdateAttempterTest, QuickFixTokenWhenDeviceIsEnterpriseEnrolled);
 
   // Returns the special flags to be added to ErrorCode values based on the
   // parameters used in the current update attempt.
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc
index ab4a5f2..b348d50 100644
--- a/cros/update_attempter_unittest.cc
+++ b/cros/update_attempter_unittest.cc
@@ -288,7 +288,6 @@
   void SessionIdTestEnforceEmptyStrPingOmaha();
   void SessionIdTestConsistencyInUpdateFlow();
   void SessionIdTestInDownloadAction();
-  void UpdateToQuickFixBuildStart(bool set_token);
   void ResetRollbackHappenedStart(bool is_consumer,
                                   bool is_policy_available,
                                   bool expected_reset);
@@ -2153,43 +2152,14 @@
   TestProcessingDone();
 }
 
-void UpdateAttempterTest::UpdateToQuickFixBuildStart(bool set_token) {
-  // Tests that checks if |device_quick_fix_build_token| arrives when
-  // policy is set and the device is enterprise enrolled based on |set_token|.
-  string token = set_token ? "some_token" : "";
-  auto device_policy = std::make_unique<policy::MockDevicePolicy>();
-  FakeSystemState::Get()->set_device_policy(device_policy.get());
-  EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
+TEST_F(UpdateAttempterTest, QuickFixTokenWhenDeviceIsEnterpriseEnrolled) {
+  attempter_.CalculateUpdateParams({.quick_fix_build_token = "token"});
+  EXPECT_EQ("token",
+            FakeSystemState::Get()->request_params()->autoupdate_token());
 
-  if (set_token)
-    EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_))
-        .WillOnce(DoAll(SetArgPointee<0>(token), Return(true)));
-  else
-    EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_))
-        .WillOnce(Return(false));
-  attempter_.policy_provider_.reset(
-      new policy::PolicyProvider(std::move(device_policy)));
-  attempter_.Update({});
-
-  EXPECT_EQ(token, attempter_.omaha_request_params_->autoupdate_token());
-  ScheduleQuitMainLoop();
-}
-
-TEST_F(UpdateAttempterTest,
-       QuickFixTokenWhenDeviceIsEnterpriseEnrolledAndPolicyIsSet) {
-  loop_.PostTask(FROM_HERE,
-                 base::Bind(&UpdateAttempterTest::UpdateToQuickFixBuildStart,
-                            base::Unretained(this),
-                            /*set_token=*/true));
-  loop_.Run();
-}
-
-TEST_F(UpdateAttempterTest, EmptyQuickFixToken) {
-  loop_.PostTask(FROM_HERE,
-                 base::Bind(&UpdateAttempterTest::UpdateToQuickFixBuildStart,
-                            base::Unretained(this),
-                            /*set_token=*/false));
-  loop_.Run();
+  attempter_.CalculateUpdateParams({});
+  EXPECT_TRUE(
+      FakeSystemState::Get()->request_params()->autoupdate_token().empty());
 }
 
 TEST_F(UpdateAttempterTest, ScheduleUpdateSpamHandlerTest) {