Update cfg files search rule

1. If prop_config_file_name is defined.
   (where prop_config_file_name is the value of the
   property (persist.vendor.nfc.config_file_name)
   Search a file matches prop_config_file_name.
2. If SKU is defined (where SKU is the value of the property
   ro.boot.product.hardware.sku)
   Search a file matches libnfc-nxp-SKU.conf
3. If none of 1,2 is defined, search the default file
   "libnfc-nxp.conf".
Bug: 148056494
Test: load correct cfg
Change-Id: Ia9a87ae9964a8c64ff07e51e42c3f6b2801e3c40
diff --git a/halimpl/utils/phNxpConfig.cpp b/halimpl/utils/phNxpConfig.cpp
index 546e04d..d5fca76 100755
--- a/halimpl/utils/phNxpConfig.cpp
+++ b/halimpl/utils/phNxpConfig.cpp
@@ -42,6 +42,7 @@
 #include <string>
 #include <vector>
 #include <log/log.h>
+#include <android-base/properties.h>
 
 #include <phNxpConfig.h>
 #include <phNxpLog.h>
@@ -203,18 +204,19 @@
 ** Returns:     none
 **
 *******************************************************************************/
-void findConfigFilePathFromTransportConfigPaths(const string& configName,
+bool findConfigFilePathFromTransportConfigPaths(const string& configName,
                                                 string& filePath) {
   for (int i = 0; i < transport_config_path_size - 1; i++) {
+    if (configName.empty()) break;
     filePath.assign(transport_config_paths[i]);
     filePath += configName;
     struct stat file_stat;
     if (stat(filePath.c_str(), &file_stat) == 0 && S_ISREG(file_stat.st_mode)) {
-      return;
+      return true;
     }
   }
-  filePath.assign(transport_config_paths[transport_config_path_size - 1]);
-  filePath += configName;
+  filePath = "";
+  return false;
 }
 
 /*******************************************************************************
@@ -444,7 +446,18 @@
         return theInstance;
       }
     }
-    findConfigFilePathFromTransportConfigPaths(config_name, strPath);
+    if (findConfigFilePathFromTransportConfigPaths(
+        android::base::GetProperty("persist.vendor.nfc.config_file_name", ""),
+        strPath)) {
+      NXPLOG_EXTNS_D("%s load %s\n", __func__,  strPath.c_str());
+    } else if (findConfigFilePathFromTransportConfigPaths(
+        extra_config_base +
+        android::base::GetProperty("ro.boot.product.hardware.sku", "") +
+        + extra_config_ext, strPath)) {
+      NXPLOG_EXTNS_D("%s load %s\n", __func__,  strPath.c_str());
+    } else {
+      findConfigFilePathFromTransportConfigPaths(config_name, strPath);
+    }
     theInstance.readConfig(strPath.c_str(), true);
   }