Update eSE init and reset process for hidl 1.2 am: ac67014519 am: 02083647df

Original change: https://android-review.googlesource.com/c/platform/hardware/st/secure_element/+/2170111

Change-Id: Ieffb56d14ee351189db37973b369c0ac72a9a32a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/1.2/SecureElement.cpp b/1.2/SecureElement.cpp
index 0ec90ae..b8b020f 100644
--- a/1.2/SecureElement.cpp
+++ b/1.2/SecureElement.cpp
@@ -523,6 +523,7 @@
 Return<::android::hardware::secure_element::V1_0::SecureElementStatus>
 SecureElement::reset() {
   int ret = 0;
+  void* stdll = nullptr;
   ESESTATUS status = ESESTATUS_SUCCESS;
   SecureElementStatus sestatus = SecureElementStatus::FAILED;
   std::string valueStr =
@@ -534,8 +535,11 @@
     if (status != ESESTATUS_SUCCESS) {
       STLOG_HAL_E("%s: seHalInit Failed!!!", __func__);
       if (valueStr.length() > 0) {
-        valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT;
-        void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
+        stdll = dlopen(valueStr.c_str(), RTLD_NOW);
+        if (!stdll) {
+          valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT;
+          stdll = dlopen(valueStr.c_str(), RTLD_NOW);
+        }
         if (stdll) {
           STEseReset fn = (STEseReset)dlsym(stdll, "direct_reset");
           if (fn) {
diff --git a/1.2/StEseService.cpp b/1.2/StEseService.cpp
index 7fa8e9f..c6faef3 100644
--- a/1.2/StEseService.cpp
+++ b/1.2/StEseService.cpp
@@ -17,12 +17,16 @@
  *
  ******************************************************************************/
 #define LOG_TAG "ese@1.2-service.st"
+#include <android-base/properties.h>
 #include <android/hardware/secure_element/1.2/ISecureElement.h>
+#include <dlfcn.h>
 #include <hidl/LegacySupport.h>
 #include <log/log.h>
 
 #include "SecureElement.h"
 
+typedef int (*STEsePreProcess)(void);
+
 // Generated HIDL files
 using android::OK;
 using android::sp;
@@ -36,6 +40,22 @@
   ALOGD("Secure Element HAL Service 1.2 is starting.");
   sp<ISecureElement> se_service = new SecureElement();
   configureRpcThreadpool(1, true /*callerWillJoin*/);
+
+  // Ignore this dlopen if you don't need it.
+  std::string valueStr =
+      android::base::GetProperty("persist.vendor.se.stpreprocess", "");
+  void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
+  if (stdll) {
+    STEsePreProcess fn = (STEsePreProcess)dlsym(stdll, "pre_process");
+    if (fn) {
+      if (fn() == 0) {
+        ALOGD("%s: init done", __func__);
+      } else {
+        ALOGE("%s: Error init ", __func__);
+      }
+    }
+  }
+
   status_t status = se_service->registerAsService("eSE1");
   if (status != OK) {
     LOG_ALWAYS_FATAL(