Send an initial status update notification on bind().

When the client calls bind(), this patch now sends an initial status
update so the client can react to the status update that could have
been sent before it called bind().

Bug: 27108108
TEST=`update_engine_client --follow` shows the initial status.

Change-Id: Ifbf056ebb66da17c9e60244561340b3e1ccd4232
diff --git a/binder_service_android.cc b/binder_service_android.cc
index 3c679da..e275319 100644
--- a/binder_service_android.cc
+++ b/binder_service_android.cc
@@ -45,8 +45,10 @@
     update_engine::UpdateStatus status,
     const std::string& /* new_version  */,
     int64_t /* new_size */) {
+  last_status_ = static_cast<int>(status);
+  last_progress_ = progress;
   for (auto& callback : callbacks_) {
-    callback->onStatusUpdate(static_cast<int>(status), progress);
+    callback->onStatusUpdate(last_status_, last_progress_);
   }
 }
 
@@ -68,6 +70,12 @@
                  base::Unretained(this),
                  base::Unretained(callback.get())));
 
+  // Send an status update on connection (except when no update sent so far),
+  // since the status update is oneway and we don't need to wait for the
+  // response.
+  if (last_status_ != -1)
+    callback->onStatusUpdate(last_status_, last_progress_);
+
   *return_value = true;
   return Status::ok();
 }
diff --git a/binder_service_android.h b/binder_service_android.h
index 3e256e0..0a82b82 100644
--- a/binder_service_android.h
+++ b/binder_service_android.h
@@ -76,6 +76,11 @@
   // List of currently bound callbacks.
   std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_;
 
+  // Cached copy of the last status update sent. Used to send an initial
+  // notification when bind() is called from the client.
+  int last_status_{-1};
+  double last_progress_{0.0};
+
   ServiceDelegateAndroidInterface* service_delegate_;
 };
 
diff --git a/daemon_state_android.cc b/daemon_state_android.cc
index 6a5aa9f..cf1e892 100644
--- a/daemon_state_android.cc
+++ b/daemon_state_android.cc
@@ -61,7 +61,6 @@
   // Initialize the UpdateAttempter before the UpdateManager.
   update_attempter_.reset(new UpdateAttempterAndroid(
       this, prefs_.get(), boot_control_.get(), hardware_.get()));
-  update_attempter_->Init();
 
   return true;
 }
@@ -69,6 +68,7 @@
 bool DaemonStateAndroid::StartUpdater() {
   // The DaemonState in Android is a passive daemon. It will only start applying
   // an update when instructed to do so from the exposed binder API.
+  update_attempter_->Init();
   return true;
 }
 
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index 561534c..f7bcab1 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -86,9 +86,9 @@
   // In case of update_engine restart without a reboot we need to restore the
   // reboot needed state.
   if (UpdateCompletedOnThisBoot())
-    status_ = UpdateStatus::UPDATED_NEED_REBOOT;
+    SetStatusAndNotify(UpdateStatus::UPDATED_NEED_REBOOT);
   else
-    status_ = UpdateStatus::IDLE;
+    SetStatusAndNotify(UpdateStatus::IDLE);
 }
 
 bool UpdateAttempterAndroid::ApplyPayload(