Remove dependency to libmediadrm from drm HAL

drm HAL has been using libmediadrm for android::SharedLibrary class and
android::PluginLoader class. This is a Treble violation since
libmediadrm is a framework-only library that is not available to
vendors.

To solve the problem, the two classes are copied into this directory
to form a small static library android.hardware.drm@1.0-helper.a.

Bug: 38302533
Test: mm under /hardware/interfaces/drm/1.0/default and
/hardware/interfaces/drm/1.0/vts/functional

Change-Id: I7b4e5cdb3bc815e971e0c3b7ec99ea86042e13eb
diff --git a/drm/1.0/vts/functional/Android.bp b/drm/1.0/vts/functional/Android.bp
index 43ea372..b45ce84 100644
--- a/drm/1.0/vts/functional/Android.bp
+++ b/drm/1.0/vts/functional/Android.bp
@@ -19,7 +19,6 @@
     srcs: [
         "drm_hal_clearkey_test.cpp",
         "drm_hal_vendor_test.cpp",
-        "shared_library.cpp",
         "vendor_modules.cpp"
         ],
     shared_libs: [
@@ -39,7 +38,8 @@
         "libutils",
     ],
     static_libs: [
-        "VtsHalHidlTargetTestBase"
+        "VtsHalHidlTargetTestBase",
+        "android.hardware.drm@1.0-helper",
     ],
     cflags: [
         "-O0",
diff --git a/drm/1.0/vts/functional/shared_library.cpp b/drm/1.0/vts/functional/shared_library.cpp
deleted file mode 100644
index 6658150..0000000
--- a/drm/1.0/vts/functional/shared_library.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "drm-vts-shared-library"
-
-#include <dlfcn.h>
-#include <shared_library.h>
-
-using std::string;
-
-namespace drm_vts {
-
-SharedLibrary::SharedLibrary(const string& path) {
-    mLibHandle = dlopen(path.c_str(), RTLD_NOW);
-}
-
-SharedLibrary::~SharedLibrary() {
-    if (mLibHandle != NULL) {
-        dlclose(mLibHandle);
-        mLibHandle = NULL;
-    }
-}
-
-bool SharedLibrary::operator!() const {
-    return mLibHandle == NULL;
-}
-
-void* SharedLibrary::lookup(const char* symbol) const {
-    if (!mLibHandle) {
-        return NULL;
-    }
-
-    // Clear last error before we load the symbol again,
-    // in case the caller didn't retrieve it.
-    (void)dlerror();
-    return dlsym(mLibHandle, symbol);
-}
-
-const char* SharedLibrary::lastError() const {
-    const char* error = dlerror();
-    return error ? error : "No errors or unknown error";
-}
-};
diff --git a/drm/1.0/vts/functional/shared_library.h b/drm/1.0/vts/functional/shared_library.h
deleted file mode 100644
index 1f32243..0000000
--- a/drm/1.0/vts/functional/shared_library.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SHARED_LIBRARY_H_
-#define SHARED_LIBRARY_H_
-
-#include <string>
-#include <vector>
-
-namespace drm_vts {
-class SharedLibrary {
-   public:
-    explicit SharedLibrary(const std::string& path);
-    ~SharedLibrary();
-
-    bool operator!() const;
-    void* lookup(const char* symbol) const;
-    const char* lastError() const;
-
-   private:
-    void* mLibHandle;
-
-    SharedLibrary(const SharedLibrary&) = delete;
-    void operator=(const SharedLibrary&) = delete;
-};
-};
-
-#endif  // SHARED_LIBRARY_H_
diff --git a/drm/1.0/vts/functional/vendor_modules.cpp b/drm/1.0/vts/functional/vendor_modules.cpp
index 2bf0b28..98430f5 100644
--- a/drm/1.0/vts/functional/vendor_modules.cpp
+++ b/drm/1.0/vts/functional/vendor_modules.cpp
@@ -20,13 +20,16 @@
 #include <dlfcn.h>
 #include <log/log.h>
 #include <memory>
+#include <utils/String8.h>
+#include <SharedLibrary.h>
 
-#include "shared_library.h"
 #include "vendor_modules.h"
 
 using std::string;
 using std::vector;
 using std::unique_ptr;
+using ::android::String8;
+using ::android::hardware::drm::V1_0::helper::SharedLibrary;
 
 namespace drm_vts {
 void VendorModules::scanModules(const std::string &directory) {
@@ -48,7 +51,7 @@
 
 DrmHalVTSVendorModule* VendorModules::getModule(const string& path) {
     if (mOpenLibraries.find(path) == mOpenLibraries.end()) {
-        auto library = std::make_unique<SharedLibrary>(path);
+        auto library = std::make_unique<SharedLibrary>(String8(path.c_str()));
         if (!library) {
             ALOGE("failed to map shared library %s", path.c_str());
             return NULL;
diff --git a/drm/1.0/vts/functional/vendor_modules.h b/drm/1.0/vts/functional/vendor_modules.h
index ca538f6..8330b0a 100644
--- a/drm/1.0/vts/functional/vendor_modules.h
+++ b/drm/1.0/vts/functional/vendor_modules.h
@@ -18,8 +18,12 @@
 #define VENDOR_MODULES_H
 
 #include <map>
+#include <vector>
+#include <string>
 
-#include "shared_library.h"
+#include <SharedLibrary.h>
+
+using ::android::hardware::drm::V1_0::helper::SharedLibrary;
 
 class DrmHalVTSVendorModule;