add magic property.* value for accessing system property variables

Change-Id: Ic916da6e7ecbf79396febfe1e5f0b0ae8570083f
This commit is contained in:
Xuefer
2015-03-26 22:45:04 +08:00
committed by Ethan Yonker
parent 26ffa869d0
commit a163f15eec

View File

@@ -48,9 +48,7 @@
#include "find_file.hpp"
#include "set_metadata.h"
#ifdef TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID
#include "cutils/properties.h"
#endif
#include "cutils/properties.h"
#ifndef TW_MAX_BRIGHTNESS
#define TW_MAX_BRIGHTNESS 255
@@ -367,6 +365,15 @@ int DataManager::GetValue(const string varName, string& value)
// Handle magic values
if (GetMagicValue(localStr, value) == 0)
return 0;
// Handle property
if (localStr.length() > 9 && localStr.substr(0, 9) == "property.") {
char property_value[PROPERTY_VALUE_MAX];
property_get(localStr.substr(9).c_str(), property_value, "");
value = property_value;
return 0;
}
map<string, string>::iterator constPos;
constPos = mConstValues.find(localStr);
if (constPos != mConstValues.end())
@@ -444,6 +451,14 @@ int DataManager::SetValue(const string varName, string value, int persist /* = 0
if (!mInitialized)
SetDefaultValues();
// Handle property
if (varName.length() > 9 && varName.substr(0, 9) == "property.") {
int ret = property_set(varName.substr(9).c_str(), value.c_str());
if (ret)
LOGERR("Error setting property '%s' to '%s'\n", varName.substr(9).c_str(), value.c_str());
return ret;
}
// Don't allow empty values or numerical starting values
if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
return -1;