update_engine: Use PrefsInterface from SystemState

There is no need to pass the Pref class around (at least not in cros)
since we have the SystemState as the global context and we can get the
pref from there.

BUG=b:171829801
TEST=cros_workon_make --board reef --test update_engine

Change-Id: I9f5fb8a118fab2ef0e188c42f746dafb1094972c
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2548740
Tested-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/omaha_request_action.cc b/cros/omaha_request_action.cc
index f847194..d67623f 100644
--- a/cros/omaha_request_action.cc
+++ b/cros/omaha_request_action.cc
@@ -346,10 +346,7 @@
 
 // static
 int OmahaRequestAction::GetInstallDate() {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-  if (prefs == nullptr)
-    return -1;
-
+  auto* prefs = SystemState::Get()->prefs();
   // If we have the value stored on disk, just return it.
   int64_t stored_value;
   if (prefs->GetInt64(kPrefsInstallDateDays, &stored_value)) {
@@ -422,7 +419,7 @@
     if (!dlc_params.send_ping)
       continue;
 
-    PrefsInterface* prefs = SystemState::Get()->prefs();
+    auto* prefs = SystemState::Get()->prefs();
     // Reset the active metadata value to |kPingInactiveValue|.
     auto active_key =
         prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive});
@@ -518,7 +515,7 @@
 
 // Update the last ping day preferences based on the server daystart
 // response. Returns true on success, false otherwise.
-bool UpdateLastPingDays(OmahaParserData* parser_data, PrefsInterface* prefs) {
+bool UpdateLastPingDays(OmahaParserData* parser_data) {
   int64_t elapsed_seconds = 0;
   TEST_AND_RETURN_FALSE(base::StringToInt64(
       parser_data->daystart_elapsed_seconds, &elapsed_seconds));
@@ -526,6 +523,7 @@
 
   // Remember the local time that matches the server's last midnight
   // time.
+  auto* prefs = SystemState::Get()->prefs();
   Time daystart = Time::Now() - TimeDelta::FromSeconds(elapsed_seconds);
   prefs->SetInt64(kPrefsLastActivePingDay, daystart.ToInternalValue());
   prefs->SetInt64(kPrefsLastRollCallPingDay, daystart.ToInternalValue());
@@ -976,7 +974,7 @@
   // Update the last ping day preferences based on the server daystart response
   // even if we didn't send a ping. Omaha always includes the daystart in the
   // response, but log the error if it didn't.
-  LOG_IF(ERROR, !UpdateLastPingDays(&parser_data, SystemState::Get()->prefs()))
+  LOG_IF(ERROR, !UpdateLastPingDays(&parser_data))
       << "Failed to update the last ping day preferences!";
 
   // Sets first_active_omaha_ping_sent to true (vpd in CrOS). We only do this if
@@ -1357,11 +1355,7 @@
 
 // static
 bool OmahaRequestAction::HasInstallDate() {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-  if (prefs == nullptr)
-    return false;
-
-  return prefs->Exists(kPrefsInstallDateDays);
+  return SystemState::Get()->prefs()->Exists(kPrefsInstallDateDays);
 }
 
 // static
@@ -1370,10 +1364,7 @@
     InstallDateProvisioningSource source) {
   TEST_AND_RETURN_FALSE(install_date_days >= 0);
 
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-  if (prefs == nullptr)
-    return false;
-
+  auto* prefs = SystemState::Get()->prefs();
   if (!prefs->SetInt64(kPrefsInstallDateDays, install_date_days))
     return false;
 
@@ -1417,7 +1408,7 @@
                      << " as it is not in the request params.";
         continue;
       }
-      PrefsInterface* prefs = SystemState::Get()->prefs();
+      auto* prefs = SystemState::Get()->prefs();
       PersistCohortData(
           prefs->CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsOmahaCohort}),
           app.cohort);
@@ -1561,16 +1552,8 @@
 
 bool OmahaRequestAction::IsUpdateAllowedOverCellularByPrefs(
     const OmahaResponse& response) const {
-  PrefsInterface* prefs = SystemState::Get()->prefs();
-
-  if (!prefs) {
-    LOG(INFO) << "Disabling updates over cellular as the preferences are "
-                 "not available.";
-    return false;
-  }
-
+  auto* prefs = SystemState::Get()->prefs();
   bool is_allowed;
-
   if (prefs->Exists(kPrefsUpdateOverCellularPermission) &&
       prefs->GetBoolean(kPrefsUpdateOverCellularPermission, &is_allowed) &&
       is_allowed) {