diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-03-10 01:04:43 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-03-10 01:04:44 +0000 |
| commit | dfacb1bea5c6eb19893ab003e5fd3e8aa0b49c7e (patch) | |
| tree | 3f4b5822978d582a58be10c50aeddbd38fd0b5de /halimpl | |
| parent | 93d393414cef36cf5b1d23df7c66b3265e596811 (diff) | |
| parent | 264af28a9d10595ef0ece33463d93a592030a110 (diff) | |
| download | android_hardware_broadcom_nfc-dfacb1bea5c6eb19893ab003e5fd3e8aa0b49c7e.tar.gz android_hardware_broadcom_nfc-dfacb1bea5c6eb19893ab003e5fd3e8aa0b49c7e.tar.bz2 android_hardware_broadcom_nfc-dfacb1bea5c6eb19893ab003e5fd3e8aa0b49c7e.zip | |
Merge "Treblize nfc config file location"
Diffstat (limited to 'halimpl')
| -rw-r--r-- | halimpl/bcm2079x/adaptation/config.cpp | 41 | ||||
| -rw-r--r-- | halimpl/pn54x/utils/phNxpConfig.cpp | 47 |
2 files changed, 72 insertions, 16 deletions
diff --git a/halimpl/bcm2079x/adaptation/config.cpp b/halimpl/bcm2079x/adaptation/config.cpp index bfb4e34..dcf46a9 100644 --- a/halimpl/bcm2079x/adaptation/config.cpp +++ b/halimpl/bcm2079x/adaptation/config.cpp @@ -20,12 +20,15 @@ #include "config.h" #include <stdio.h> +#include <sys/stat.h> #include <list> #include <string> #include <vector> #include "_OverrideLog.h" -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-" @@ -130,6 +133,30 @@ inline int getDigitValue(char c, int base) { /******************************************************************************* ** +** 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 @@ -332,8 +359,7 @@ CNfcConfig& CNfcConfig::GetInstance() { 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); } @@ -637,9 +663,10 @@ extern void resetConfig() { *******************************************************************************/ 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 aa73627..50bd7b6 100644 --- a/halimpl/pn54x/utils/phNxpConfig.cpp +++ b/halimpl/pn54x/utils/phNxpConfig.cpp @@ -52,10 +52,12 @@ const char alternative_config_path[] = ""; #endif #if 1 -const char transport_config_path[] = "/etc/"; +const char* transport_config_paths[] = {"/odm/etc/", "/vendor/etc/", "/etc/"}; #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" #define extra_config_base "libnfc-nxp-" @@ -166,6 +168,30 @@ inline int getDigitValue(char c, int base) { /******************************************************************************* ** +** 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 @@ -391,8 +417,7 @@ CNfcConfig& CNfcConfig::GetInstance() { return theInstance; } } - strPath.assign(transport_config_path); - strPath += config_name; + findConfigFilePathFromTransportConfigPaths(config_name, strPath); theInstance.readConfig(strPath.c_str(), true); } @@ -865,13 +890,17 @@ extern "C" void resetNxpConfig() *******************************************************************************/ void readOptionalConfig(const char* extra) { string strPath; - strPath.assign(transport_config_path); - if (alternative_config_path[0] != '\0') + string configName(extra_config_base); + configName += extra; + configName += extra_config_ext; + + if (alternative_config_path[0] != '\0') { strPath.assign(alternative_config_path); + strPath += configName; + } else { + findConfigFilePathFromTransportConfigPaths(configName, strPath); + } - strPath += extra_config_base; - strPath += extra; - strPath += extra_config_ext; CNfcConfig::GetInstance().readConfig(strPath.c_str(), false); } |
