Add new dex file support constructor.

The requirement of an r-value for the DexFile constructor made it
hard to use and required a bunch of std::move calls.

Add a constructor that takes a unique_ptr instead.

Bug: 151966190

Test: Build and run art_libdexfile_support_static_tests.
Change-Id: Ie6711be8efce62f591814512f796605e20e1ac89
diff --git a/libdexfile/external/dex_file_supp_test.cc b/libdexfile/external/dex_file_supp_test.cc
index 955eb12..0d7644a 100644
--- a/libdexfile/external/dex_file_supp_test.cc
+++ b/libdexfile/external/dex_file_supp_test.cc
@@ -285,5 +285,16 @@
   EXPECT_EQ(info.offset, int32_t{0x100});
 }
 
+TEST(DexFileTest, pointer_construct) {
+  std::unique_ptr<DexFile> dex_file = GetTestDexData();
+  ASSERT_NE(dex_file, nullptr);
+
+  auto new_dex = DexFile(dex_file);
+  ASSERT_TRUE(dex_file.get() == nullptr);
+
+  MethodInfo info = new_dex.GetMethodInfoForOffset(0x100, false);
+  EXPECT_EQ(info.offset, int32_t{0x100});
+}
+
 }  // namespace dex
 }  // namespace art_api
diff --git a/libdexfile/external/include/art_api/dex_file_support.h b/libdexfile/external/include/art_api/dex_file_support.h
index 9287dba..404fa65 100644
--- a/libdexfile/external/include/art_api/dex_file_support.h
+++ b/libdexfile/external/include/art_api/dex_file_support.h
@@ -129,6 +129,12 @@
     ext_dex_file_ = dex_file.ext_dex_file_;
     dex_file.ext_dex_file_ = nullptr;
   }
+
+  explicit DexFile(std::unique_ptr<DexFile>& dex_file) noexcept {
+    ext_dex_file_ = dex_file->ext_dex_file_;
+    dex_file->ext_dex_file_ = nullptr;
+    dex_file.reset(nullptr);
+  }
   virtual ~DexFile();
 
   // Interprets a chunk of memory as a dex file. As long as *size is too small,