Merge changes I4580e60e,I23b77414

* changes:
  Let DSUEndtoEndTest unsparse super.img if needed
  Clean up temporary files created by DSUEndtoEndTest
diff --git a/gsi_tool.cpp b/gsi_tool.cpp
index 5bf69fc..aba9404 100644
--- a/gsi_tool.cpp
+++ b/gsi_tool.cpp
@@ -78,6 +78,10 @@
     return "error code " + std::to_string(error_code);
 }
 
+static inline bool IsRoot() {
+    return getuid() == 0;
+}
+
 class ProgressBar {
   public:
     explicit ProgressBar(sp<IGsiService> gsid) : gsid_(gsid) {}
@@ -210,7 +214,7 @@
     bool reboot = true;
     std::string installDir = "";
     std::string partition = kDefaultPartition;
-    if (getuid() != 0) {
+    if (!IsRoot()) {
         std::cerr << "must be root to install a GSI" << std::endl;
         return EX_NOPERM;
     }
@@ -376,7 +380,7 @@
         }
     }
 
-    if (getuid() != 0) {
+    if (!IsRoot()) {
         std::cerr << "must be root to install a DSU" << std::endl;
         return EX_NOPERM;
     }
@@ -555,7 +559,7 @@
     } else {
         std::cout << "normal" << std::endl;
     }
-    if (getuid() != 0) {
+    if (!IsRoot()) {
         return 0;
     }
 
@@ -676,7 +680,16 @@
         std::cerr << "Unrecognized arguments to disable." << std::endl;
         return EX_USAGE;
     }
-
+    std::string dsuSlot = {};
+    auto status = gsid->getActiveDsuSlot(&dsuSlot);
+    if (!status.isOk()) {
+        std::cerr << "Could not get the active DSU slot: " << ErrorMessage(status) << "\n";
+        return EX_SOFTWARE;
+    }
+    if (android::base::EndsWith(dsuSlot, ".lock") && !IsRoot()) {
+        std::cerr << "must be root to disable a locked DSU" << std::endl;
+        return EX_NOPERM;
+    }
     bool installing = false;
     gsid->isGsiInstallInProgress(&installing);
     if (installing) {
diff --git a/include/libgsi/libgsi.h b/include/libgsi/libgsi.h
index 5318341..969ea28 100644
--- a/include/libgsi/libgsi.h
+++ b/include/libgsi/libgsi.h
@@ -76,6 +76,8 @@
 // install_dir "/data/gsi/dsu/dsu2" has a slot name "dsu2"
 std::string GetDsuSlot(const std::string& install_dir);
 
+static constexpr char kDsuSlotProp[] = "ro.gsid.dsu_slot";
+
 static constexpr char kGsiBootedProp[] = "ro.gsid.image_running";
 
 static constexpr char kGsiInstalledProp[] = "gsid.image_installed";