Treblize nfc config file location
Treblization requires to locate partner-specific configs in its own
partition. So the nfc config file could be located in /odm/etc or
/vendor/etc.
This CL is to support those locations for the config.
Test: building succeeded and tested on sailfish.
Bug: 35369237
Change-Id: I22840654044e142433a1d828cb8e382c48cd699f
(cherry picked from commit 264af28a9d10595ef0ece33463d93a592030a110)
diff --git a/halimpl/bcm2079x/adaptation/config.cpp b/halimpl/bcm2079x/adaptation/config.cpp
index f847389..7889a52 100644
--- a/halimpl/bcm2079x/adaptation/config.cpp
+++ b/halimpl/bcm2079x/adaptation/config.cpp
@@ -17,6 +17,7 @@
******************************************************************************/
#include "OverrideLog.h"
#include "config.h"
+#include <sys/stat.h>
#include <stdio.h>
#include <string>
#include <vector>
@@ -24,7 +25,9 @@
#define LOG_TAG "NfcNciHal"
-const char transport_config_path[] = "/etc/";
+const char* transport_config_paths[] = {"/odm/etc/", "/vendor/etc/", "/etc/"};
+const int transport_config_path_size =
+ (sizeof(transport_config_paths) / sizeof(transport_config_paths[0]));
#define config_name "libnfc-brcm.conf"
#define extra_config_base "libnfc-brcm-"
@@ -140,6 +143,30 @@
/*******************************************************************************
**
+** Function: findConfigFilePathFromTransportConfigPaths()
+**
+** Description: find a config file path with a given config name from transport
+** config paths
+**
+** Returns: none
+**
+*******************************************************************************/
+void findConfigFilePathFromTransportConfigPaths(const string& configName,
+ string& filePath) {
+ for (int i = 0; i < transport_config_path_size - 1; i++) {
+ 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;
+ }
+ }
+ filePath.assign(transport_config_paths[transport_config_path_size - 1]);
+ filePath += configName;
+}
+
+/*******************************************************************************
+**
** Function: CNfcConfig::readConfig()
**
** Description: read Config settings and parse them into a linked list
@@ -379,8 +406,7 @@
if (theInstance.size() == 0 && theInstance.mValidFile)
{
string strPath;
- strPath.assign(transport_config_path);
- strPath += config_name;
+ findConfigFilePathFromTransportConfigPaths(config_name, strPath);
theInstance.readConfig(strPath.c_str(), true);
}
@@ -727,10 +753,11 @@
void readOptionalConfig(const char* extra)
{
string strPath;
- strPath.assign(transport_config_path);
- strPath += extra_config_base;
- strPath += extra;
- strPath += extra_config_ext;
+ string configName(extra_config_base);
+ configName += extra;
+ configName += extra_config_ext;
+
+ findConfigFilePathFromTransportConfigPaths(configName, strPath);
CNfcConfig::GetInstance().readConfig(strPath.c_str(), false);
}
diff --git a/halimpl/pn54x/utils/phNxpConfig.cpp b/halimpl/pn54x/utils/phNxpConfig.cpp
index dc34f11..1f9ca7a 100644
--- a/halimpl/pn54x/utils/phNxpConfig.cpp
+++ b/halimpl/pn54x/utils/phNxpConfig.cpp
@@ -68,11 +68,13 @@
#endif
#if 1
-const char transport_config_path[] = "/etc/";
+const char* transport_config_paths[] = {"/odm/etc/", "/vendor/etc/", "/etc/"};
const char transit_config_path[] = "/data/nfc/";
#else
-const char transport_config_path[] = "res/";
+const char* transport_config_paths[] = {"res/"};
#endif
+const int transport_config_path_size =
+ (sizeof(transport_config_paths) / sizeof(transport_config_paths[0]));
#define config_name "libnfc-nxp.conf"
#if (NXP_EXTNS == TRUE)
@@ -463,6 +465,30 @@
/*******************************************************************************
**
+** Function: findConfigFilePathFromTransportConfigPaths()
+**
+** Description: find a config file path with a given config name from transport
+** config paths
+**
+** Returns: none
+**
+*******************************************************************************/
+void findConfigFilePathFromTransportConfigPaths(const string& configName,
+ string& filePath) {
+ for (int i = 0; i < transport_config_path_size - 1; i++) {
+ 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;
+ }
+ }
+ filePath.assign(transport_config_paths[transport_config_path_size - 1]);
+ filePath += configName;
+}
+
+/*******************************************************************************
+**
** Function: CNfcConfig::readConfig()
**
** Description: read Config settings and parse them into a linked list
@@ -779,8 +805,7 @@
return theInstance;
}
}
- strPath.assign(transport_config_path);
- strPath += config_name;
+ findConfigFilePathFromTransportConfigPaths(config_name, strPath);
//checks whether the default config file is present in th target
if (theInstance.file_exist(strPath.c_str())) {
ALOGI("default config file exists = %s, disables dynamic selection", strPath.c_str());
@@ -1307,13 +1332,17 @@
void readOptionalConfig(const char* extra)
{
string strPath;
- strPath.assign(transport_config_path);
- if (alternative_config_path[0] != '\0')
- strPath.assign(alternative_config_path);
+ string configName(extra_config_base);
+ configName += extra;
+ configName += extra_config_ext;
- strPath += extra_config_base;
- strPath += extra;
- strPath += extra_config_ext;
+ if (alternative_config_path[0] != '\0') {
+ strPath.assign(alternative_config_path);
+ strPath += configName;
+ } else {
+ findConfigFilePathFromTransportConfigPaths(configName, strPath);
+ }
+
CNfcConfig::GetInstance().readConfig(strPath.c_str(), false);
}
diff --git a/src/adaptation/config.cpp b/src/adaptation/config.cpp
index d20ceeb..7913fbc 100644
--- a/src/adaptation/config.cpp
+++ b/src/adaptation/config.cpp
@@ -37,6 +37,7 @@
#include "OverrideLog.h"
#include "config.h"
#include <stdio.h>
+#include <sys/stat.h>
#include <string>
#include <vector>
#include <list>
@@ -44,7 +45,9 @@
#undef LOG_TAG
#define LOG_TAG "NfcAdaptation"
-const char transport_config_path[] = "/etc/";
+const char* transport_config_paths[] = {"/odm/etc/", "/vendor/etc/", "/etc/"};
+const int transport_config_path_size =
+ (sizeof(transport_config_paths) / sizeof(transport_config_paths[0]));
#if(NXP_EXTNS == TRUE)
const char transit_config_path[] = "/data/nfc/";
@@ -175,6 +178,30 @@
/*******************************************************************************
**
+** Function: findConfigFilePathFromTransportConfigPaths()
+**
+** Description: find a config file path with a given config name from transport
+** config paths
+**
+** Returns: none
+**
+*******************************************************************************/
+void findConfigFilePathFromTransportConfigPaths(const string& configName,
+ string& filePath) {
+ for (int i = 0; i < transport_config_path_size - 1; i++) {
+ 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;
+ }
+ }
+ filePath.assign(transport_config_paths[transport_config_path_size - 1]);
+ filePath += configName;
+}
+
+/*******************************************************************************
+**
** Function: CNfcConfig::readConfig()
**
** Description: read Config settings and parse them into a linked list
@@ -432,8 +459,7 @@
if (theInstance.size() == 0 && theInstance.mValidFile)
{
string strPath;
- strPath.assign(transport_config_path);
- strPath += config_name;
+ findConfigFilePathFromTransportConfigPaths(config_name, strPath);
theInstance.readConfig(strPath.c_str(), true);
#if(NXP_EXTNS == TRUE)
readOptionalConfigExt("nxp_default");
@@ -872,9 +898,10 @@
void readOptionalConfigExt(const char* extra)
{
string strPath;
- strPath.assign(transport_config_path);
- strPath += extra_config_base;
- strPath += extra;
- strPath += extra_config_ext;
+ string configName(extra_config_base);
+ configName += extra;
+ configName += extra_config_ext;
+
+ findConfigFilePathFromTransportConfigPaths(configName, strPath);
CNfcConfig::GetInstance().readConfig(strPath.c_str(), false);
}