Revert "Move HidlInstrumentor to HidlInternal and namespace details."

This reverts commit f509befb751b01701f6157b32c3a332abc237b2b.

Change-Id: I0770e5a7d5cea3d42a97d664fcc3ad2f1f7414f7
diff --git a/base/HidlInternal.cpp b/base/HidlInternal.cpp
index ad937e7..45afda3 100644
--- a/base/HidlInternal.cpp
+++ b/base/HidlInternal.cpp
@@ -20,14 +20,6 @@
 
 #include <android-base/logging.h>
 
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
-#include <cutils/properties.h>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <hidl-util/FQName.h>
-#include <regex>
-#endif
-
 namespace android {
 namespace hardware {
 namespace details {
@@ -36,113 +28,6 @@
     LOG(FATAL) << message;
 }
 
-// ----------------------------------------------------------------------
-// HidlInstrumentor implementation.
-HidlInstrumentor::HidlInstrumentor(
-        const std::string &package,
-        const std::string &interface)
-        : mInstrumentationLibPackage(package), mInterfaceName(interface) {
-    configureInstrumentation(false);
-}
-
-HidlInstrumentor:: ~HidlInstrumentor() {}
-
-void HidlInstrumentor::configureInstrumentation(bool log) {
-    bool enable_instrumentation = property_get_bool(
-            "hal.instrumentation.enable",
-            false);
-    if (enable_instrumentation != mEnableInstrumentation) {
-        mEnableInstrumentation = enable_instrumentation;
-        if (mEnableInstrumentation) {
-            if (log) {
-                LOG(INFO) << "Enable instrumentation.";
-            }
-            registerInstrumentationCallbacks (&mInstrumentationCallbacks);
-        } else {
-            if (log) {
-                LOG(INFO) << "Disable instrumentation.";
-            }
-            mInstrumentationCallbacks.clear();
-        }
-    }
-}
-
-void HidlInstrumentor::registerInstrumentationCallbacks(
-        std::vector<InstrumentationCallback> *instrumentationCallbacks) {
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
-    std::vector<std::string> instrumentationLibPaths;
-    char instrumentation_lib_path[PROPERTY_VALUE_MAX];
-    if (property_get("hal.instrumentation.lib.path",
-                     instrumentation_lib_path,
-                     "") > 0) {
-        instrumentationLibPaths.push_back(instrumentation_lib_path);
-    } else {
-        instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_SYSTEM);
-        instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_VENDOR);
-        instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_ODM);
-    }
-
-    for (auto path : instrumentationLibPaths) {
-        DIR *dir = opendir(path.c_str());
-        if (dir == 0) {
-            LOG(WARNING) << path << " does not exist. ";
-            return;
-        }
-
-        struct dirent *file;
-        while ((file = readdir(dir)) != NULL) {
-            if (!isInstrumentationLib(file))
-                continue;
-
-            void *handle = dlopen((path + file->d_name).c_str(), RTLD_NOW);
-            char *error;
-            if (handle == nullptr) {
-                LOG(WARNING) << "couldn't load file: " << file->d_name
-                    << " error: " << dlerror();
-                continue;
-            }
-
-            dlerror(); /* Clear any existing error */
-
-            using cb_fun = void (*)(
-                    const InstrumentationEvent,
-                    const char *,
-                    const char *,
-                    const char *,
-                    const char *,
-                    std::vector<void *> *);
-            FQName package_name = FQName(mInstrumentationLibPackage);
-            auto cb = (cb_fun)dlsym(handle, ("HIDL_INSTRUMENTATION_FUNCTION_"
-                        + package_name.tokenName() + "_"
-                        + mInterfaceName).c_str());
-            if ((error = dlerror()) != NULL) {
-                LOG(WARNING)
-                    << "couldn't find symbol: HIDL_INSTRUMENTATION_FUNCTION_"
-                    << mInterfaceName << ", error: " << error;
-                continue;
-            }
-            instrumentationCallbacks->push_back(cb);
-            LOG(INFO) << "Register instrumentation callback from "
-                << file->d_name;
-        }
-        closedir(dir);
-    }
-#else
-    // No-op for user builds.
-    return;
-#endif
-}
-
-bool HidlInstrumentor::isInstrumentationLib(const dirent *file) {
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
-    if (file->d_type != DT_REG) return false;
-    std::cmatch cm;
-    std::regex e("^" + mInstrumentationLibPackage + "(.*).profiler.so$");
-    if (std::regex_match(file->d_name, cm, e)) return true;
-#endif
-    return false;
-}
-
 }  // namespace details
 }  // namespace hardware
 }  // namespace android
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index 1544969..3bd68af 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -25,6 +25,13 @@
 #include <vintf/VendorManifest.h>
 #include <vintf/parse_string.h>
 
