Add ST eSE/eSIM Reset process

A proprietary process for a specific ST solution
Executed only when persist.vendor.modem.esim.reset needed.

Bug: 139319524
Bug: 137376072
Test: Reset eSE/eSIM part manually
Change-Id: I416753fe445740cdb83bfbef3c0aa4a32e2e06f6
diff --git a/1.2/StNfcService.cpp b/1.2/StNfcService.cpp
index ae6c8c0..9cad44a 100644
--- a/1.2/StNfcService.cpp
+++ b/1.2/StNfcService.cpp
@@ -19,6 +19,8 @@
 
 #define LOG_TAG "stnfc@1.2-service.st"
 #include <android/hardware/nfc/1.1/INfc.h>
+#include <cutils/properties.h>
+#include <dlfcn.h>
 
 #include <hidl/LegacySupport.h>
 #include "Nfc.h"
@@ -32,10 +34,32 @@
 using android::hardware::nfc::V1_2::INfc;
 using android::hardware::nfc::V1_2::implementation::Nfc;
 
+typedef int (*STEseReset)(void);
+
 int main() {
   ALOGD(" ST NFC HAL Service 1.2 is starting.");
   sp<INfc> nfc_service = new Nfc();
 
+  char valueStr[PROPERTY_VALUE_MAX] = {0};
+  int len = property_get("persist.vendor.modem.esim.reset", valueStr, "");
+  if (len > 0) {
+    if (strncmp(valueStr,"needed", 6) == 0) {
+      void* stdll = dlopen("/vendor/lib64/libstreset.so", RTLD_NOW);
+      ALOGE(" ST NFC HAL eSIM Reset starting.");
+      if(stdll) {
+        ALOGE(" Recovery");
+        STEseReset fn = (STEseReset) dlsym(stdll,"reset_start");
+        if(fn){
+          ALOGE("Result=%d", fn());
+        }
+      } else {
+        ALOGE("libstreset.so not found, do nothing.");
+      }
+      ALOGE(" ST NFC HAL eSIM Reset Done.");
+    }
+  }
+  property_set("persist.vendor.modem.esim.reset", "done");
+
   configureRpcThreadpool(1, true /*callerWillJoin*/);
   status_t status = nfc_service->registerAsService();
   if (status != OK) {