update_engine: Make SystemState accessible from everywhere
SystemState is supposed to be a global context and is used lamost
everywhere. So instead of passing it to functions and keeping multiple
pointers to it, its better to do what we did in dlcservice and make it a
singleton class with a getter that can be get from everywhere.
BUG=b:171829801
TEST=unittests
Change-Id: I3b2de9394b7769b3911195ca52d61dbe49afd4dd
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2521792
Commit-Queue: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/connection_manager.cc b/cros/connection_manager.cc
index 331f76b..6a5c63b 100644
--- a/cros/connection_manager.cc
+++ b/cros/connection_manager.cc
@@ -41,16 +41,14 @@
namespace chromeos_update_engine {
namespace connection_manager {
-std::unique_ptr<ConnectionManagerInterface> CreateConnectionManager(
- SystemState* system_state) {
+std::unique_ptr<ConnectionManagerInterface> CreateConnectionManager() {
return std::unique_ptr<ConnectionManagerInterface>(
- new ConnectionManager(new ShillProxy(), system_state));
+ new ConnectionManager(new ShillProxy()));
}
} // namespace connection_manager
-ConnectionManager::ConnectionManager(ShillProxyInterface* shill_proxy,
- SystemState* system_state)
- : shill_proxy_(shill_proxy), system_state_(system_state) {}
+ConnectionManager::ConnectionManager(ShillProxyInterface* shill_proxy)
+ : shill_proxy_(shill_proxy) {}
bool ConnectionManager::IsUpdateAllowedOver(
ConnectionType type, ConnectionTethering tethering) const {
@@ -64,15 +62,16 @@
<< "Current connection is confirmed tethered, using Cellular setting.";
}
- const policy::DevicePolicy* device_policy = system_state_->device_policy();
+ const policy::DevicePolicy* device_policy =
+ SystemState::Get()->device_policy();
// The device_policy is loaded in a lazy way before an update check. Load
// it now from the libbrillo cache if it wasn't already loaded.
if (!device_policy) {
- UpdateAttempter* update_attempter = system_state_->update_attempter();
+ UpdateAttempter* update_attempter = SystemState::Get()->update_attempter();
if (update_attempter) {
update_attempter->RefreshDevicePolicy();
- device_policy = system_state_->device_policy();
+ device_policy = SystemState::Get()->device_policy();
}
}
@@ -109,7 +108,8 @@
}
bool ConnectionManager::IsAllowedConnectionTypesForUpdateSet() const {
- const policy::DevicePolicy* device_policy = system_state_->device_policy();
+ const policy::DevicePolicy* device_policy =
+ SystemState::Get()->device_policy();
if (!device_policy) {
LOG(INFO) << "There's no device policy loaded yet.";
return false;