!672 修复部分数据未同步完成时查询接口返回成功问题

Merge pull request !672 from 张雷/master
This commit is contained in:
openharmony_ci 2024-09-26 14:07:20 +00:00 committed by Gitee
commit cd33df2dbb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 44 additions and 1 deletions

View File

@ -54,6 +54,12 @@ public:
static bool IsSvrProfileValid(const ServiceProfile& svrProfile);
// This mothed can be invoked only when put or delete profile.
static bool IsCharProfileValid(const CharacteristicProfile& charProfile);
// This mothed can be invoked only when get profile.
static bool IsDeviceProfileValid(const DeviceProfile& devProfile);
// This mothed can be invoked only when get profile.
static bool IsServiceProfileValid(const ServiceProfile& svrProfile);
// This mothed can be invoked only when get profile.
static bool IsCharacteristicProfileValid(const CharacteristicProfile& charProfile);
static std::string GenerateDeviceProfileKey(const std::string& deviceId);
static std::string GenerateServiceProfileKey(const std::string& deviceId, const std::string& serviceName);
static std::string GenerateCharProfileKey(const std::string& deviceId, const std::string& serviceName,

View File

@ -363,6 +363,30 @@ bool ProfileUtils::IsCharProfileValid(const CharacteristicProfile& charProfile)
IsKeyValid(charProfile.GetServiceName()) && IsKeyValid(charProfile.GetCharacteristicKey());
}
bool ProfileUtils::IsDeviceProfileValid(const DeviceProfile& devProfile)
{
if (devProfile.GetOsVersion().empty() || devProfile.GetOsType() == MIN_OS_TYPE) {
return false;
}
return true;
}
bool ProfileUtils::IsServiceProfileValid(const ServiceProfile& svrProfile)
{
if (svrProfile.GetServiceName().empty() || svrProfile.GetServiceType().empty()) {
return false;
}
return true;
}
bool ProfileUtils::IsCharacteristicProfileValid(const CharacteristicProfile& charProfile)
{
if (charProfile.GetCharacteristicKey().empty() || charProfile.GetCharacteristicValue().empty()) {
return false;
}
return true;
}
std::string ProfileUtils::GenerateDeviceProfileKey(const std::string& deviceId)
{
return DEV_PREFIX + SEPARATOR + deviceId;
@ -704,6 +728,7 @@ bool ProfileUtils::IsPropertyValid(const std::map<std::string, std::string>& pro
(static_cast<int32_t>(propertyMap.at(property).length())) < maxValue) {
return true;
}
HILOGE("property is valid, property : %{public}s", property.c_str());
return false;
}
@ -711,7 +736,7 @@ bool ProfileUtils::IsPropertyValid(const std::map<std::string, std::string>& pro
int32_t minValue, int32_t maxValue)
{
if (property.empty() || propertyMap.find(property) == propertyMap.end()) {
HILOGE("property is valid");
HILOGE("property is valid, property : %{public}s", property.c_str());
return false;
}
std::string propertyValue = propertyMap.at(property);

View File

@ -244,6 +244,10 @@ int32_t ProfileControlUtils::GetDeviceProfile(std::shared_ptr<IKVAdapter> kvStor
return DP_GET_KV_DB_FAIL;
}
ProfileUtils::EntriesToDeviceProfile(values, deviceProfile);
if (!ProfileUtils::IsDeviceProfileValid(deviceProfile)) {
HILOGE("deviceProfile is invalid!");
return DP_GET_KV_DB_FAIL;
}
HILOGD("GetDeviceProfile in db : %{public}s!", deviceProfile.AnnoymizeDump().c_str());
return DP_SUCCESS;
}
@ -273,6 +277,10 @@ int32_t ProfileControlUtils::GetServiceProfile(std::shared_ptr<IKVAdapter> kvSto
return DP_GET_KV_DB_FAIL;
}
ProfileUtils::EntriesToServiceProfile(values, serviceProfile);
if (!ProfileUtils::IsServiceProfileValid(serviceProfile)) {
HILOGE("serviceProfile is invalid!");
return DP_GET_KV_DB_FAIL;
}
HILOGD("GetServiceProfile in db : %{public}s!", serviceProfile.dump().c_str());
return DP_SUCCESS;
}
@ -312,6 +320,10 @@ int32_t ProfileControlUtils::GetCharacteristicProfile(std::shared_ptr<IKVAdapter
}
}
ProfileUtils::EntriesToCharProfile(values, charProfile);
if (!ProfileUtils::IsCharacteristicProfileValid(charProfile)) {
HILOGE("charProfile is invalid!");
return DP_GET_KV_DB_FAIL;
}
HILOGD("GetCharacteristicProfile in db : %{public}s!", charProfile.dump().c_str());
return DP_SUCCESS;
}