Revert "Implement Android UE daemon using brillo::Daemon."

This reverts commit c180400937eac75e8b7119f68d44593713dd4557.

This breaks both AOSP and Chrome OS

Change-Id: Ie9686a4d03a8fd53a614ed1706e3268918c414fb
diff --git a/daemon.cc b/daemon.cc
index 838c407..cc528a4 100644
--- a/daemon.cc
+++ b/daemon.cc
@@ -24,16 +24,15 @@
 #if USE_WEAVE || USE_BINDER
 #include <binderwrapper/binder_wrapper.h>
 #endif  // USE_WEAVE || USE_BINDER
+#include <brillo/message_loops/message_loop.h>
 
-#ifdef __BRILLO__
 #include "update_engine/update_attempter.h"
-#endif  // __BRILLO__
 
-#if USE_DBUS
+using brillo::MessageLoop;
+
 namespace {
 const int kDBusSystemMaxWaitSeconds = 2 * 60;
 }  // namespace
-#endif // USE_DBUS
 
 namespace chromeos_update_engine {
 
@@ -51,7 +50,6 @@
   binder_watcher_.Init();
 #endif  // USE_WEAVE || USE_BINDER
 
-#if USE_DBUS
   // We wait for the D-Bus connection for up two minutes to avoid re-spawning
   // the daemon too fast causing thrashing if dbus-daemon is not running.
   scoped_refptr<dbus::Bus> bus = dbus_connection_.ConnectWithTimeout(
@@ -65,34 +63,26 @@
   }
 
   CHECK(bus->SetUpAsyncOperations());
-#endif // USE_DBUS
 
-#ifdef __BRILLO__
   // Initialize update engine global state but continue if something fails.
   real_system_state_.reset(new RealSystemState(bus));
   LOG_IF(ERROR, !real_system_state_->Initialize())
       << "Failed to initialize system state.";
   UpdateAttempter* update_attempter = real_system_state_->update_attempter();
   CHECK(update_attempter);
-#else  // !defined(__BRILLO__)
-  //TODO(deymo): Initialize non-Brillo state.
-#endif // defined(__BRILLO__)
 
 #if USE_BINDER
-  // Create the Binder Service.
-#ifdef __BRILLO__
+  // Create the Binder Service
   service_ = new BinderUpdateEngineService{real_system_state_.get()};
-#else  // !defined(__BRILLO__)
-  service_ = new BinderUpdateEngineAndroidService{};
-#endif // defined(__BRILLO__)
   auto binder_wrapper = android::BinderWrapper::Get();
+  sleep(10);
   if (!binder_wrapper->RegisterService("android.brillo.UpdateEngineService",
                                        service_)) {
     LOG(ERROR) << "Failed to register binder service.";
   }
+
 #endif  // USE_BINDER
 
-#if USE_DBUS
   // Create the DBus service.
   dbus_adaptor_.reset(new UpdateEngineAdaptor(real_system_state_.get(), bus));
   update_attempter->set_dbus_adaptor(dbus_adaptor_.get());
@@ -100,17 +90,9 @@
   dbus_adaptor_->RegisterAsync(base::Bind(&UpdateEngineDaemon::OnDBusRegistered,
                                           base::Unretained(this)));
   LOG(INFO) << "Waiting for DBus object to be registered.";
-#else  // !USE_DBUS
-#ifdef __BRILLO__
-  real_system_state_->StartUpdater();
-#else  // !defined(__BRILLO__)
-  // TODO(deymo): Start non-Brillo service.
-#endif // defined(__BRILLO__)
-#endif // USE_DBUS
   return EX_OK;
 }
 
-#if USE_DBUS
 void UpdateEngineDaemon::OnDBusRegistered(bool succeeded) {
   if (!succeeded) {
     LOG(ERROR) << "Registering the UpdateEngineAdaptor";
@@ -127,8 +109,30 @@
     QuitWithExitCode(1);
     return;
   }
-  real_system_state_->StartUpdater();
+
+  // Initiate update checks.
+  UpdateAttempter* update_attempter = real_system_state_->update_attempter();
+  update_attempter->ScheduleUpdates();
+
+  // Update boot flags after 45 seconds.
+  MessageLoop::current()->PostDelayedTask(
+      FROM_HERE,
+      base::Bind(&UpdateAttempter::UpdateBootFlags,
+                 base::Unretained(update_attempter)),
+      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(update_attempter)));
+
+  // Run the UpdateEngineStarted() method on |update_attempter|.
+  MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+      &UpdateAttempter::UpdateEngineStarted,
+      base::Unretained(update_attempter)));
+
+  LOG(INFO) << "Finished initialization. Now running the loop.";
 }
-#endif  // USE_DBUS
 
 }  // namespace chromeos_update_engine