+#ifdef LIBHIDL_TARGET_DEBUGGABLE
+#include <cutils/properties.h>
+#include <dlfcn.h>
+#include <regex>
+#include <utility>
+#endif
+
 namespace android {
 namespace hardware {
 vintf::Transport getTransportForFrameworkPackages(const std::string &name) {
@@ -309,6 +316,113 @@
     return mSize == 0;
 }
 
+// ----------------------------------------------------------------------
+// HidlInstrumentor implementation.
+HidlInstrumentor::HidlInstrumentor(
+        const std::string &package,
+        const std::string &interface)
+        : mInstrumentationLibPackage(package), mInterfaceName(interface) {
+    configureInstrumentation(false);
+}
+
+HidlInstrumentor:: ~HidlInstrumentor() {}
+
+void HidlInstrumentor::configureInstrumentation(bool log) {
+    bool enable_instrumentation = property_get_bool(
+            "hal.instrumentation.enable",
+            false);
+    if (enable_instrumentation != mEnableInstrumentation) {
+        mEnableInstrumentation = enable_instrumentation;
+        if (mEnableInstrumentation) {
+            if (log) {
+                LOG(INFO) << "Enable instrumentation.";
+            }
+            registerInstrumentationCallbacks (&mInstrumentationCallbacks);
+        } else {
+            if (log) {
+                LOG(INFO) << "Disable instrumentation.";
+            }
+            mInstrumentationCallbacks.clear();
+        }
+    }
+}
+
+void HidlInstrumentor::registerInstrumentationCallbacks(
+        std::vector<InstrumentationCallback> *instrumentationCallbacks) {
+#ifdef LIBHIDL_TARGET_DEBUGGABLE
+    std::vector<std::string> instrumentationLibPaths;
+    char instrumentation_lib_path[PROPERTY_VALUE_MAX];
+    if (property_get("hal.instrumentation.lib.path",
+                     instrumentation_lib_path,
+                     "") > 0) {
+        instrumentationLibPaths.push_back(instrumentation_lib_path);
+    } else {
+        instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_SYSTEM);
+        instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_VENDOR);
+        instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_ODM);
+    }
+
+    for (auto path : instrumentationLibPaths) {
+        DIR *dir = opendir(path.c_str());
+        if (dir == 0) {
+            LOG(WARNING) << path << " does not exist. ";
+            return;
+        }
+
+        struct dirent *file;
+        while ((file = readdir(dir)) != NULL) {
+            if (!isInstrumentationLib(file))
+                continue;
+
+            void *handle = dlopen((path + file->d_name).c_str(), RTLD_NOW);
+            char *error;
+            if (handle == nullptr) {
+                LOG(WARNING) << "couldn't load file: " << file->d_name
+                    << " error: " << dlerror();
+                continue;
+            }
+
+            dlerror(); /* Clear any existing error */
+
+            using cb_fun = void (*)(
+                    const InstrumentationEvent,
+                    const char *,
+                    const char *,
+                    const char *,
+                    const char *,
+                    std::vector<void *> *);
+            FQName package_name = FQName(mInstrumentationLibPackage);
+            auto cb = (cb_fun)dlsym(handle, ("HIDL_INSTRUMENTATION_FUNCTION_"
+                        + package_name.tokenName() + "_"
+                        + mInterfaceName).c_str());
+            if ((error = dlerror()) != NULL) {
+                LOG(WARNING)
+                    << "couldn't find symbol: HIDL_INSTRUMENTATION_FUNCTION_"
+                    << mInterfaceName << ", error: " << error;
+                continue;
+            }
+            instrumentationCallbacks->push_back(cb);
+            LOG(INFO) << "Register instrumentation callback from "
+                << file->d_name;
+        }
+        closedir(dir);
+    }
+#else
+    // No-op for user builds.
+    return;
+#endif
+}
+
+bool HidlInstrumentor::isInstrumentationLib(const dirent *file) {
+#ifdef LIBHIDL_TARGET_DEBUGGABLE
+    if (file->d_type != DT_REG) return false;
+    std::cmatch cm;
+    std::regex e("^" + mInstrumentationLibPackage + "(.*).profiler.so$");
+    if (std::regex_match(file->d_name, cm, e)) return true;
+#endif
+    return false;
+}
+
 }  // namespace hardware
 }  // namespace android
 
