Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 1 | /* |
Li Sun | f1d739f | 2019-02-14 11:37:55 -0500 | [diff] [blame] | 2 | * Copyright (c) 2017 - 2019, The Linux Foundation. All rights reserved. |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 3 | * |
| 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 Kanamarlapudi | 3b60a57 | 2018-03-05 16:26:27 +0530 | [diff] [blame] | 33 | #include <utils/Log.h> |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 34 | #include <sys/mman.h> |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 35 | #include "PlatformConfig.h" |
| 36 | #include "ConfigParser.h" |
| 37 | |
Li Sun | f1d739f | 2019-02-14 11:37:55 -0500 | [diff] [blame] | 38 | #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 Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 43 | namespace Platform { |
| 44 | |
Umesh Pandey | 8ecad1b | 2017-07-06 15:02:31 -0700 | [diff] [blame] | 45 | #define PLAT_CONFIG_FILE "/vendor/etc/system_properties.xml" |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 46 | |
| 47 | Config* Config::mInstance; |
| 48 | |
| 49 | Config::Config() { |
| 50 | Platform::ConfigParser::initAndParse(PLAT_CONFIG_FILE, mConfigMap); |
| 51 | } |
| 52 | |
| 53 | Config* Config::getInstance() { |
shubham | abd71cf | 2018-08-01 23:16:46 +0530 | [diff] [blame] | 54 | VIDC_PLAT_LOGH("%s: Enter", __func__); |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 55 | if (!mInstance) { |
| 56 | mInstance = new Config(); |
| 57 | } |
| 58 | return mInstance; |
| 59 | } |
| 60 | |
| 61 | ConfigError_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()) { |
shubham | abd71cf | 2018-08-01 23:16:46 +0530 | [diff] [blame] | 69 | VIDC_PLAT_LOGH("%s: Returning default", __func__); |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 70 | *value = defaultValue; |
| 71 | return FAIL; |
| 72 | } |
| 73 | *value = (int32_t) atoi(conf->mConfigMap[configStrMap[config].name].c_str()); |
shubham | abd71cf | 2018-08-01 23:16:46 +0530 | [diff] [blame] | 74 | VIDC_PLAT_LOGH("%s Config name: %s value: %d", |
Amit Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 75 | __func__, configStrMap[config].name, *value); |
| 76 | return OK; |
| 77 | } |
| 78 | |
Li Sun | f1d739f | 2019-02-14 11:37:55 -0500 | [diff] [blame] | 79 | bool Config::isConfigStoreEnabled() |
| 80 | { |
| 81 | #ifdef ENABLE_CONFIGSTORE |
| 82 | return true; |
| 83 | #else |
| 84 | return false; |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | ConfigError_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 B | 84521b9 | 2019-07-16 19:20:53 +0530 | [diff] [blame^] | 115 | CommandResult result = {Result::NOT_FOUND, 0}; |
Li Sun | f1d739f | 2019-02-14 11:37:55 -0500 | [diff] [blame] | 116 | 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 Shekhar | 580a327 | 2017-04-05 15:50:21 -0700 | [diff] [blame] | 142 | } |