update_engine: Persist EOL date continously
Need to not delete the old EOL date persisted file in the case that
Omaha does not send EOL date attribute. Previous approach of clearing
could cause unexpected behavior where a previously persisted EOL date is
removed when it shouldn't be.
BUG=chromium:1022550
TEST=FEATURES="test" P2_TEST_FILTER="*OmahaRequestActionTest.*-*RunAsRoot*" emerge-$B update_engine
Change-Id: I1c491951496377940c8f1592d5451c181bc81508
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1904628
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Regan Hsu <hsuregan@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
Auto-Submit: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index 6ebab0d..f25f8ee 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -1318,11 +1318,12 @@
}
bool OmahaRequestAction::PersistEolInfo(const map<string, string>& attrs) {
+ // If EOL date attribute is not sent, don't delete the old persisted EOL
+ // date information.
auto eol_date_attr = attrs.find(kAttrEolDate);
- if (eol_date_attr == attrs.end()) {
- system_state_->prefs()->Delete(kPrefsOmahaEolDate);
- } else if (!system_state_->prefs()->SetString(kPrefsOmahaEolDate,
- eol_date_attr->second)) {
+ if (eol_date_attr != attrs.end() &&
+ !system_state_->prefs()->SetString(kPrefsOmahaEolDate,
+ eol_date_attr->second)) {
LOG(ERROR) << "Setting EOL date failed.";
return false;
}
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index b66375f..8dcec04 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -2815,11 +2815,15 @@
tuc_params_.expected_check_result = metrics::CheckResult::kNoUpdateAvailable;
tuc_params_.expected_check_reaction = metrics::CheckReaction::kUnset;
+ const string kDate = "123";
+ fake_system_state_.prefs()->SetString(kPrefsOmahaEolDate, kDate);
+
ASSERT_TRUE(TestUpdateCheck());
string eol_date;
- EXPECT_FALSE(
+ EXPECT_TRUE(
fake_system_state_.prefs()->GetString(kPrefsOmahaEolDate, &eol_date));
+ EXPECT_EQ(kDate, eol_date);
}
TEST_F(OmahaRequestActionTest, PersistEolBadDateTest) {