diff --git a/base/include/hidl/HidlInternal.h b/base/include/hidl/HidlInternal.h
index 80543c0..24e17cb 100644
--- a/base/include/hidl/HidlInternal.h
+++ b/base/include/hidl/HidlInternal.h
@@ -18,10 +18,6 @@
 #define ANDROID_HIDL_INTERNAL_H
 
 #include <cstdint>
-#include <dirent.h>
-#include <functional>
-#include <string>
-#include <vector>
 #include <utility>
 
 namespace android {
@@ -97,84 +93,6 @@
     };
 };
 
-#if defined(__LP64__)
-#define HAL_LIBRARY_PATH_SYSTEM "/system/lib64/hw/"
-#define HAL_LIBRARY_PATH_VENDOR "/vendor/lib64/hw/"
-#define HAL_LIBRARY_PATH_ODM "/odm/lib64/hw/"
-#else
-#define HAL_LIBRARY_PATH_SYSTEM "/system/lib/hw/"
-#define HAL_LIBRARY_PATH_VENDOR "/vendor/lib/hw/"
-#define HAL_LIBRARY_PATH_ODM "/odm/lib/hw/"
-#endif
-
-// ----------------------------------------------------------------------
-// Class that provides Hidl instrumentation utilities.
-struct HidlInstrumentor {
-    // Event that triggers the instrumentation. e.g. enter of an API call on
-    // the server/client side, exit of an API call on the server/client side
-    // etc.
-    enum InstrumentationEvent {
-        SERVER_API_ENTRY = 0,
-        SERVER_API_EXIT,
-        CLIENT_API_ENTRY,
-        CLIENT_API_EXIT,
-        SYNC_CALLBACK_ENTRY,
-        SYNC_CALLBACK_EXIT,
-        ASYNC_CALLBACK_ENTRY,
-        ASYNC_CALLBACK_EXIT,
-        PASSTHROUGH_ENTRY,
-        PASSTHROUGH_EXIT,
-    };
-
-    // Signature of the instrumentation callback function.
-    using InstrumentationCallback = std::function<void(
-            const InstrumentationEvent event,
-            const char *package,
-            const char *version,
-            const char *interface,
-            const char *method,
-            std::vector<void *> *args)>;
-
-    explicit HidlInstrumentor(
-            const std::string &package,
-            const std::string &insterface);
-    virtual ~HidlInstrumentor();
-
- protected:
-    // Set mEnableInstrumentation based on system property
-    // hal.instrumentation.enable, register/de-register instrumentation
-    // callbacks if mEnableInstrumentation is true/false.
-    void configureInstrumentation(bool log=true);
-    // Function that lookup and dynamically loads the hidl instrumentation
-    // libraries and registers the instrumentation callback functions.
-    //
-    // The instrumentation libraries should be stored under any of the following
-    // directories: HAL_LIBRARY_PATH_SYSTEM, HAL_LIBRARY_PATH_VENDOR and
-    // HAL_LIBRARY_PATH_ODM. The name of instrumentation libraries should
-    // follow pattern: ^profilerPrefix(.*).profiler.so$
-    //
-    // Each instrumentation library is expected to implement the instrumentation
-    // function called HIDL_INSTRUMENTATION_FUNCTION.
-    //
-    // A no-op for user build.
-    void registerInstrumentationCallbacks(
-            std::vector<InstrumentationCallback> *instrumentationCallbacks);
-
-    // Utility function to determine whether a give file is a instrumentation
-    // library (i.e. the file name follow the expected pattern).
-    bool isInstrumentationLib(const dirent *file);
-
-    // A list of registered instrumentation callbacks.
-    std::vector<InstrumentationCallback> mInstrumentationCallbacks;
-    // Flag whether to enable instrumentation.
-    bool mEnableInstrumentation;
-    // Prefix to lookup the instrumentation libraries.
-    std::string mInstrumentationLibPackage;
-    // Used for dlsym to load the profiling method for given interface.
-    std::string mInterfaceName;
-
-};
-
 }  // namespace details
 }  // namespace hardware
 }  // namespace android
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 80f95b6..6c00c3d 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -19,8 +19,11 @@
 
 #include <algorithm>
 #include <array>
