Add NFC configuration file search rules

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-hal-st-SKU.conf
3. If none of 1,2 is defined, search the default file
   "libnfc-hal-st.conf"

Bug: 152176567
Test: load different cfg files
Change-Id: Ibde553416fee6064d2422227b52bbac6842c8f51
diff --git a/st21nfc/adaptation/config.cpp b/st21nfc/adaptation/config.cpp
index 99c18eb..5724666 100644
--- a/st21nfc/adaptation/config.cpp
+++ b/st21nfc/adaptation/config.cpp
@@ -20,6 +20,7 @@
  *
  *
  ******************************************************************************/
+#include <android-base/properties.h>
 #include <log/log.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -33,7 +34,7 @@
 const int transport_config_path_size =
     (sizeof(transport_config_paths) / sizeof(transport_config_paths[0]));
 #define config_name "libnfc-hal-st.conf"
-#define extra_config_base "libnfc-st-"
+#define extra_config_base "libnfc-hal-st-"
 #define extra_config_ext ".conf"
 #define IsStringValue 0x80000000
 
@@ -143,17 +144,18 @@
 ** Returns:     none
 **
 *******************************************************************************/
-void findConfigFile(const string& configName, string& filePath) {
+bool findConfigFile(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;
 }
 
 /*******************************************************************************
@@ -381,7 +383,20 @@
         return theInstance;
       }
     }
-    findConfigFile(config_name, strPath);
+
+    if (findConfigFile(android::base::GetProperty(
+                           "persist.vendor.nfc.config_file_name", ""),
+                       strPath)) {
+      STLOG_HAL_D("%s Get config file %s\n", __func__, strPath.c_str());
+    } else if (findConfigFile(extra_config_base +
+                                  android::base::GetProperty(
+                                      "ro.boot.product.hardware.sku", "") +
+                                  extra_config_ext,
+                              strPath)) {
+      STLOG_HAL_D("%s Get config file %s\n", __func__, strPath.c_str());
+    } else {
+      findConfigFile(config_name, strPath);
+    }
     theInstance.readConfig(strPath.c_str(), true);
   }