Refine HidlMemory

Add construct from a const hidl_memory& so that we can easily
copy it out of a synchronous callback

Bug: 67758915
Test: hidl_test
Change-Id: I0e10cc4c9321197787657f957ea184a5e7262744
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index e60f2f3..486fd0a 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -295,23 +295,22 @@
 // to support other type of hidl_memory without break the ABI.
 class HidlMemory : public virtual hidl_memory, public virtual ::android::RefBase {
 public:
+    static sp<HidlMemory> getInstance(const hidl_memory& mem);
+
     static sp<HidlMemory> getInstance(hidl_memory&& mem);
 
     static sp<HidlMemory> getInstance(const hidl_string& name, hidl_handle&& handle, uint64_t size);
     // @param fd, shall be opened and points to the resource.
     // @note this method takes the ownership of the fd and will close it in
     //     destructor
+    // @return nullptr in failure with the fd closed
     static sp<HidlMemory> getInstance(const hidl_string& name, int fd, uint64_t size);
 
     virtual ~HidlMemory();
+
 protected:
-    HidlMemory() : hidl_memory() {}
-    HidlMemory(const hidl_string& name, hidl_handle&& handle, size_t size)
-        : hidl_memory(name, std::move(handle), size) {}
-    HidlMemory& operator=(hidl_memory&& src) {
-        hidl_memory::operator=(src);
-        return *this;
-    }
+    HidlMemory();
+    HidlMemory(const hidl_string& name, hidl_handle&& handle, size_t size);
 };
 ////////////////////////////////////////////////////////////////////////////////