[go: nahoru, domu]

media: add configstore and check it for vpp enablement

Reduction in property usage. Go to the configstore to check whether vpp
should be enabled, instead of checking vendor.media.vpp.enable. If the
configstore is not enabled, fall back to the sysprop.

Expose the configstore through libplatformconfig, by adding static
methods to the Config class. Add a ConfigStore wrapper to allow C
implementations to access the ConfigStore.

Change-Id: Icb6b247b19f0adc107be636517d97b293229eb34
diff --git a/libplatformconfig/PlatformConfig.cpp b/libplatformconfig/PlatformConfig.cpp
index 35237e8..cd8956b 100644
--- a/libplatformconfig/PlatformConfig.cpp
+++ b/libplatformconfig/PlatformConfig.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 - 2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017 - 2019, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -35,6 +35,11 @@
 #include "PlatformConfig.h"
 #include "ConfigParser.h"
 
+#ifdef ENABLE_CONFIGSTORE
+#include <vendor/qti/hardware/capabilityconfigstore/1.0/types.h>
+#include <vendor/qti/hardware/capabilityconfigstore/1.0/ICapabilityConfigStore.h>
+#endif
+
 namespace Platform {
 
 #define PLAT_CONFIG_FILE "/vendor/etc/system_properties.xml"
@@ -71,4 +76,67 @@
     return OK;
 }
 
+bool Config::isConfigStoreEnabled()
+{
+#ifdef ENABLE_CONFIGSTORE
+    return true;
+#else
+    return false;
+#endif
+}
+
+ConfigError_t Config::getConfigStoreBool(const char *area, const char *config,
+        bool &value, const bool defaultValue)
+{
+#ifdef ENABLE_CONFIGSTORE
+    using vendor::qti::hardware::capabilityconfigstore::V1_0::Result;
+    using vendor::qti::hardware::capabilityconfigstore::V1_0::CommandResult;
+    if (area == nullptr || config == nullptr) {
+        return FAIL;
+    }
+
+    value = defaultValue;
+
+    Config *conf = getInstance();
+    if (conf == nullptr) {
+        return FAIL;
+    }
+
+    // load on demand
+    if (conf->mConfigStore == nullptr) {
+        conf->mConfigStore = ICapabilityConfigStore::tryGetService();
+    }
+
+    if (conf->mConfigStore == nullptr) {
+        VIDC_PLAT_LOGH("%s: unable to get configstore service", __func__);
+        return FAIL;
+    }
+
+    CommandResult result;
+    conf->mConfigStore->getConfig(area, config, [&](const CommandResult &res) {
+        result = res;
+    });
+
+    if (result.result_type != Result::SUCCESS) {
+        VIDC_PLAT_LOGH("%s: %s/%s not found(%u)", __func__, area, config,
+                       result.result_type);
+        return FAIL;
+    }
+
+    if (strncasecmp("true", result.value.c_str(), result.value.size()) == 0) {
+        value = true;
+    } else {
+        value = false;
+    }
+    VIDC_PLAT_LOGH("%s: %s/%s=%s, returning %s ", __func__, area, config,
+            result.value.c_str(), value ? "true" : "false");
+    return OK;
+#else
+    (void)(area);
+    (void)(config);
+    value = defaultValue;
+    return OK;
+#endif
+}
+
 }