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/common_service.cc b/cros/common_service.cc
index df63bca..e5ee828 100644
--- a/cros/common_service.cc
+++ b/cros/common_service.cc
@@ -218,12 +218,11 @@
bool UpdateEngineService::SetCohortHint(ErrorPtr* error,
const string& in_cohort_hint) {
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
// It is ok to override the cohort hint with an invalid value since it is
// stored in stateful partition. The code reading it should sanitize it
// anyway.
- if (!prefs->SetString(kPrefsOmahaCohortHint, in_cohort_hint)) {
+ if (!SystemState::Get()->prefs()->SetString(kPrefsOmahaCohortHint,
+ in_cohort_hint)) {
LogAndSetError(
error,
FROM_HERE,
@@ -236,8 +235,7 @@
bool UpdateEngineService::GetCohortHint(ErrorPtr* error,
string* out_cohort_hint) {
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
+ const auto* prefs = SystemState::Get()->prefs();
*out_cohort_hint = "";
if (prefs->Exists(kPrefsOmahaCohortHint) &&
!prefs->GetString(kPrefsOmahaCohortHint, out_cohort_hint)) {
@@ -249,9 +247,7 @@
bool UpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
bool in_enabled) {
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
- if (!prefs->SetBoolean(kPrefsP2PEnabled, in_enabled)) {
+ if (!SystemState::Get()->prefs()->SetBoolean(kPrefsP2PEnabled, in_enabled)) {
LogAndSetError(
error,
FROM_HERE,
@@ -264,8 +260,7 @@
bool UpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
bool* out_enabled) {
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
+ const auto* prefs = SystemState::Get()->prefs();
bool p2p_pref = false; // Default if no setting is present.
if (prefs->Exists(kPrefsP2PEnabled) &&
!prefs->GetBoolean(kPrefsP2PEnabled, &p2p_pref)) {
@@ -293,11 +288,8 @@
// If the policy wasn't loaded yet, then it is still OK to change the local
// setting because the policy will be checked again during the update check.
-
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
- if (!prefs ||
- !prefs->SetBoolean(kPrefsUpdateOverCellularPermission, in_allowed)) {
+ if (!SystemState::Get()->prefs()->SetBoolean(
+ kPrefsUpdateOverCellularPermission, in_allowed)) {
LogAndSetError(error,
FROM_HERE,
string("Error setting the update over cellular to ") +
@@ -326,10 +318,8 @@
// If the policy wasn't loaded yet, then it is still OK to change the local
// setting because the policy will be checked again during the update check.
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
- if (!prefs ||
- !prefs->SetString(kPrefsUpdateOverCellularTargetVersion,
+ auto* prefs = SystemState::Get()->prefs();
+ if (!prefs->SetString(kPrefsUpdateOverCellularTargetVersion,
target_version) ||
!prefs->SetInt64(kPrefsUpdateOverCellularTargetSize, target_size)) {
LogAndSetError(
@@ -349,9 +339,8 @@
*out_allowed = connection_manager->IsUpdateAllowedOver(
ConnectionType::kCellular, ConnectionTethering::kUnknown);
} else {
- PrefsInterface* prefs = SystemState::Get()->prefs();
-
- if (!prefs || !prefs->Exists(kPrefsUpdateOverCellularPermission)) {
+ const auto* prefs = SystemState::Get()->prefs();
+ if (!prefs->Exists(kPrefsUpdateOverCellularPermission)) {
// Update is not allowed as user preference is not set or not available.
*out_allowed = false;
return true;