update_engine: Save and reload ping prefs from powerwash prefs.
Improve device active accuracy by updating prefs with last ping time.
Check if |kPrefsLastActivePingDay| and |kPrefsLastRollCallPingDay|
were preserved after powerwash and move to prefs if the key
does not already exist. Delete from powerwash to preserve user
privacy.
BUG=b:173145783
TEST=FEATURES=test emerge-{board} update_engine
Cq-Depend: chromium:2558521
Change-Id: I2f71d767ac90b5214c1f0e988137277e4fbe8ec3
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2558010
Tested-by: Vyshu Khota <vyshu@google.com>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/update_attempter_unittest.cc b/cros/update_attempter_unittest.cc
index b4fcdf2..a11e00c 100644
--- a/cros/update_attempter_unittest.cc
+++ b/cros/update_attempter_unittest.cc
@@ -2448,4 +2448,34 @@
EXPECT_THAT(attempter_.GetSuccessfulDlcIds(), ElementsAre(dlc_2));
}
+TEST_F(UpdateAttempterTest, MoveToPrefs) {
+ string key1 = kPrefsLastActivePingDay;
+ string key2 = kPrefsPingLastRollcall;
+
+ FakePrefs fake_prefs;
+ EXPECT_TRUE(fake_prefs.SetString(key2, "current-rollcall"));
+ FakeSystemState::Get()->set_prefs(&fake_prefs);
+
+ FakePrefs powerwash_safe_prefs;
+ EXPECT_TRUE(powerwash_safe_prefs.SetString(key1, "powerwash-last-active"));
+ EXPECT_TRUE(powerwash_safe_prefs.SetString(key2, "powerwash-last-rollcall"));
+ FakeSystemState::Get()->set_powerwash_safe_prefs(&powerwash_safe_prefs);
+
+ attempter_.Init();
+ attempter_.MoveToPrefs({key1, key2});
+
+ string pref_value_1;
+ fake_prefs.GetString(key1, &pref_value_1);
+ EXPECT_EQ(pref_value_1, "powerwash-last-active");
+ // Do not overwrite if value already exists.
+ string pref_value_2;
+ fake_prefs.GetString(key2, &pref_value_2);
+ EXPECT_EQ(pref_value_2, "current-rollcall");
+
+ // Make sure keys are deleted from powerwash safe prefs regardless of whether
+ // they are written to prefs.
+ EXPECT_FALSE(FakeSystemState::Get()->powerwash_safe_prefs()->Exists(key1));
+ EXPECT_FALSE(FakeSystemState::Get()->powerwash_safe_prefs()->Exists(key2));
+}
+
} // namespace chromeos_update_engine