Running streset process if persist.vendor.nfc.streset is defined

running streset tool every time at startup

Bug: 160672745
Test: load streset tool
Merged-In: Ib0f89f7d01cd2d0eccf6a4e5be4601a9d5892658
Change-Id: Ib0f89f7d01cd2d0eccf6a4e5be4601a9d5892658
diff --git a/1.2/StNfcService.cpp b/1.2/StNfcService.cpp
index 9624c32..a5b7b70 100644
--- a/1.2/StNfcService.cpp
+++ b/1.2/StNfcService.cpp
@@ -18,13 +18,16 @@
  ******************************************************************************/
 
 #define LOG_TAG "stnfc@1.2-service.st"
+#include <android-base/properties.h>
 #include <android/hardware/nfc/1.1/INfc.h>
-#include <cutils/properties.h>
 #include <dlfcn.h>
 
 #include <hidl/LegacySupport.h>
 #include "Nfc.h"
 
+#define VENDOR_LIB_PATH "/vendor/lib64/"
+#define VENDOR_LIB_EXT ".so"
+
 // Generated HIDL files
 using android::OK;
 using android::sp;
@@ -40,26 +43,23 @@
   ALOGD(" ST NFC HAL Service 1.2 is starting.");
   sp<INfc> nfc_service = new Nfc();
 
-  char valueStr[PROPERTY_VALUE_MAX] = {0};
-  //Running streset after factory data reset
-  int len = property_get("persist.vendor.modem.esim.reset", valueStr, "needed");
-  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.");
+  std::string valueStr =
+      android::base::GetProperty("persist.vendor.nfc.streset", "");
+  if (valueStr.length() > 0) {
+    valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT;
+    void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
+    ALOGD("ST NFC HAL STReset starting.");
+    if (stdll) {
+      ALOGD("STReset Start");
+      STEseReset fn = (STEseReset)dlsym(stdll, "boot_reset");
+      if (fn) {
+        ALOGD("STReset Result=%d", fn());
       }
-      ALOGE(" ST NFC HAL eSIM Reset Done.");
+    } else {
+      ALOGE("%s not found, do nothing.", valueStr.c_str());
     }
+    ALOGD("ST NFC HAL STReset Done.");
   }
-  property_set("persist.vendor.modem.esim.reset", "done");
 
   configureRpcThreadpool(1, true /*callerWillJoin*/);
   status_t status = nfc_service->registerAsService();
diff --git a/1.2/hal_st21nfc.cc b/1.2/hal_st21nfc.cc
index 0aa6b89..9cbd19f 100644
--- a/1.2/hal_st21nfc.cc
+++ b/1.2/hal_st21nfc.cc
@@ -20,7 +20,8 @@
  *
  ******************************************************************************/
 
-#include <cutils/properties.h>
+#include <android-base/properties.h>
+#include <dlfcn.h>
 #include <errno.h>
 #include <hardware/nfc.h>
 #include <string.h>
@@ -30,10 +31,15 @@
 #include "hal_config.h"
 #include "halcore.h"
 
+#define VENDOR_LIB_PATH "/vendor/lib64/"
+#define VENDOR_LIB_EXT ".so"
+
 extern void HalCoreCallback(void* context, uint32_t event, const void* d,
                             size_t length);
 extern bool I2cOpenLayer(void* dev, HAL_CALLBACK callb, HALHANDLE* pHandle);
 
+typedef int (*STEseReset)(void);
+
 typedef struct {
   struct nfc_nci_device nci_device;  // nci_device must be first struct member
   // below declarations are private variables within HAL
@@ -376,6 +382,22 @@
     return -1;  // We are doomed, stop it here, NOW !
   }
 
+  std::string valueStr =
+      android::base::GetProperty("persist.vendor.nfc.streset", "");
+  if (valueStr.length() > 0) {
+    valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT;
+    void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
+    if (stdll) {
+      STLOG_HAL_D("STReset Cold reset");
+      STEseReset fn = (STEseReset)dlsym(stdll, "cold_reset");
+      if (fn) {
+        STLOG_HAL_D("STReset Result=%d", fn());
+      }
+    } else {
+      STLOG_HAL_D("%s not found, do nothing.", valueStr.c_str());
+    }
+  }
+
   STLOG_HAL_D("HAL st21nfc: %s close", __func__);
   return 0;
 }