Use libhidl function to convert to hidl IMemory.

Now that this API is available.

This keeps the implementation details of hidl's
ashmem allocator in libhidl itself (it should be
opaque).

Test: try and succeed watching (part of a) DRM protected movie
Bug: 34234561
Change-Id: Ied9beddace2ccfc859833ac55f4e3837db5f495e
diff --git a/drm/libmediadrm/Android.bp b/drm/libmediadrm/Android.bp
index 66f5fc2..98b01ba 100644
--- a/drm/libmediadrm/Android.bp
+++ b/drm/libmediadrm/Android.bp
@@ -39,8 +39,8 @@
         "libstagefright_foundation",
         "libutils",
         "android.hardware.drm@1.0",
+        "libhidlallocatorutils",
         "libhidlbase",
-        "libhidlmemory",
         "libhidltransport",
     ],
 
diff --git a/drm/libmediadrm/CryptoHal.cpp b/drm/libmediadrm/CryptoHal.cpp
index d613a5b..b9b3685 100644
--- a/drm/libmediadrm/CryptoHal.cpp
+++ b/drm/libmediadrm/CryptoHal.cpp
@@ -29,6 +29,7 @@
 #include <media/stagefright/foundation/AString.h>
 #include <media/stagefright/foundation/hexdump.h>
 #include <media/stagefright/MediaErrors.h>
+#include <hidlmemory/FrameworkUtils.h>
 
 using ::android::hardware::drm::V1_0::BufferType;
 using ::android::hardware::drm::V1_0::DestinationBuffer;
@@ -227,6 +228,9 @@
  * are sent by providing an offset into the heap and a buffer size.
  */
 int32_t CryptoHal::setHeapBase(const sp<IMemoryHeap>& heap) {
+    using ::android::hardware::fromHeap;
+    using ::android::hardware::HidlMemory;
+
     if (heap == NULL) {
         ALOGE("setHeapBase(): heap is NULL");
         return -1;
@@ -240,12 +244,9 @@
     Mutex::Autolock autoLock(mLock);
 
     int32_t seqNum = mHeapSeqNum++;
-    int fd = heap->getHeapID();
-    nativeHandle->data[0] = fd;
-    auto hidlHandle = hidl_handle(nativeHandle);
-    auto hidlMemory = hidl_memory("ashmem", hidlHandle, heap->getSize());
+    sp<HidlMemory> hidlMemory = fromHeap(heap);
     mHeapBases.add(seqNum, mNextBufferId);
-    Return<void> hResult = mPlugin->setSharedBufferBase(hidlMemory, mNextBufferId++);
+    Return<void> hResult = mPlugin->setSharedBufferBase(*hidlMemory, mNextBufferId++);
     ALOGE_IF(!hResult.isOk(), "setSharedBufferBase(): remote call failed");
     return seqNum;
 }