!1414 重复添加同一张卡片能获取图片信息

Merge pull request !1414 from 李伟峰/master
This commit is contained in:
openharmony_ci 2022-04-08 01:58:32 +00:00 committed by Gitee
commit 3253838b43
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 18 additions and 2 deletions

View File

@ -195,7 +195,7 @@ void FormJsInfo::ReadImageData(Parcel &parcel)
auto picName = Str16ToStr8(parcel.ReadString16());
HILOG_INFO("picName: %{public}s, fd: %{public}d, size: %{public}d", picName.c_str(), fd, len);
std::pair<int, int32_t> imageDataPair = std::make_pair(fd, len);
imageDataMap.emplace(picName, imageDataPair);
imageDataMap[picName] = imageDataPair;
}
break;
}

View File

@ -128,6 +128,7 @@ void FormProviderData::AddImageData(std::string picName, int fd)
{
HILOG_INFO("%{public}s called. fd is %{public}d", __func__, fd);
if (fd < 0) {
HILOG_ERROR("fd is invalid.");
return;
}
@ -162,6 +163,8 @@ void FormProviderData::ParseImagesData()
for (auto iter = jsonImages.begin(); iter != jsonImages.end(); iter++) {
if (iter->is_number_integer()) {
AddImageData(iter.key(), iter.value());
} else {
HILOG_ERROR("fd is not number integer.");
}
}
}
@ -279,7 +282,8 @@ bool FormProviderData::ReadFromParcel(Parcel &parcel)
int32_t len = parcel.ReadInt32();
std::pair<sptr<Ashmem>, int32_t> imageDataRecord = std::make_pair(ashmem, len);
imageDataMap_.emplace(Str16ToStr8(parcel.ReadString16()), imageDataRecord);
auto picName = Str16ToStr8(parcel.ReadString16());
imageDataMap_[picName] = imageDataRecord;
}
break;
}

View File

@ -204,6 +204,18 @@ void FormDataMgr::CreateFormInfo(const int64_t formId, const FormRecord &record,
formInfo.versionName = record.versionName;
formInfo.compatibleVersion = record.compatibleVersion;
formInfo.icon = record.icon;
auto sharedImageMap = record.formProviderInfo.GetFormData().GetImageDataMap();
if (sharedImageMap.size() > FormJsInfo::IMAGE_DATA_THRESHOLD) {
return;
}
for (auto entry : sharedImageMap) {
auto picName = entry.first;
auto ashmem = entry.second.first;
auto fd = ashmem->GetAshmemFd();
auto len = ashmem->GetAshmemSize();
std::pair<int, int32_t> imageDataPair = std::make_pair(fd, len);
formInfo.imageDataMap[picName] = imageDataPair;
}
}
/**
* @brief Check temp form count is max.