You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.7 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2020. All rights reserved.
* Description: BootVideo Configer
*/
#include "BootvideoConfiger.h"
#include <string>
#include <utils/Log.h>
#include <cutils/klog.h>
#undef LOG_TAG
#define LOG_TAG "BootVideo"
namespace android {
using namespace std;
using namespace tinyxml2;
const string BootvideoConfiger::PROPERTY_EN_UI = "isEnableUI";
const string BootvideoConfiger::PROPERTY_EN_COUNTDOWN = "isEnableCountDown";
const string BootvideoConfiger::PROPERTY_EN_VOLUMEBAR = "isEnableVolumeBar";
const string BootvideoConfiger::PROPERTY_EN_VOLUMEMUTE = "isEnableVolumeMute";
const string BootvideoConfiger::PROPERTY_EN_INPUT = "isEnableInput";
const string BootvideoConfiger::PROPERTY_PATH_FIRST = "path1";
const string BootvideoConfiger::PROPERTY_PATH_STR_FIRST = "strPath1";
const int VALUE_VIDEO_LIMIT = 20;
BootvideoConfiger::BootvideoConfiger()
{
}
BootvideoConfiger::~BootvideoConfiger()
{
}
// check support feature
bool BootvideoConfiger::IsFeature(const string property) const
{
string value = GetPropertyValue(property, "enable");
if (value == "true") {
return true;
}
return false;
}
// get value feature
string BootvideoConfiger::GetFeature(const string property) const
{
string value = GetPropertyValue(property, "value");
return value;
}
// get video limit time sec
int BootvideoConfiger::GetVideoLimit() const
{
string temp = GetFeature(PROPERTY_VIDEO_LIMIT);
int value = std::atoi(temp.c_str());
if (value != 0) {
return value;
} else {
return VALUE_VIDEO_LIMIT;
}
}
// check count language
bool BootvideoConfiger::IsCountDownCH() const
{
string value = GetPropertyValue(PROPERTY_EN_COUNTDOWN, "language");
if (value == "ch") {
return true;
}
return false;
}
// load config.xml or default.xml
void BootvideoConfiger::InitConfiger(tinyxml2::XMLDocument& document) const
{
document.LoadFile(CONFIG_DEFAULT_PATH.c_str());
if (document.ErrorID() != 0) {
ALOGE("load %s failed, set default config", CONFIG_DEFAULT_PATH.c_str());
document.Parse(CONFIG_DEFAULT_XML.c_str());
}
}
/**
* name: GetPropertyValue
* function: get bootvideo property attribute in the config.xml
* param property: property is a feature, and attribute key is the feature of identity
* param attribute: property may have many attribute
* return: attribute corresponding value
*/
string BootvideoConfiger::GetPropertyValue(const string property, const string attr) const
{
auto mDocument = std::make_unique<tinyxml2::XMLDocument>();
InitConfiger(*mDocument);
// get xml root element
XMLElement* root = mDocument->RootElement();
if (root == nullptr) {
ALOGD("config xml not have root element");
return "";
}
// get xml bootvideo element
XMLElement* bootVideoElement = root->FirstChildElement(CONFIG_MODULE_BOOTVIDEO.c_str());
if (bootVideoElement == nullptr) {
ALOGD("config xml not have %s element", CONFIG_MODULE_BOOTVIDEO.c_str());
return "";
}
// get attribute value int the root element
string propertyValue = GetElementValue(bootVideoElement, property, attr);
if (propertyValue.empty()) {
ALOGD("config xml not have %s property", property.c_str());
}
return propertyValue;
}
/**
* name: GetElementValue
* function: find attribute in the element
* param element: the element int the xml
* param attrKey: property unique identifier int the element
* param attrName: the user wants to access attribute
* return: attrName corresponding value
*/
string BootvideoConfiger::GetElementValue(const XMLElement *element, const string attrKey, const string attrName) const
{
if (element == nullptr) {
return "";
}
const XMLElement* childElement = element->FirstChildElement(CONFIG_ITEM_PROPERTY.c_str());
while (childElement != nullptr) {
// find attribute key
const char* key = childElement->Attribute("key", attrKey.c_str());
if (key != nullptr) {
// get attribute value
const char* attrValue = childElement->Attribute(attrName.c_str());
if (attrValue != nullptr) {
return string(attrValue);
}
} else {
// find attribute int child element
string attrValue = GetElementValue(childElement, attrKey, attrName);
if (!attrValue.empty()) {
return attrValue;
}
}
// move index to next element
childElement = childElement->NextSiblingElement(CONFIG_ITEM_PROPERTY.c_str());
}
return "";
}
} // namespace android