Blacklist versions as part of Rollback along with unittests.

This CL adds version blacklisting as part of AU Rollback. A few additional
things:

1) Since this pref must persist across rollback I have introduced a
powerwash_safe_prefs as part of system_state that will persist across
powerwashes.
2) Fixed bug where we needed to read the device policy (which is read during an
update_check before Rollback would work).
3) Some refactoring to move pref constants to constants.
4) Passing keepimg into our powerwash command so we don't wipe the old
partitions.

BUG=chromium:252589 chromium:254217
TEST=Unittests + test on device + using rollback with and without powerwash
checking preserve state.

Change-Id: I991fad944594944425fd9941e10b30a919f2b83b
Reviewed-on: https://gerrit.chromium.org/gerrit/59518
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Chris Sosa <sosa@chromium.org>
diff --git a/omaha_response_handler_action_unittest.cc b/omaha_response_handler_action_unittest.cc
index 3516cd6..f3b4b99 100644
--- a/omaha_response_handler_action_unittest.cc
+++ b/omaha_response_handler_action_unittest.cc
@@ -59,6 +59,7 @@
     "very_long_name_and_no_slashes-very_long_name_and_no_slashes"
     "very_long_name_and_no_slashes-very_long_name_and_no_slashes"
     "-the_update_a.b.c.d_DELTA_.tgz";
+const string kBadVersion = "don't update me";
 }  // namespace {}
 
 bool OmahaResponseHandlerActionTest::DoTestCommon(
@@ -72,7 +73,7 @@
 
   ObjectFeederAction<OmahaResponse> feeder_action;
   feeder_action.set_obj(in);
-  if (in.update_exists) {
+  if (in.update_exists and in.version != kBadVersion) {
     EXPECT_CALL(*(mock_system_state->mock_prefs()),
                 SetString(kPrefsUpdateCheckResponseHash, in.hash))
         .WillOnce(Return(true));
@@ -81,6 +82,8 @@
   string current_url = in.payload_urls.size() ? in.payload_urls[0] : "";
   EXPECT_CALL(*(mock_system_state->mock_payload_state()), GetCurrentUrl())
       .WillRepeatedly(Return(current_url));
+  EXPECT_CALL(*(mock_system_state->mock_payload_state()), GetRollbackVersion())
+        .WillRepeatedly(Return(kBadVersion));
 
   OmahaResponseHandlerAction response_handler_action(mock_system_state);
   response_handler_action.set_boot_device(boot_dev);
@@ -187,6 +190,31 @@
   EXPECT_EQ("", install_plan.install_path);
 }
 
+TEST_F(OmahaResponseHandlerActionTest, RollbackVersionTest) {
+  string version_ok = "124.0.0";
+
+  InstallPlan install_plan;
+  OmahaResponse in;
+  in.update_exists = true;
+  in.version = kBadVersion;
+  in.payload_urls.push_back("http://foo/the_update_a.b.c.d.tgz");
+  in.more_info_url = "http://more/info";
+  in.hash = "HASHj+";
+  in.size = 12;
+  in.prompt = true;
+
+  // Version is blacklisted for first call so no update.
+  EXPECT_FALSE(DoTest(in, "/dev/sda5", &install_plan));
+  EXPECT_EQ("", install_plan.download_url);
+  EXPECT_EQ("", install_plan.payload_hash);
+  EXPECT_EQ("", install_plan.install_path);
+
+  // Version isn't blacklisted.
+  in.version = version_ok;
+  EXPECT_TRUE(DoTest(in, "/dev/sda5", &install_plan));
+  EXPECT_EQ(in.payload_urls[0], install_plan.download_url);
+}
+
 TEST_F(OmahaResponseHandlerActionTest, HashChecksForHttpTest) {
   OmahaResponse in;
   in.update_exists = true;