Add stubs for UpdateEngine.CleanupSuccessfulUpdate

This API waits for merge to finish after rebooting to
the new Virtual A/B build.

Test: pass
Bug: 138808328
Change-Id: I9422f0ffb1876b71ab45e994fc2d5c76d9ec3a75
diff --git a/binder_bindings/android/os/IUpdateEngine.aidl b/binder_bindings/android/os/IUpdateEngine.aidl
index 8a5ec71..bbb86a3 100644
--- a/binder_bindings/android/os/IUpdateEngine.aidl
+++ b/binder_bindings/android/os/IUpdateEngine.aidl
@@ -58,4 +58,12 @@
    */
   long allocateSpaceForPayload(in String metadataFilename,
                                in String[] headerKeyValuePairs);
+  /** @hide
+   *
+   * Wait for merge to finish, and clean up necessary files.
+   *
+   * @return SUCCESS if successful. ERROR if transient errors (e.g. merged but
+   * needs reboot). DEVICE_CORRUPTED for permanent errors.
+   */
+  int cleanupSuccessfulUpdate();
 }
diff --git a/binder_service_android.cc b/binder_service_android.cc
index 214801b..c376f4e 100644
--- a/binder_service_android.cc
+++ b/binder_service_android.cc
@@ -214,7 +214,15 @@
           payload_metadata, str_headers, &error));
   if (error != nullptr)
     return ErrorPtrToStatus(error);
+  return Status::ok();
+}
 
+Status BinderUpdateEngineAndroidService::cleanupSuccessfulUpdate(
+    int32_t* return_value) {
+  brillo::ErrorPtr error;
+  *return_value = service_delegate_->CleanupSuccessfulUpdate(&error);
+  if (error != nullptr)
+    return ErrorPtrToStatus(error);
   return Status::ok();
 }
 
diff --git a/binder_service_android.h b/binder_service_android.h
index 5207075..1c38d2b 100644
--- a/binder_service_android.h
+++ b/binder_service_android.h
@@ -74,6 +74,8 @@
       const android::String16& metadata_filename,
       const std::vector<android::String16>& header_kv_pairs,
       int64_t* return_value) override;
+  android::binder::Status cleanupSuccessfulUpdate(
+      int32_t* return_value) override;
 
  private:
   // Remove the passed |callback| from the list of registered callbacks. Called
diff --git a/service_delegate_android_interface.h b/service_delegate_android_interface.h
index 7f0169e..a12f1e8 100644
--- a/service_delegate_android_interface.h
+++ b/service_delegate_android_interface.h
@@ -96,6 +96,13 @@
       const std::vector<std::string>& key_value_pair_headers,
       brillo::ErrorPtr* error) = 0;
 
+  // Wait for merge to complete, then clean up merge after an update has been
+  // successful.
+  //
+  // This function returns immediately if no merge is needed, but may block
+  // for a long time (up to several minutes) in the worst case.
+  virtual int32_t CleanupSuccessfulUpdate(brillo::ErrorPtr* error) = 0;
+
  protected:
   ServiceDelegateAndroidInterface() = default;
 };
diff --git a/update_attempter_android.cc b/update_attempter_android.cc
index 59cdbb8..263498b 100644
--- a/update_attempter_android.cc
+++ b/update_attempter_android.cc
@@ -910,4 +910,11 @@
   return 0;
 }
 
+int32_t UpdateAttempterAndroid::CleanupSuccessfulUpdate(
+    brillo::ErrorPtr* error) {
+  // TODO(elsk): implement b/138808328
+  LogAndSetError(error, FROM_HERE, "Not implemented.");
+  return static_cast<int32_t>(ErrorCode::kError);
+}
+
 }  // namespace chromeos_update_engine
diff --git a/update_attempter_android.h b/update_attempter_android.h
index 309adff..c301e64 100644
--- a/update_attempter_android.h
+++ b/update_attempter_android.h
@@ -81,6 +81,7 @@
       const std::string& metadata_filename,
       const std::vector<std::string>& key_value_pair_headers,
       brillo::ErrorPtr* error) override;
+  int32_t CleanupSuccessfulUpdate(brillo::ErrorPtr* error) override;
 
   // ActionProcessorDelegate methods:
   void ProcessingDone(const ActionProcessor* processor,