Update eSE init and reset process for hidl 1.2

Add ST init process to wait for STReset at boot
Add the ability to load streset lib from the path defined from the property directly

Bug: 228898178
Bug: 235074864
Test: check esim reset complete before eSE1 hal service up
Change-Id: Ic358ebe58b43dd9606ce556bd2a05d041a832368
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(