Add closePartition() method to gsid

closePartition() closes an ongoing partition installation and does error
checking.
closePartition() returns a non-zero error code if the installation ends
with an error.

Bug: 165471299
Test: Observe the logcat of a failed DSU installation
Change-Id: I2ca7868834fa1f59bd534a7fef5eb7b3201d6789
diff --git a/gsi_service.cpp b/gsi_service.cpp
index 490655c..3c875f8 100644
--- a/gsi_service.cpp
+++ b/gsi_service.cpp
@@ -182,6 +182,21 @@
     return binder::Status::ok();
 }
 
+binder::Status GsiService::closePartition(int32_t* _aidl_return) {
+    ENFORCE_SYSTEM;
+    std::lock_guard<std::mutex> guard(lock_);
+
+    if (installer_ == nullptr) {
+        LOG(ERROR) << "createPartition() has to be called before closePartition()";
+        *_aidl_return = IGsiService::INSTALL_ERROR_GENERIC;
+        return binder::Status::ok();
+    }
+    // It is important to not reset |installer_| here because other methods such
+    // as enableGsi() relies on the state of |installer_|.
+    *_aidl_return = installer_->FinishInstall();
+    return binder::Status::ok();
+}
+
 binder::Status GsiService::commitGsiChunkFromStream(const android::os::ParcelFileDescriptor& stream,
                                                     int64_t bytes, bool* _aidl_return) {
     ENFORCE_SYSTEM;