update_engine: Move DaemonStateInterface implementation to UpdateAttempter
It seems like UpdateAttempter is the best option for implementation of
DaemonStateInterface. SystemState should only be doing state keeping not
doing these startup logics.
BUG=b:171829801
TEST=unittests
TEST=CQ passes
Change-Id: I47ec50107ffbeb544e061f39c900a1559f2cdcab
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2519843
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/cros/update_attempter.cc b/cros/update_attempter.cc
index e9098de..e417457 100644
--- a/cros/update_attempter.cc
+++ b/cros/update_attempter.cc
@@ -134,6 +134,10 @@
is_install_(false) {}
UpdateAttempter::~UpdateAttempter() {
+ // Prevent any DBus communication from UpdateAttempter when shutting down the
+ // daemon.
+ ClearObservers();
+
// CertificateChecker might not be initialized in unittests.
if (cert_checker_)
cert_checker_->SetObserver(nullptr);
@@ -177,6 +181,33 @@
return true;
}
+bool UpdateAttempter::StartUpdater() {
+ // Initiate update checks.
+ ScheduleUpdates();
+
+ auto update_boot_flags_action =
+ std::make_unique<UpdateBootFlagsAction>(system_state_->boot_control());
+ processor_->EnqueueAction(std::move(update_boot_flags_action));
+ // Update boot flags after 45 seconds.
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ActionProcessor::StartProcessing,
+ base::Unretained(processor_.get())),
+ base::TimeDelta::FromSeconds(45));
+
+ // Broadcast the update engine status on startup to ensure consistent system
+ // state on crashes.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&UpdateAttempter::BroadcastStatus, base::Unretained(this)));
+
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&UpdateAttempter::UpdateEngineStarted,
+ base::Unretained(this)));
+ return true;
+}
+
void UpdateAttempter::CertificateChecked(ServerToCheck server_to_check,
CertificateCheckResult result) {
system_state_->metrics_reporter()->ReportCertificateCheckMetrics(