Pass the fd to OatFile::Setup to avoid selinux errors.

bug: 77853712
Test: test.py

(cherry picked from commit 30025095524e471ec347633e39f26ed0606bea65)

Change-Id: I2af5c784f2ca12cd5b0859d93500c16be6a03428
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index bc8468e..a229d7d 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -135,7 +135,8 @@
       ASSERT_TRUE(success) << error_msg << std::endl << output_;
 
       // Verify the odex file was generated as expected.
-      std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+      std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                       odex_location.c_str(),
                                                        odex_location.c_str(),
                                                        nullptr,
                                                        nullptr,
@@ -154,7 +155,8 @@
 
       if (!test_accepts_odex_file_on_failure) {
         // Verify there's no loadable odex file.
-        std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+        std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                         odex_location.c_str(),
                                                          odex_location.c_str(),
                                                          nullptr,
                                                          nullptr,
@@ -542,7 +544,8 @@
     }
     // Host/target independent checks.
     std::string error_msg;
-    std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+    std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                     odex_location.c_str(),
                                                      odex_location.c_str(),
                                                      nullptr,
                                                      nullptr,
@@ -812,7 +815,8 @@
                    const std::string& app_image_file_name) {
     // Host/target independent checks.
     std::string error_msg;
-    std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+    std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                     odex_location.c_str(),
                                                      odex_location.c_str(),
                                                      nullptr,
                                                      nullptr,
@@ -973,7 +977,8 @@
 
   void CheckResult(const std::string& dex_location, const std::string& odex_location) {
     std::string error_msg;
-    std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+    std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                     odex_location.c_str(),
                                                      odex_location.c_str(),
                                                      nullptr,
                                                      nullptr,
@@ -1366,7 +1371,8 @@
   EXPECT_EQ(res, 0);
 
   // Open our generated oat file.
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(oat_filename.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   oat_filename.c_str(),
                                                    oat_filename.c_str(),
                                                    nullptr,
                                                    nullptr,
@@ -1479,7 +1485,8 @@
       {"--compact-dex-level=fast"});
   EXPECT_EQ(res, 0);
   // Open our generated oat file.
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(oat_filename.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   oat_filename.c_str(),
                                                    oat_filename.c_str(),
                                                    nullptr,
                                                    nullptr,
@@ -1724,7 +1731,8 @@
                       });
   // Open our generated oat file.
   std::string error_msg;
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(oat_filename.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   oat_filename.c_str(),
                                                    oat_filename.c_str(),
                                                    nullptr,
                                                    nullptr,
@@ -1801,7 +1809,8 @@
                       { "--compilation-reason=install" },
                       true);
   std::string error_msg;
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   odex_location.c_str(),
                                                    odex_location.c_str(),
                                                    nullptr,
                                                    nullptr,
@@ -1826,7 +1835,8 @@
                       {},
                       true);
   std::string error_msg;
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   odex_location.c_str(),
                                                    odex_location.c_str(),
                                                    nullptr,
                                                    nullptr,
@@ -1863,7 +1873,8 @@
     ASSERT_TRUE(vdex != nullptr);
     EXPECT_FALSE(vdex->HasDexSection()) << output_;
   }
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   odex_location.c_str(),
                                                    odex_location.c_str(),
                                                    nullptr,
                                                    nullptr,
@@ -2106,7 +2117,8 @@
                       [](const OatFile&) {});
   // Open our generated oat file.
   std::string error_msg;
-  std::unique_ptr<OatFile> odex_file(OatFile::Open(odex_location.c_str(),
+  std::unique_ptr<OatFile> odex_file(OatFile::Open(/* zip_fd */ -1,
+                                                   odex_location.c_str(),
                                                    odex_location.c_str(),
                                                    nullptr,
                                                    nullptr,