Check LAUNCHED_BY_ACLOUD!=true env var then delete the home directory.

Test: m -j 160 acloud
cvd acloud translator --opt-out
acloud-dev create --local-instance --local-image --local-system-image -vv
Bug: 279987820
Bug: 279691419
(cherry picked from https://android-review.googlesource.com/q/commit:997ed31859d018d5ef824f6742e3d44d3f7fa756)
Merged-In: If1e679498e88e09af7fbae7585f79d7ac298fe74
Change-Id: If1e679498e88e09af7fbae7585f79d7ac298fe74
diff --git a/host/commands/cvd/common_utils.h b/host/commands/cvd/common_utils.h
index 9040f15..623b0fc 100644
--- a/host/commands/cvd/common_utils.h
+++ b/host/commands/cvd/common_utils.h
@@ -61,6 +61,7 @@
 // kAndroidHostOut for old branches
 constexpr char kAndroidSoongHostOut[] = "ANDROID_SOONG_HOST_OUT";
 constexpr char kAndroidProductOut[] = "ANDROID_PRODUCT_OUT";
+constexpr char kLaunchedByAcloud[] = "LAUNCHED_BY_ACLOUD";
 
 template <typename Ostream, typename... Args>
 Ostream& ConcatToStream(Ostream& out, Args&&... args) {
diff --git a/host/commands/cvd/server_command/start.cpp b/host/commands/cvd/server_command/start.cpp
index 91c14b0..b61eac8 100644
--- a/host/commands/cvd/server_command/start.cpp
+++ b/host/commands/cvd/server_command/start.cpp
@@ -172,22 +172,25 @@
         ConcatToString(acloud_compat_home_prefix, instance.instance_id_));
   }
   for (const auto acloud_compat_home : acloud_compat_homes) {
-    bool result_id = false;
+    bool result_deleted = true;
     std::stringstream acloud_compat_home_stream;
     if (!FileExists(acloud_compat_home)) {
       continue;
     }
     if (!DirectoryExists(acloud_compat_home, /*follow_symlinks=*/false)) {
       // cvd created a symbolic link
-      result_id = RemoveFile(acloud_compat_home);
+      result_deleted = RemoveFile(acloud_compat_home);
     } else {
       // acloud created a directory
       // rm -fr isn't supporetd by TreeHugger, so if we fork-and-exec to
       // literally run "rm -fr", the presubmit testing may fail if ever this
       // code is tested in the future.
-      result_id = RecursivelyRemoveDirectory(acloud_compat_home);
+      if (!Contains(group_creation_info.envs, kLaunchedByAcloud) ||
+        group_creation_info.envs.at(kLaunchedByAcloud) != "true") {
+        result_deleted = RecursivelyRemoveDirectory(acloud_compat_home);
+      }
     }
-    if (!result_id) {
+    if (!result_deleted) {
       LOG(ERROR) << "Removing " << acloud_compat_home << " failed.";
       continue;
     }