Make the StartInstall abort-able

The StartInstall may take more than one mintue. This CL adds an
aborting_ flag to notify the allocating procedure to exit once
the flag is set. It also adds a "cancel" command to gsi_tool for
testing purpose.

Test: open two adb consoles: one starts the installation and
    another uses the cancel command to abort.
Bug: 125599267
Change-Id: I8f8fc460df526abda81ed6e0ac8f7176a28e9df3
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::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 @@
         // 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;
         };
     }