From 36fdbc6daf44c85c5d811e08c35a792b867d0aae Mon Sep 17 00:00:00 2001 From: Yo Chiang Date: Thu, 20 Aug 2020 19:40:31 +0800 Subject: 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 --- aidl/android/gsi/IGsiService.aidl | 13 ++++++++++++- gsi_service.cpp | 15 +++++++++++++++ gsi_service.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/aidl/android/gsi/IGsiService.aidl b/aidl/android/gsi/IGsiService.aidl index 5503493..8b38504 100644 --- a/aidl/android/gsi/IGsiService.aidl +++ b/aidl/android/gsi/IGsiService.aidl @@ -178,6 +178,16 @@ interface IGsiService { */ int createPartition(in @utf8InCpp String name, long size, boolean readOnly); + /** + * Complete the current partition installation. A partition installation is + * complete after all pending bytes are written successfully. + * Returns an error if current installation still have pending bytes. + * Returns an error if there is any internal filesystem error. + * + * @return 0 on success, an error code on failure. + */ + int closePartition(); + /** * Wipe a partition. This will not work if the GSI is currently running. * The partition will not be removed, but the first block will be zeroed. @@ -212,7 +222,8 @@ interface IGsiService { * 2. Open a new partition installer. * 3. Create and map the new partition. * - * In other words, getAvbPublicKey() works between two createPartition() calls. + * In other words, getAvbPublicKey() should be called after + * createPartition() is called and before closePartition() is called. * * @param dst Output the AVB public key. * @return 0 on success, an error code on failure. 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 @@ binder::Status GsiService::createPartition(const ::std::string& name, int64_t si return binder::Status::ok(); } +binder::Status GsiService::closePartition(int32_t* _aidl_return) { + ENFORCE_SYSTEM; + std::lock_guard 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; diff --git a/gsi_service.h b/gsi_service.h index 229db36..3f81786 100644 --- a/gsi_service.h +++ b/gsi_service.h @@ -42,6 +42,7 @@ class GsiService : public BinderService, public BnGsiService { binder::Status closeInstall(int32_t* _aidl_return) override; binder::Status createPartition(const ::std::string& name, int64_t size, bool readOnly, int32_t* _aidl_return) override; + binder::Status closePartition(int32_t* _aidl_return) override; binder::Status commitGsiChunkFromStream(const ::android::os::ParcelFileDescriptor& stream, int64_t bytes, bool* _aidl_return) override; binder::Status getInstallProgress(::android::gsi::GsiProgress* _aidl_return) override; -- cgit v1.2.3