diff options
| author | Howard Chen <howardsoc@google.com> | 2019-03-15 02:51:00 -0700 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-03-15 02:51:00 -0700 |
| commit | 4e38b0dda76f4ade4a0346de6893c8dc65dae733 (patch) | |
| tree | c6466fa047a3edbb16b9364649430a8cdc8b46e9 | |
| parent | e876679d620397c6dc17b6d37cd2cb89c9136684 (diff) | |
| parent | 65721715679e8cdcf84eebd2619db0810d4f3d12 (diff) | |
| download | platform_system_gsid-4e38b0dda76f4ade4a0346de6893c8dc65dae733.tar.gz platform_system_gsid-4e38b0dda76f4ade4a0346de6893c8dc65dae733.tar.bz2 platform_system_gsid-4e38b0dda76f4ade4a0346de6893c8dc65dae733.zip | |
Make the StartInstall abort-able am: ecbc0198c6 am: ff8125d882
am: 6572171567
Change-Id: I9fb783e8999f7417641f2bd626faa1bbd3dcbfc6
| -rw-r--r-- | gsi_service.cpp | 13 | ||||
| -rw-r--r-- | gsi_service.h | 1 | ||||
| -rw-r--r-- | gsi_tool.cpp | 19 |
3 files changed, 25 insertions, 8 deletions
diff --git a/gsi_service.cpp b/gsi_service.cpp index 5e786b2..ec5f584 100644 --- a/gsi_service.cpp +++ b/gsi_service.cpp @@ -254,17 +254,15 @@ binder::Status GsiService::isGsiInstallInProgress(bool* _aidl_return) { binder::Status GsiService::cancelGsiInstall(bool* _aidl_return) { ENFORCE_SYSTEM; + should_abort_ = true; std::lock_guard<std::mutex> guard(main_lock_); - if (!installing_) { - LOG(ERROR) << "No GSI installation in progress to cancel"; - *_aidl_return = false; - return binder::Status::ok(); + should_abort_ = false; + if (installing_) { + PostInstallCleanup(); + RemoveGsiFiles(install_dir_, wipe_userdata_on_failure_); } - PostInstallCleanup(); - RemoveGsiFiles(install_dir_, wipe_userdata_on_failure_); - *_aidl_return = true; return binder::Status::ok(); } @@ -627,6 +625,7 @@ std::unique_ptr<SplitFiemap> GsiService::CreateFiemapWriter(const std::string& p // TODO: allow cancelling inside cancelGsiInstall. progress = [this](uint64_t bytes, uint64_t /* total */) -> bool { UpdateProgress(STATUS_WORKING, bytes); + if (should_abort_) return false; return true; }; } diff --git a/gsi_service.h b/gsi_service.h index 272d524..f3cbad0 100644 --- a/gsi_service.h +++ b/gsi_service.h @@ -133,6 +133,7 @@ class GsiService : public BinderService<GsiService>, public BnGsiService { // These are initialized or set in StartInstall(). bool installing_ = false; + std::atomic<bool> should_abort_ = false; std::string install_dir_; std::string userdata_gsi_path_; std::string system_gsi_path_; diff --git a/gsi_tool.cpp b/gsi_tool.cpp index 2b8e52a..df2fcd5 100644 --- a/gsi_tool.cpp +++ b/gsi_tool.cpp @@ -46,6 +46,7 @@ static int Enable(sp<IGsiService> gsid, int argc, char** argv); static int Install(sp<IGsiService> gsid, int argc, char** argv); static int Wipe(sp<IGsiService> gsid, int argc, char** argv); static int Status(sp<IGsiService> gsid, int argc, char** argv); +static int Cancel(sp<IGsiService> gsid, int argc, char** argv); static const std::map<std::string, CommandCallback> kCommandMap = { {"disable", Disable}, @@ -53,6 +54,7 @@ static const std::map<std::string, CommandCallback> kCommandMap = { {"install", Install}, {"wipe", Wipe}, {"status", Status}, + {"cancel", Cancel}, }; static sp<IGsiService> GetGsiService() { @@ -355,6 +357,20 @@ static int Status(sp<IGsiService> gsid, int argc, char** /* argv */) { return 0; } +static int Cancel(sp<IGsiService> gsid, int /* argc */, char** /* argv */) { + bool cancelled = false; + auto status = gsid->cancelGsiInstall(&cancelled); + if (!status.isOk()) { + std::cerr << status.exceptionMessage().string() << std::endl; + return EX_SOFTWARE; + } + if (!cancelled) { + std::cout << "Fail to cancel the installation." << std::endl; + return EX_SOFTWARE; + } + return 0; +} + static int Enable(sp<IGsiService> gsid, int argc, char** argv) { bool one_shot = false; @@ -436,7 +452,8 @@ static int usage(int /* argc */, char* argv[]) { " --userdata-size (the latter defaults to 8GiB)\n" " --wipe (remove old gsi userdata first)\n" " wipe Completely remove a GSI and its associated data\n" - " status Show status", + " cancel Cancel the installation\n" + " status Show status\n", argv[0], argv[0]); return EX_USAGE; } |
