1 alexa-voiceagent-service: update config and database file paths
3 Tweak getDataRootPath in the AASBConfigProviderImpl class to use the
4 AFM_WORKDIR environment variable as the basis for the path, which
5 moves things from the binding installation hierarchy into the app
6 framework's provided application data directory. This avoids the
7 permissions problems stemming from the new security model of running
8 as non-root. Also reworked the main configuration JSON file location
9 logic to use a new helper member function that checks for the file
10 in /etc/xdg/AGL and then in AFM_WORKDIR (app-data directory), before
11 falling back to the original location in var/config under the binding
12 installation directory. The local copy of GetBindingDirPath has been
13 removed, as it seems to be working fine now that the binding is being
14 built with AFB_BINDING_VERSION = 3.
16 Upstream-Status: Pending
18 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
20 diff --git a/src/plugins/aasb-client/config/AASBConfigProviderImpl.cpp b/src/plugins/aasb-client/config/AASBConfigProviderImpl.cpp
21 index b51185c..5d5c3ba 100644
22 --- a/src/plugins/aasb-client/config/AASBConfigProviderImpl.cpp
23 +++ b/src/plugins/aasb-client/config/AASBConfigProviderImpl.cpp
28 +#include <sys/stat.h>
30 #include <rapidjson/document.h>
31 #include <rapidjson/istreamwrapper.h>
32 @@ -36,6 +37,9 @@ using Level = agl::common::interfaces::ILogger::Level;
33 /// Logging tag for this file.
34 static std::string TAG = "agl::alexa::AASBConfigProviderImpl";
36 +/// Directory where user over-ride alexa json configuration may be.
37 +static std::string ALEXA_CONFIG_FILE_OVERRIDE_DIR = "/etc/xdg/AGL/";
39 /// File name where alexa json configuration is stored.
40 static std::string ALEXA_CONFIG_FILE_NAME = "AlexaAutoCoreEngineConfig.json";
42 @@ -64,8 +68,7 @@ AASBConfigProviderImpl::AASBConfigProviderImpl(std::shared_ptr<agl::common::inte
43 m_enableLocalVoiceControl(false) {
44 m_LocalVoiceControlConfiguration = std::unique_ptr<LVCConfiguration>(new LVCConfiguration());
45 m_carControlConfiguration = std::unique_ptr<CarControlConfiguration>(new CarControlConfiguration());
46 - std::string alexaConfigFile = getDataRootPath() + ALEXA_CONFIG_FILE_NAME;
47 - initConfigFromFile(alexaConfigFile);
48 + initConfigFromFile(getAlexaConfigPath());
49 logCurrentConfiguration();
52 @@ -520,32 +523,25 @@ void AASBConfigProviderImpl::initConfigFromFile(const std::string& fileName) {
56 -// GetBindingDirPath() method provided by AGL SDK crashes every single time.
57 -// It turns out that on latest AGL platforms, GetBindingDirPath(afb_api_t) version
58 -// is supposed to be the correct version. However when we include filescan-utils.h
59 -// it compiles a version without "afb_api_t" parameter. For now, I have made a
60 -// copy of this method here which accepts "afb_api_t" parameter.
62 -std::string GetBindingDirectoryPath(afb_api_t api) {
63 - // A file description should not be greater than 999.999.999
64 - char fd_link[CONTROL_MAXPATH_LEN];
65 - char retdir[CONTROL_MAXPATH_LEN];
67 - sprintf(fd_link, "/proc/self/fd/%d", afb_dynapi_rootdir_get_fd(api));
69 - if ((len = readlink(fd_link, retdir, sizeof(retdir) - 1)) == -1) {
71 - strncpy(retdir, "/tmp", CONTROL_MAXPATH_LEN - 1);
76 - return std::string(retdir);
77 +std::string AASBConfigProviderImpl::getDataRootPath() {
78 + std::string workDir(getenv("AFM_WORKDIR"));
79 + return workDir + "/";
82 -std::string AASBConfigProviderImpl::getDataRootPath() {
83 - std::string bindingDir(GetBindingDirectoryPath(m_api));
84 - return bindingDir + "/var/config/";
85 +std::string AASBConfigProviderImpl::getAlexaConfigPath() {
86 + struct stat statbuf;
88 + // Look in over-ride directory first
89 + std::string configPath = ALEXA_CONFIG_FILE_OVERRIDE_DIR + ALEXA_CONFIG_FILE_NAME;
90 + if(stat(configPath.c_str(), &statbuf) != 0) {
91 + // Look in work directory (app-data) next
92 + configPath = getDataRootPath() + ALEXA_CONFIG_FILE_NAME;
93 + if(stat(configPath.c_str(), &statbuf) != 0) {
94 + // Fall back to default version in widget
95 + configPath = std::string(GetBindingDirPath(m_api)) + "/var/config/" + ALEXA_CONFIG_FILE_NAME;
101 void AASBConfigProviderImpl::logCurrentConfiguration() {
102 diff --git a/src/plugins/aasb-client/config/AASBConfigProviderImpl.h b/src/plugins/aasb-client/config/AASBConfigProviderImpl.h
103 index 6b79994..e32f7b7 100644
104 --- a/src/plugins/aasb-client/config/AASBConfigProviderImpl.h
105 +++ b/src/plugins/aasb-client/config/AASBConfigProviderImpl.h
106 @@ -87,6 +87,11 @@ private:
108 std::string getDataRootPath();
111 + * Provides the path where alexa json config resides.
113 + std::string getAlexaConfigPath();
116 * Logs the current configuration loaded by this object.
118 @@ -139,4 +144,4 @@ private:
122 -#endif // AGL_ALEXA_SVC_AASB_CONFIG_PROVIDER_IMPL_H_
123 \ No newline at end of file
124 +#endif // AGL_ALEXA_SVC_AASB_CONFIG_PROVIDER_IMPL_H_