• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "form_provider_data.h"
17 
18 #include <cinttypes>
19 #include <fstream>
20 #include <iostream>
21 #include <sys/types.h>
22 #include <unistd.h>
23 
24 #include "fms_log_wrapper.h"
25 #include "form_constants.h"
26 #include "message_parcel.h"
27 #include "string_ex.h"
28 
29 #include <sys/mman.h>
30 #include "ashmem.h"
31 #include "buffer_handle_parcel.h"
32 #include "ipc_file_descriptor.h"
33 
34 namespace OHOS {
35 namespace AppExecFwk {
36 const std::string JSON_EMPTY_STRING = "{}";
37 const std::string JSON_IMAGES_STRING = "formImages";
38 constexpr int32_t READ_PARCEL_MAX_IMAGE_DATA_NUM_SIZE = 1000;
39 constexpr int32_t MAX_IMAGE_BYTE_SIZE = 50 * 1024 * 1024;
40 constexpr int32_t MAX_BUFFER_SIZE = 32 * 1024 * 1024;
41 constexpr int32_t BIG_DATA = 32 * 1024;
42 constexpr int32_t SHARE_MEM_ALLOC = 2;
43 /**
44  * @brief Constructor.
45  */
FormProviderData()46 FormProviderData::FormProviderData()
47 {
48     jsonFormProviderData_.clear();
49 }
50 
51 /**
52  * @brief A constructor used to create a {@code FormProviderData} instance with data of
53  * the {@code nlohmann::json} type specified.
54  * @param jsonData Indicates the data to be carried in the new {@code FormProviderData} instance,
55  *             in {@code nlohmann::json} format.
56  */
FormProviderData(nlohmann::json & jsonData)57 FormProviderData::FormProviderData(nlohmann::json &jsonData)
58 {
59     if (!jsonData.is_object()) {
60         HILOG_ERROR("jsonData not object");
61         return;
62     }
63     jsonFormProviderData_ = jsonData;
64     ParseImagesData();
65 }
66 
67 /**
68  * @brief A constructor used to create a {@code FormProviderData} instance with data of the {@code String} type
69  * specified.
70  * @param jsonDataString Indicates the data to be carried in the new {@code FormProviderData} instance,
71  * in JSON string format.
72  */
FormProviderData(std::string jsonDataString)73 FormProviderData::FormProviderData(std::string jsonDataString)
74 {
75     SetDataString(jsonDataString);
76     ParseImagesData();
77 }
78 
79 /**
80  * @brief A constructor used to create a {@code FormProviderData} instance with data of the {@code String} type
81  * specified.
82  * @param jsonDataString Indicates the data to be carried in the new {@code FormProviderData} instance, in JSON
83  * string format.
84  * @param isUsedInFRS Indicates is used in frs
85  */
FormProviderData(std::string jsonDataString,bool isUsedInFRS)86 FormProviderData::FormProviderData(std::string jsonDataString, bool isUsedInFRS)
87 {
88     SetDataString(jsonDataString);
89     if (!isUsedInFRS) {
90         ParseImagesData();
91     }
92 }
93 
94 /**
95  * @brief Updates form data in this {@code FormProviderData} object.
96  * @param jsonData Indicates the new data to use, in {@code ZSONObject} format.
97  */
UpdateData(nlohmann::json & jsonData)98 void FormProviderData::UpdateData(nlohmann::json &jsonData)
99 {
100     jsonFormProviderData_ = jsonData;
101 }
102 /**
103  * @brief Obtains the form data stored in this {@code FormProviderData} object.
104  * @return Returns json data
105  */
GetData() const106 nlohmann::json FormProviderData::GetData() const
107 {
108     return jsonFormProviderData_;
109 }
110 /**
111  * @brief Obtains the form data stored in this {@code FormProviderData} object.
112  * @return Returns json string format
113  */
GetDataString() const114 std::string FormProviderData::GetDataString() const
115 {
116     HILOG_DEBUG("get data string");
117     std::string dataStr = jsonFormProviderData_.empty() ? "" : jsonFormProviderData_.dump();
118     HILOG_DEBUG("data: %{private}s", dataStr.c_str());
119     return dataStr;
120 }
121 
122 /**
123  * @brief Adds an image to this {@code FormProviderData} instance.
124  * @param picName Indicates the name of the image to add.
125  * @param data Indicates the binary data of the image content.
126  */
AddImageData(const std::string & picName,const std::shared_ptr<char> & data,int32_t size)127 void FormProviderData::AddImageData(const std::string &picName, const std::shared_ptr<char> &data, int32_t size)
128 {
129     if ((picName.length() == 0) || (!data)) {
130         HILOG_ERROR("null inputParam");
131         return;
132     }
133 
134     rawImageBytesMap_[picName] = std::make_pair(data, size);
135 
136     imageDataState_ = IMAGE_DATA_STATE_ADDED;
137 }
138 
139 /**
140  * @brief Adds an image to this {@code FormProviderData} instance.
141  * @param picName Indicates the name of the image to add.
142  * @param data Indicates the binary data of the image content.
143  */
AddImageData(const std::string & picName,int fd)144 void FormProviderData::AddImageData(const std::string &picName, int fd)
145 {
146     HILOG_BRIEF("fd is %{public}d, picName:%{public}s", fd, picName.c_str());
147     if (fd < 0) {
148         HILOG_ERROR("invalid fd");
149         return;
150     }
151 
152     int32_t size = lseek(fd, 0L, SEEK_END);
153     if (size <= 0) {
154         HILOG_ERROR("Get file size failed, errno is %{public}d", errno);
155         return;
156     }
157     HILOG_BRIEF("File size is %{public}d", size);
158     if (lseek(fd, 0L, SEEK_SET) == -1) {
159         return;
160     }
161     if (size > MAX_IMAGE_BYTE_SIZE) {
162         HILOG_ERROR("File is too large");
163         return;
164     }
165     char* bytes = new (std::nothrow) char[size];
166     if (bytes == nullptr) {
167         HILOG_ERROR("malloc memory failed, errno is %{public}d", errno);
168         return;
169     }
170     if (read(fd, bytes, size) < 0) {
171         delete[] bytes;
172         HILOG_ERROR("errno %{public}d", errno);
173         return;
174     }
175     std::shared_ptr<char> data(bytes, DeleteBytes());
176     AddImageData(picName, data, size);
177 }
178 
ParseImagesData()179 void FormProviderData::ParseImagesData()
180 {
181     if (jsonFormProviderData_ == nullptr) {
182         HILOG_ERROR("null jsonFormProviderData_");
183         return;
184     }
185     if (!jsonFormProviderData_.contains(JSON_IMAGES_STRING)) {
186         return;
187     }
188     nlohmann::json jsonImages = jsonFormProviderData_.at(JSON_IMAGES_STRING);
189     for (auto iter = jsonImages.begin(); iter != jsonImages.end(); iter++) {
190         if (iter->is_number_integer()) {
191             AddImageData(iter.key(), iter.value());
192         } else {
193             HILOG_ERROR("fd not integer");
194         }
195     }
196 }
197 
198 /**
199  * @brief Removes data of an image with the specified {@code picName} from this {@code FormProviderData} instance.
200  * @param picName Indicates the name of the image to remove.
201  */
RemoveImageData(std::string picName)202 void FormProviderData::RemoveImageData(std::string picName)
203 {
204     rawImageBytesMap_.erase(picName);
205 }
206 
207 /**
208  * @brief Set the form data stored from string string.
209  * @param Returns string string.
210  */
SetDataString(std::string & jsonDataString)211 void FormProviderData::SetDataString(std::string &jsonDataString)
212 {
213     if (jsonDataString.empty()) {
214         jsonDataString = JSON_EMPTY_STRING;
215     }
216     nlohmann::json jsonObject = nlohmann::json::parse(jsonDataString, nullptr, false);
217     if (jsonObject.is_discarded()) {
218         HILOG_ERROR("fail parse jsonDataString: %{private}s.", jsonDataString.c_str());
219         return;
220     }
221     if (!jsonObject.is_object()) {
222         HILOG_ERROR("jsonDataString not object");
223         return;
224     }
225     jsonFormProviderData_ = jsonObject;
226 }
227 /**
228  * @brief Merge new data to FormProviderData.
229  * @param addJsonData data to merge to FormProviderData
230  */
MergeData(nlohmann::json & addJsonData)231 void FormProviderData::MergeData(nlohmann::json &addJsonData)
232 {
233     HILOG_DEBUG("merge data");
234     if (addJsonData.empty()) {
235         return;
236     }
237 
238     if (jsonFormProviderData_.empty()) {
239         jsonFormProviderData_ = addJsonData;
240         return;
241     }
242 
243     for (auto && [key, value] : addJsonData.items()) {
244         jsonFormProviderData_[key] = value;
245     }
246 }
247 
248 /**
249  * @brief Obtains the imageDataMap stored in this {@code FormProviderData} object.
250  * @return Returns the map that contains shared image data.
251  */
GetImageDataMap() const252 std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> FormProviderData::GetImageDataMap() const
253 {
254     return imageDataMap_;
255 }
256 
257 /**
258  * @brief Obtains the add/remove state stored in this {@code FormProviderData} object.
259  * @return Returns the add/remove state of shared image data.
260  */
GetImageDataState() const261 int32_t FormProviderData::GetImageDataState() const
262 {
263     return imageDataState_;
264 }
265 
266 /**
267  * @brief Updates imageDataState in this {@code FormProviderData} object.
268  * @param imageDataState Indicates the imageDataState to update.
269  */
SetImageDataState(int32_t imageDataState)270 void FormProviderData::SetImageDataState(int32_t imageDataState)
271 {
272     imageDataState_ = imageDataState;
273 }
274 
275 /**
276  * @brief Updates imageDataMap in this {@code FormProviderData} object.
277  * @param imageDataMap Indicates the imageDataMap to update.
278  */
SetImageDataMap(std::map<std::string,std::pair<sptr<FormAshmem>,int32_t>> imageDataMap)279 void FormProviderData::SetImageDataMap(std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> imageDataMap)
280 {
281     imageDataMap_ = imageDataMap;
282     if (!imageDataMap.empty()) {
283         imageDataState_ = IMAGE_DATA_STATE_ADDED;
284     } else {
285         imageDataState_ = IMAGE_DATA_STATE_NO_OPERATION;
286     }
287 }
288 
289 /**
290  * Read this {@code FormProviderData} object from a Parcel.
291  * @param parcel the parcel
292  * @return Returns {@code true} if the marshalling is successful; returns {@code false} otherwise.
293  */
ReadFromParcel(Parcel & parcel)294 bool FormProviderData::ReadFromParcel(Parcel &parcel)
295 {
296     int32_t formDataLength = parcel.ReadInt32();
297     HILOG_DEBUG("ReadFromParcel data length is %{public}d ", formDataLength);
298     std::string jsonDataString;
299     if (formDataLength > BIG_DATA) {
300         void *rawData = ReadAshmemDataFromParcel(parcel, formDataLength);
301         if (rawData == nullptr) {
302             HILOG_INFO("rawData is nullptr");
303             return false;
304         }
305         jsonDataString = std::string(static_cast<const char*>(rawData), formDataLength);
306         free(rawData);
307         rawData = nullptr;
308     } else {
309         jsonDataString = Str16ToStr8(parcel.ReadString16());
310     }
311     nlohmann::json jsonObject = nlohmann::json::parse(jsonDataString, nullptr, false);
312     if (jsonObject.is_discarded()) {
313         HILOG_ERROR("fail parse jsonDataString: %{private}s.", jsonDataString.c_str());
314         return false;
315     }
316     jsonFormProviderData_ = jsonObject;
317 
318     imageDataState_ = parcel.ReadInt32();
319     HILOG_DEBUG("imageDateState is %{public}d", imageDataState_);
320     switch (imageDataState_) {
321         case IMAGE_DATA_STATE_ADDED: {
322             if (!HandleImageDataStateAdded(parcel)) {
323                 return false;
324             }
325             break;
326         }
327         case IMAGE_DATA_STATE_NO_OPERATION:
328         case IMAGE_DATA_STATE_REMOVED:
329             break;
330         default:
331             HILOG_WARN("unexpected imageDataState_ %{public}d", imageDataState_);
332             break;
333     }
334     return true;
335 }
336 
ReadFileDescriptor(Parcel & parcel)337 int FormProviderData::ReadFileDescriptor(Parcel &parcel)
338 {
339     sptr<IPCFileDescriptor> descriptor = parcel.ReadObject<IPCFileDescriptor>();
340     if (descriptor == nullptr) {
341         HILOG_INFO("ReadFileDescriptor get descriptor failed");
342         return -1;
343     }
344     int fd = descriptor->GetFd();
345     if (fd < 0) {
346         HILOG_INFO("ReadFileDescriptor get fd failed, fd:[%{public}d].", fd);
347         return -1;
348     }
349     return dup(fd);
350 }
351 
ReleaseMemory(int32_t allocType,void * addr,void * context,uint32_t size)352 void FormProviderData::ReleaseMemory(int32_t allocType, void *addr, void *context, uint32_t size)
353 {
354     if (allocType == SHARE_MEM_ALLOC) {
355         if (context != nullptr) {
356             int *fd = static_cast<int *>(context);
357             if (addr != nullptr) {
358                 ::munmap(addr, size);
359             }
360             if (fd != nullptr) {
361                 fdsan_close_with_tag(*fd, Constants::FORM_DOMAIN_ID);
362             }
363             context = nullptr;
364             addr = nullptr;
365         }
366     }
367 }
368 
ReadAshmemDataFromParcel(Parcel & parcel,int32_t bufferSize)369 char *FormProviderData::ReadAshmemDataFromParcel(Parcel &parcel, int32_t bufferSize)
370 {
371     char *base = nullptr;
372     int fd = ReadFileDescriptor(parcel);
373     if (!CheckAshmemSize(fd, bufferSize)) {
374         HILOG_INFO("ReadAshmemDataFromParcel check ashmem size failed, fd:[%{public}d].", fd);
375         close(fd);
376         return nullptr;
377     }
378     if (bufferSize <= 0 || bufferSize > MAX_BUFFER_SIZE) {
379         HILOG_INFO("malloc parameter bufferSize:[%{public}d] error.", bufferSize);
380         close(fd);
381         return nullptr;
382     }
383 
384     void *ptr = ::mmap(nullptr, bufferSize, PROT_READ, MAP_SHARED, fd, 0);
385     if (ptr == MAP_FAILED) {
386         HILOG_INFO("ReadImageData map failed, errno:%{public}d", errno);
387         close(fd);
388         return nullptr;
389     }
390     if (fd == -1) {
391         HILOG_ERROR("ReadFileDescriptor Error");
392         return nullptr;
393     }
394     fdsan_exchange_owner_tag(fd, 0, Constants::FORM_DOMAIN_ID);
395     base = static_cast<char *>(malloc(bufferSize));
396     if (base == nullptr) {
397         ::munmap(ptr, bufferSize);
398         fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
399         HILOG_INFO("alloc output pixel memory size:[%{public}d] error.", bufferSize);
400         return nullptr;
401     }
402     if (memcpy_s(base, bufferSize, ptr, bufferSize) != 0) {
403         ::munmap(ptr, bufferSize);
404         free(base);
405         base = nullptr;
406         fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
407         HILOG_INFO("memcpy pixel data size:[%{public}d] error.", bufferSize);
408         return nullptr;
409     }
410 
411     ReleaseMemory(SHARE_MEM_ALLOC, ptr, &fd, bufferSize);
412     return base;
413 }
414 
HandleImageDataStateAdded(Parcel & parcel)415 bool FormProviderData::HandleImageDataStateAdded(Parcel &parcel)
416 {
417     int32_t imageDataNum = parcel.ReadInt32();
418     if (imageDataNum > READ_PARCEL_MAX_IMAGE_DATA_NUM_SIZE) {
419         return false;
420     }
421     HILOG_INFO("imageDataNum is %{public}d", imageDataNum);
422     for (int32_t i = 0; i < imageDataNum; i++) {
423         sptr<FormAshmem> formAshmem = parcel.ReadParcelable<FormAshmem>();
424         if (formAshmem == nullptr) {
425             HILOG_ERROR("null ashmem");
426             return false;
427         }
428         int32_t len = parcel.ReadInt32();
429         std::pair<sptr<FormAshmem>, int32_t> imageDataRecord = std::make_pair(formAshmem, len);
430         auto picName = Str16ToStr8(parcel.ReadString16());
431         imageDataMap_[picName] = imageDataRecord;
432     }
433     return true;
434 }
435 
WriteFileDescriptor(Parcel & parcel,int fd) const436 bool FormProviderData::WriteFileDescriptor(Parcel &parcel, int fd) const
437 {
438     if (fd < 0) {
439         HILOG_INFO("WriteFileDescriptor get fd failed, fd:[%{public}d].", fd);
440         return false;
441     }
442     int dupFd = dup(fd);
443     if (dupFd < 0) {
444         HILOG_INFO("WriteFileDescriptor dup fd failed, dupFd:[%{public}d].", dupFd);
445         return false;
446     }
447     sptr<IPCFileDescriptor> descriptor = new IPCFileDescriptor(dupFd);
448     bool result = parcel.WriteObject<IPCFileDescriptor>(descriptor);
449     if (!result) {
450         close(dupFd);
451     }
452     return result;
453 }
454 
WriteAshmemDataToParcel(Parcel & parcel,size_t size,const char * dataPtr) const455 bool FormProviderData::WriteAshmemDataToParcel(Parcel &parcel, size_t size, const char* dataPtr) const
456 {
457     const char *data = dataPtr;
458     std::string name = "formAshmemData";
459     int fd = AshmemCreate(name.c_str(), size);
460     HILOG_INFO("AshmemCreate:[%{public}d].", fd);
461     if (fd < 0) {
462         return false;
463     }
464     fdsan_exchange_owner_tag(fd, 0, Constants::FORM_DOMAIN_ID);
465     int result = AshmemSetProt(fd, PROT_READ | PROT_WRITE);
466     HILOG_INFO("AshmemSetProt:[%{public}d].", result);
467     if (result < 0) {
468         fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
469         return false;
470     }
471     void *ptr = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
472     if (ptr == MAP_FAILED) {
473         fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
474         HILOG_INFO("WriteAshmemData map failed, errno:%{public}d", errno);
475         return false;
476     }
477     HILOG_INFO("mmap success");
478 
479     if (memcpy_s(ptr, size, data, size) != EOK) {
480         ::munmap(ptr, size);
481         fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
482         HILOG_INFO("WriteAshmemData memcpy_s error");
483         return false;
484     }
485 
486     if (!FormProviderData::WriteFileDescriptor(parcel, fd)) {
487         ::munmap(ptr, size);
488         fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
489         HILOG_INFO("WriteAshmemData WriteFileDescriptor error");
490         return false;
491     }
492     HILOG_INFO("WriteAshmemData WriteFileDescriptor success");
493     ::munmap(ptr, size);
494     fdsan_close_with_tag(fd, Constants::FORM_DOMAIN_ID);
495     return true;
496 }
497 
WriteFormData(Parcel & parcel) const498 bool FormProviderData::WriteFormData(Parcel &parcel) const
499 {
500     std::string formData = jsonFormProviderData_.empty() ?
501         JSON_EMPTY_STRING : jsonFormProviderData_.dump();
502     int32_t formDataLength = static_cast<int32_t>(formData.length());
503     parcel.WriteInt32(formDataLength);
504     if (formDataLength > BIG_DATA) {
505         const char* dataPtr = formData.c_str();
506         HILOG_INFO("FormProviderData::WriteFormData data length is %{public}d", formDataLength);
507         return WriteAshmemDataToParcel(parcel, formDataLength, dataPtr);
508     } else {
509         return parcel.WriteString16(Str8ToStr16(formData));
510     }
511 }
512 
513 /**
514  * @brief Marshals this {@code FormProviderData} object into a {@link ohos.utils.Parcel} object.
515  * @param parcel Indicates the {@code Parcel} object for marshalling.
516  * @return Returns {@code true} if the marshalling is successful; returns {@code false} otherwise.
517  */
Marshalling(Parcel & parcel) const518 bool FormProviderData::Marshalling(Parcel &parcel) const
519 {
520     HILOG_DEBUG("jsonFormProviderData_ is private");
521     if (!WriteFormData(parcel)) {
522         return false;
523     }
524 
525     parcel.WriteInt32(imageDataState_);
526     HILOG_DEBUG("imageDateState is %{public}d", imageDataState_);
527     switch (imageDataState_) {
528         case IMAGE_DATA_STATE_ADDED: {
529             parcel.WriteInt32(rawImageBytesMap_.size()); // firstly write the number of shared image to add
530             for (auto &entry : rawImageBytesMap_) {
531                 if (!WriteImageDataToParcel(parcel, entry.first, entry.second.first, entry.second.second)) {
532                     HILOG_ERROR("the picture name is %{public}s", entry.first.c_str());
533                     return false;
534                 }
535                 parcel.WriteInt32(sizeof(entry.second));
536                 parcel.WriteString16(Str8ToStr16(entry.first));
537             }
538             break;
539         }
540         case IMAGE_DATA_STATE_NO_OPERATION:
541         case IMAGE_DATA_STATE_REMOVED:
542             break;
543         default:
544             HILOG_WARN("unexpected imageDataState_ %{public}d", imageDataState_);
545             break;
546     }
547     return true;
548 }
549 
550 /**
551  * @brief Unmarshals this {@code FormProviderData} object from a {@link ohos.utils.Parcel} object.
552  * @param parcel Indicates the {@code Parcel} object for unmarshalling.
553  * @return FormProviderData.
554  */
Unmarshalling(Parcel & parcel)555 FormProviderData* FormProviderData::Unmarshalling(Parcel &parcel)
556 {
557     std::unique_ptr<FormProviderData> formProviderData = std::make_unique<FormProviderData>();
558     if (formProviderData && !formProviderData->ReadFromParcel(parcel)) {
559         formProviderData = nullptr;
560     }
561     return formProviderData.release();
562 }
563 
564 /**
565  * @brief Clear imageDataMap, rawImageBytesMap_, imageDataState_ and jsonFormProviderData_.
566  */
ClearData()567 void FormProviderData::ClearData()
568 {
569     jsonFormProviderData_.clear();
570 }
571 
NeedCache() const572 bool FormProviderData::NeedCache() const
573 {
574     return !jsonFormProviderData_.empty() || !imageDataMap_.empty();
575 }
576 
WriteImageDataToParcel(Parcel & parcel,const std::string & picName,const std::shared_ptr<char> & data,int32_t size) const577 bool FormProviderData::WriteImageDataToParcel(Parcel &parcel, const std::string &picName,
578     const std::shared_ptr<char> &data, int32_t size) const
579 {
580     FormAshmem formAshmem;
581     if (!formAshmem.WriteToAshmem(picName, data.get(), size)) {
582         return false;
583     }
584 
585     // write formAshmem
586     if (!parcel.WriteParcelable(&formAshmem)) {
587         HILOG_ERROR("write FormAshmem fail,the picture name is %{public}s", picName.c_str());
588         return false;
589     }
590 
591     HILOG_INFO("write FormAshmem success, picName:%{public}s, size:%{public}d", picName.c_str(), size);
592     return true;
593 }
594 
ConvertRawImageData()595 bool FormProviderData::ConvertRawImageData()
596 {
597     HILOG_INFO("call");
598     for (auto &entry : rawImageBytesMap_) {
599         sptr<FormAshmem> formAshmem = new (std::nothrow) FormAshmem();
600         if (formAshmem == nullptr) {
601             HILOG_ERROR("alloc shmem failed");
602             return false;
603         }
604         if (!formAshmem->WriteToAshmem(entry.first, entry.second.first.get(), entry.second.second)) {
605             HILOG_ERROR("write to shmem failed");
606             return false;
607         }
608         std::pair<sptr<FormAshmem>, int32_t> imageDataRecord = std::make_pair(formAshmem, entry.second.second);
609         imageDataMap_[entry.first] = imageDataRecord;
610     }
611     rawImageBytesMap_.clear();
612     HILOG_INFO("end");
613     return true;
614 }
615 } // namespace AppExecFwk
616 } // namespace OHOS
617