Revert "Remove the primary boot image from the ART APEX."

Revert "Remove the primary boot image from the ART APEX."

Revert submission 1946769-boot-image-flip-b211973309

Reason for revert: Broke golem
Reverted Changes:
I80ffd9160:Remove the primary boot image from the ART APEX.
I45aaa5984:Remove the primary boot image from the ART APEX.

Change-Id: I32c65b2389e269e676c231db91a5985a652e7381
diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc
index 0b670e7..139d904 100644
--- a/libartbase/base/file_utils.cc
+++ b/libartbase/base/file_utils.cc
@@ -54,7 +54,6 @@
 #if defined(__APPLE__)
 #include <crt_externs.h>
 #include <sys/syscall.h>
-
 #include "AvailabilityMacros.h"  // For MAC_OS_X_VERSION_MAX_ALLOWED
 #endif
 
@@ -88,7 +87,7 @@
 // Return the empty string if that directory cannot be found or if this code is
 // run on Windows or macOS.
 static std::string GetRootContainingLibartbase() {
-#if !defined(_WIN32) && !defined(__APPLE__)
+#if !defined( _WIN32) && !defined(__APPLE__)
   // Check where libartbase is from, and derive from there.
   Dl_info info;
   if (dladdr(reinterpret_cast<const void*>(&GetRootContainingLibartbase), /* out */ &info) != 0) {
@@ -156,6 +155,7 @@
   return ret;
 }
 
+
 static const char* GetAndroidDirSafe(const char* env_var,
                                      const char* default_dir,
                                      bool must_exist,
@@ -200,8 +200,9 @@
   const char* android_art_root_from_env = getenv(kAndroidArtRootEnvVar);
   if (android_art_root_from_env != nullptr) {
     if (must_exist && !OS::DirectoryExists(android_art_root_from_env)) {
-      *error_msg = StringPrintf(
-          "Failed to find %s directory %s", kAndroidArtRootEnvVar, android_art_root_from_env);
+      *error_msg = StringPrintf("Failed to find %s directory %s",
+                                kAndroidArtRootEnvVar,
+                                android_art_root_from_env);
       return "";
     }
     return android_art_root_from_env;
@@ -233,8 +234,8 @@
 
   // Try the default path.
   if (must_exist && !OS::DirectoryExists(kAndroidArtApexDefaultPath)) {
-    *error_msg =
-        StringPrintf("Failed to find default ART root directory %s", kAndroidArtApexDefaultPath);
+    *error_msg = StringPrintf("Failed to find default ART root directory %s",
+                              kAndroidArtApexDefaultPath);
     return "";
   }
   return kAndroidArtApexDefaultPath;
@@ -274,22 +275,16 @@
   return (android_dir != nullptr) ? android_dir : "";
 }
 
-std::string GetAndroidData() { return GetAndroidDir(kAndroidDataEnvVar, kAndroidDataDefaultPath); }
+std::string GetAndroidData() {
+  return GetAndroidDir(kAndroidDataEnvVar, kAndroidDataDefaultPath);
+}
 
 std::string GetArtApexData() {
   return GetAndroidDir(kArtApexDataEnvVar, kArtApexDataDefaultPath, /*must_exist=*/false);
 }
 
-static std::string GetPrebuiltPrimaryBootImageDir(const std::string& android_root) {
-  return StringPrintf("%s/framework", android_root.c_str());
-}
-
 std::string GetPrebuiltPrimaryBootImageDir() {
-  std::string android_root = GetAndroidRoot();
-  if (android_root.empty()) {
-    return "";
-  }
-  return GetPrebuiltPrimaryBootImageDir(android_root);
+  return StringPrintf("%s/javalib", kAndroidArtApexDefaultPath);
 }
 
 std::string GetDefaultBootImageLocation(const std::string& android_root,
@@ -347,7 +342,7 @@
   // Typically "/apex/com.android.art/javalib/boot.art!/apex/com.android.art/etc/boot-image.prof:
   // /system/framework/boot-framework.art!/system/etc/boot-image.prof".
   return StringPrintf("%s/%s.art!%s/%s:%s/framework/%s-framework.art!%s/%s",
-                      GetPrebuiltPrimaryBootImageDir(android_root).c_str(),
+                      GetPrebuiltPrimaryBootImageDir().c_str(),
                       kBootImageStem,
                       kAndroidArtApexDefaultPath,
                       kEtcBootImageProf,
@@ -368,9 +363,9 @@
 static /*constinit*/ std::string_view dalvik_cache_sub_dir = "dalvik-cache";
 
 void OverrideDalvikCacheSubDirectory(std::string sub_dir) {
-  static std::string overridden_dalvik_cache_sub_dir;
-  overridden_dalvik_cache_sub_dir = std::move(sub_dir);
-  dalvik_cache_sub_dir = overridden_dalvik_cache_sub_dir;
+    static std::string overridden_dalvik_cache_sub_dir;
+    overridden_dalvik_cache_sub_dir = std::move(sub_dir);
+    dalvik_cache_sub_dir = overridden_dalvik_cache_sub_dir;
 }
 
 static std::string GetDalvikCacheDirectory(std::string_view root_directory,
@@ -383,12 +378,8 @@
   return oss.str();
 }
 
-void GetDalvikCache(const char* subdir,
-                    const bool create_if_absent,
-                    std::string* dalvik_cache,
-                    bool* have_android_data,
-                    bool* dalvik_cache_exists,
-                    bool* is_global_cache) {
+void GetDalvikCache(const char* subdir, const bool create_if_absent, std::string* dalvik_cache,
+                    bool* have_android_data, bool* dalvik_cache_exists, bool* is_global_cache) {
 #ifdef _WIN32
   UNUSED(subdir);
   UNUSED(create_if_absent);
@@ -432,7 +423,8 @@
     return false;
   }
   std::string cache_file(&location[1]);  // skip leading slash
-  if (!android::base::EndsWith(location, ".dex") && !android::base::EndsWith(location, ".art") &&
+  if (!android::base::EndsWith(location, ".dex") &&
+      !android::base::EndsWith(location, ".art") &&
       !android::base::EndsWith(location, ".oat")) {
     cache_file += "/";
     cache_file += kClassesDex;
@@ -637,20 +629,22 @@
                       kAndroidSystemExtRootEnvVar,
                       kAndroidSystemExtRootDefaultPath,
                       /* subdir= */ "framework/") ||
-         // When the 'system_ext' partition is not present, builds will create
-         // '/system/system_ext' instead.
-         IsLocationOn(full_path,
-                      kAndroidRootEnvVar,
-                      kAndroidRootDefaultPath,
-                      /* subdir= */ "system_ext/framework/");
+      // When the 'system_ext' partition is not present, builds will create
+      // '/system/system_ext' instead.
+      IsLocationOn(full_path,
+                   kAndroidRootEnvVar,
+                   kAndroidRootDefaultPath,
+                   /* subdir= */ "system_ext/framework/");
 }
 
 bool LocationIsOnConscryptModule(std::string_view full_path) {
-  return IsLocationOn(full_path, kAndroidConscryptRootEnvVar, kAndroidConscryptApexDefaultPath);
+  return IsLocationOn(
+      full_path, kAndroidConscryptRootEnvVar, kAndroidConscryptApexDefaultPath);
 }
 
 bool LocationIsOnI18nModule(std::string_view full_path) {
-  return IsLocationOn(full_path, kAndroidI18nRootEnvVar, kAndroidI18nApexDefaultPath);
+  return IsLocationOn(
+      full_path, kAndroidI18nRootEnvVar, kAndroidI18nApexDefaultPath);
 }
 
 bool LocationIsOnApex(std::string_view full_path) {
@@ -696,8 +690,9 @@
                                            kAndroidArtApexDefaultPath,
                                            /* must_exist= */ kIsTargetBuild,
                                            &error_msg);
-  return (android_root != nullptr) && (art_root != nullptr) &&
-         (std::string_view(android_root) != std::string_view(art_root));
+  return (android_root != nullptr)
+      && (art_root != nullptr)
+      && (std::string_view(android_root) != std::string_view(art_root));
 }
 
 int DupCloexec(int fd) {