+#include <dirent.h>
 #include <iterator>
 #include <cutils/native_handle.h>
+#include <cutils/properties.h>
+#include <functional>
 #include <hidl/HidlInternal.h>
 #include <hidl/Status.h>
 #include <map>
@@ -792,6 +795,84 @@
     return hidl_version(major,minor);
 }
 
+#if defined(__LP64__)
+#define HAL_LIBRARY_PATH_SYSTEM "/system/lib64/hw/"
+#define HAL_LIBRARY_PATH_VENDOR "/vendor/lib64/hw/"
+#define HAL_LIBRARY_PATH_ODM "/odm/lib64/hw/"
+#else
+#define HAL_LIBRARY_PATH_SYSTEM "/system/lib/hw/"
+#define HAL_LIBRARY_PATH_VENDOR "/vendor/lib/hw/"
+#define HAL_LIBRARY_PATH_ODM "/odm/lib/hw/"
+#endif
+
+// ----------------------------------------------------------------------
+// Class that provides Hidl instrumentation utilities.
+struct HidlInstrumentor {
+    // Event that triggers the instrumentation. e.g. enter of an API call on
+    // the server/client side, exit of an API call on the server/client side
+    // etc.
+    enum InstrumentationEvent {
+        SERVER_API_ENTRY = 0,
+        SERVER_API_EXIT,
+        CLIENT_API_ENTRY,
+        CLIENT_API_EXIT,
+        SYNC_CALLBACK_ENTRY,
+        SYNC_CALLBACK_EXIT,
+        ASYNC_CALLBACK_ENTRY,
+        ASYNC_CALLBACK_EXIT,
+        PASSTHROUGH_ENTRY,
+        PASSTHROUGH_EXIT,
+    };
+
+    // Signature of the instrumentation callback function.
+    using InstrumentationCallback = std::function<void(
+            const InstrumentationEvent event,
+            const char *package,
+            const char *version,
+            const char *interface,
+            const char *method,
+            std::vector<void *> *args)>;
+
+    explicit HidlInstrumentor(
+            const std::string &package,
+            const std::string &insterface);
+    virtual ~HidlInstrumentor();
+
+ protected:
+    // Set mEnableInstrumentation based on system property
+    // hal.instrumentation.enable, register/de-register instrumentation
+    // callbacks if mEnableInstrumentation is true/false.
+    void configureInstrumentation(bool log=true);
+    // Function that lookup and dynamically loads the hidl instrumentation
+    // libraries and registers the instrumentation callback functions.
+    //
+    // The instrumentation libraries should be stored under any of the following
+    // directories: HAL_LIBRARY_PATH_SYSTEM, HAL_LIBRARY_PATH_VENDOR and
+    // HAL_LIBRARY_PATH_ODM. The name of instrumentation libraries should
+    // follow pattern: ^profilerPrefix(.*).profiler.so$
+    //
+    // Each instrumentation library is expected to implement the instrumentation
+    // function called HIDL_INSTRUMENTATION_FUNCTION.
+    //
+    // A no-op for user build.
+    void registerInstrumentationCallbacks(
+            std::vector<InstrumentationCallback> *instrumentationCallbacks);
+
+    // Utility function to determine whether a give file is a instrumentation
+    // library (i.e. the file name follow the expected pattern).
+    bool isInstrumentationLib(const dirent *file);
+
+    // A list of registered instrumentation callbacks.
+    std::vector<InstrumentationCallback> mInstrumentationCallbacks;
+    // Flag whether to enable instrumentation.
+    bool mEnableInstrumentation;
+    // Prefix to lookup the instrumentation libraries.
+    std::string mInstrumentationLibPackage;
+    // Used for dlsym to load the profiling method for given interface.
+    std::string mInterfaceName;
+
+};
+
 ///////////////////// toString functions
 
 namespace details {