[go: nahoru, domu]

blob: 9a5bdbd50ce9b600a77d79ce8e123378bebd88dd [file] [log] [blame]
Amit Shekhar580a3272017-04-05 15:50:21 -07001/*
Li Sunf1d739f2019-02-14 11:37:55 -05002 * Copyright (c) 2017 - 2019, The Linux Foundation. All rights reserved.
Amit Shekhar580a3272017-04-05 15:50:21 -07003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#define LOG_TAG "PlatformConfig"
31
32#include <errno.h>
Manikanta Kanamarlapudi3b60a572018-03-05 16:26:27 +053033#include <utils/Log.h>
Amit Shekhar580a3272017-04-05 15:50:21 -070034#include <sys/mman.h>
Amit Shekhar580a3272017-04-05 15:50:21 -070035#include "PlatformConfig.h"
36#include "ConfigParser.h"
37
Li Sunf1d739f2019-02-14 11:37:55 -050038#ifdef ENABLE_CONFIGSTORE
39#include <vendor/qti/hardware/capabilityconfigstore/1.0/types.h>
40#include <vendor/qti/hardware/capabilityconfigstore/1.0/ICapabilityConfigStore.h>
41#endif
42
Amit Shekhar580a3272017-04-05 15:50:21 -070043namespace Platform {
44
Umesh Pandey8ecad1b2017-07-06 15:02:31 -070045#define PLAT_CONFIG_FILE "/vendor/etc/system_properties.xml"
Amit Shekhar580a3272017-04-05 15:50:21 -070046
47Config* Config::mInstance;
48
49Config::Config() {
50 Platform::ConfigParser::initAndParse(PLAT_CONFIG_FILE, mConfigMap);
51}
52
53Config* Config::getInstance() {
shubhamabd71cf2018-08-01 23:16:46 +053054 VIDC_PLAT_LOGH("%s: Enter", __func__);
Amit Shekhar580a3272017-04-05 15:50:21 -070055 if (!mInstance) {
56 mInstance = new Config();
57 }
58 return mInstance;
59}
60
61ConfigError_t Config::getInt32(Config_t config, int32_t *value,
62 const int32_t defaultValue) {
63 Config *conf = getInstance();
64 if (conf == nullptr) {
65 *value = defaultValue;
66 return FAIL;
67 }
68 if (conf->mConfigMap.find(configStrMap[config].name) == conf->mConfigMap.end()) {
shubhamabd71cf2018-08-01 23:16:46 +053069 VIDC_PLAT_LOGH("%s: Returning default", __func__);
Amit Shekhar580a3272017-04-05 15:50:21 -070070 *value = defaultValue;
71 return FAIL;
72 }
73 *value = (int32_t) atoi(conf->mConfigMap[configStrMap[config].name].c_str());
shubhamabd71cf2018-08-01 23:16:46 +053074 VIDC_PLAT_LOGH("%s Config name: %s value: %d",
Amit Shekhar580a3272017-04-05 15:50:21 -070075 __func__, configStrMap[config].name, *value);
76 return OK;
77}
78
Li Sunf1d739f2019-02-14 11:37:55 -050079bool Config::isConfigStoreEnabled()
80{
81#ifdef ENABLE_CONFIGSTORE
82 return true;
83#else
84 return false;
85#endif
86}
87
88ConfigError_t Config::getConfigStoreBool(const char *area, const char *config,
89 bool &value, const bool defaultValue)
90{
91#ifdef ENABLE_CONFIGSTORE
92 using vendor::qti::hardware::capabilityconfigstore::V1_0::Result;
93 using vendor::qti::hardware::capabilityconfigstore::V1_0::CommandResult;
94 if (area == nullptr || config == nullptr) {
95 return FAIL;
96 }
97
98 value = defaultValue;
99
100 Config *conf = getInstance();
101 if (conf == nullptr) {
102 return FAIL;
103 }
104
105 // load on demand
106 if (conf->mConfigStore == nullptr) {
107 conf->mConfigStore = ICapabilityConfigStore::tryGetService();
108 }
109
110 if (conf->mConfigStore == nullptr) {
111 VIDC_PLAT_LOGH("%s: unable to get configstore service", __func__);
112 return FAIL;
113 }
114
Shrikara B84521b92019-07-16 19:20:53 +0530115 CommandResult result = {Result::NOT_FOUND, 0};
Li Sunf1d739f2019-02-14 11:37:55 -0500116 conf->mConfigStore->getConfig(area, config, [&](const CommandResult &res) {
117 result = res;
118 });
119
120 if (result.result_type != Result::SUCCESS) {
121 VIDC_PLAT_LOGH("%s: %s/%s not found(%u)", __func__, area, config,
122 result.result_type);
123 return FAIL;
124 }
125
126 if (strncasecmp("true", result.value.c_str(), result.value.size()) == 0) {
127 value = true;
128 } else {
129 value = false;
130 }
131 VIDC_PLAT_LOGH("%s: %s/%s=%s, returning %s ", __func__, area, config,
132 result.value.c_str(), value ? "true" : "false");
133 return OK;
134#else
135 (void)(area);
136 (void)(config);
137 value = defaultValue;
138 return OK;
139#endif
140}
141
Amit Shekhar580a3272017-04-05 15:50:21 -0700142}