1 /*
2  * Copyright (C) 2021-2023 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 #define MLOG_TAG "FileAsset"
16 
17 #include "file_asset.h"
18 
19 #include <nlohmann/json.hpp>
20 
21 #include "datashare_business_error.h"
22 #include "datashare_predicates.h"
23 #include "datashare_result_set.h"
24 #include "directory_ex.h"
25 #include "media_column.h"
26 #include "media_exif.h"
27 #include "media_file_utils.h"
28 #include "media_log.h"
29 #include "medialibrary_db_const.h"
30 #include "medialibrary_helper_container.h"
31 #include "medialibrary_errno.h"
32 #include "medialibrary_type_const.h"
33 #include "sandbox_helper.h"
34 #include "uri.h"
35 #include "values_bucket.h"
36 
37 using namespace std;
38 
39 namespace OHOS {
40 namespace Media {
41 static constexpr int MAP_INT_MAX = 50;
42 using json = nlohmann::json;
FileAsset()43 FileAsset::FileAsset()
44     : albumUri_(DEFAULT_MEDIA_ALBUM_URI), resultNapiType_(ResultNapiType::TYPE_NAPI_MAX)
45 {
46     member_.reserve(MAP_INT_MAX);
47 }
48 
GetId() const49 int32_t FileAsset::GetId() const
50 {
51     return GetInt32Member(MEDIA_DATA_DB_ID);
52 }
53 
SetId(int32_t id)54 void FileAsset::SetId(int32_t id)
55 {
56     member_[MEDIA_DATA_DB_ID] = id;
57 }
58 
GetCount() const59 int32_t FileAsset::GetCount() const
60 {
61     return GetInt32Member(MEDIA_DATA_DB_COUNT);
62 }
63 
SetCount(int32_t count)64 void FileAsset::SetCount(int32_t count)
65 {
66     member_[MEDIA_DATA_DB_COUNT] = count;
67 }
68 
GetUri() const69 const string &FileAsset::GetUri() const
70 {
71     return GetStrMember(MEDIA_DATA_DB_URI);
72 }
73 
SetUri(const string & uri)74 void FileAsset::SetUri(const string &uri)
75 {
76     member_[MEDIA_DATA_DB_URI] = uri;
77 }
78 
GetPath() const79 const string &FileAsset::GetPath() const
80 {
81     return GetStrMember(MEDIA_DATA_DB_FILE_PATH);
82 }
83 
SetPath(const string & path)84 void FileAsset::SetPath(const string &path)
85 {
86     member_[MEDIA_DATA_DB_FILE_PATH] = path;
87 }
88 
GetRelativePath() const89 const string &FileAsset::GetRelativePath() const
90 {
91     return GetStrMember(MEDIA_DATA_DB_RELATIVE_PATH);
92 }
93 
SetRelativePath(const string & relativePath)94 void FileAsset::SetRelativePath(const string &relativePath)
95 {
96     member_[MEDIA_DATA_DB_RELATIVE_PATH] = relativePath;
97 }
98 
GetMimeType() const99 const string &FileAsset::GetMimeType() const
100 {
101     return GetStrMember(MEDIA_DATA_DB_MIME_TYPE);
102 }
103 
SetMimeType(const string & mimeType)104 void FileAsset::SetMimeType(const string &mimeType)
105 {
106     member_[MEDIA_DATA_DB_MIME_TYPE] = mimeType;
107 }
108 
GetMediaType() const109 MediaType FileAsset::GetMediaType() const
110 {
111     return static_cast<Media::MediaType>(GetInt32Member(MEDIA_DATA_DB_MEDIA_TYPE));
112 }
113 
SetMediaType(MediaType mediaType)114 void FileAsset::SetMediaType(MediaType mediaType)
115 {
116     member_[MEDIA_DATA_DB_MEDIA_TYPE] = mediaType;
117 }
118 
GetDisplayName() const119 const string &FileAsset::GetDisplayName() const
120 {
121     return GetStrMember(MEDIA_DATA_DB_NAME);
122 }
123 
SetDisplayName(const string & displayName)124 void FileAsset::SetDisplayName(const string &displayName)
125 {
126     member_[MEDIA_DATA_DB_NAME] = displayName;
127 }
128 
GetSize() const129 int64_t FileAsset::GetSize() const
130 {
131     return GetInt64Member(MEDIA_DATA_DB_SIZE);
132 }
133 
SetSize(int64_t size)134 void FileAsset::SetSize(int64_t size)
135 {
136     member_[MEDIA_DATA_DB_SIZE] = size;
137 }
138 
GetDateAdded() const139 int64_t FileAsset::GetDateAdded() const
140 {
141     return GetInt64Member(MEDIA_DATA_DB_DATE_ADDED);
142 }
143 
SetDateAdded(int64_t dateAdded)144 void FileAsset::SetDateAdded(int64_t dateAdded)
145 {
146     member_[MEDIA_DATA_DB_DATE_ADDED] = dateAdded;
147 }
148 
GetDateModified() const149 int64_t FileAsset::GetDateModified() const
150 {
151     return GetInt64Member(MEDIA_DATA_DB_DATE_MODIFIED);
152 }
153 
SetDateModified(int64_t dateModified)154 void FileAsset::SetDateModified(int64_t dateModified)
155 {
156     member_[MEDIA_DATA_DB_DATE_MODIFIED] = dateModified;
157 }
158 
GetTitle() const159 const string &FileAsset::GetTitle() const
160 {
161     return GetStrMember(MEDIA_DATA_DB_TITLE);
162 }
163 
SetTitle(const string & title)164 void FileAsset::SetTitle(const string &title)
165 {
166     member_[MEDIA_DATA_DB_TITLE] = title;
167 }
168 
GetArtist() const169 const string &FileAsset::GetArtist() const
170 {
171     return GetStrMember(MEDIA_DATA_DB_ARTIST);
172 }
173 
SetArtist(const string & artist)174 void FileAsset::SetArtist(const string &artist)
175 {
176     member_[MEDIA_DATA_DB_ARTIST] = artist;
177 }
178 
GetAlbum() const179 const string &FileAsset::GetAlbum() const
180 {
181     return GetStrMember(MEDIA_DATA_DB_ALBUM);
182 }
183 
SetAlbum(const string & album)184 void FileAsset::SetAlbum(const string &album)
185 {
186     member_[MEDIA_DATA_DB_ALBUM] = album;
187 }
188 
GetPosition() const189 int32_t FileAsset::GetPosition() const
190 {
191     return GetInt32Member(MEDIA_DATA_DB_POSITION);
192 }
193 
SetPosition(int32_t position)194 void FileAsset::SetPosition(int32_t position)
195 {
196     member_[MEDIA_DATA_DB_POSITION] = position;
197 }
198 
GetWidth() const199 int32_t FileAsset::GetWidth() const
200 {
201     return GetInt32Member(MEDIA_DATA_DB_WIDTH);
202 }
203 
SetWidth(int32_t width)204 void FileAsset::SetWidth(int32_t width)
205 {
206     member_[MEDIA_DATA_DB_WIDTH] = width;
207 }
208 
GetHeight() const209 int32_t FileAsset::GetHeight() const
210 {
211     return GetInt32Member(MEDIA_DATA_DB_HEIGHT);
212 }
213 
SetHeight(int32_t height)214 void FileAsset::SetHeight(int32_t height)
215 {
216     member_[MEDIA_DATA_DB_HEIGHT] = height;
217 }
218 
GetDuration() const219 int32_t FileAsset::GetDuration() const
220 {
221     return GetInt32Member(MEDIA_DATA_DB_DURATION);
222 }
223 
SetDuration(int32_t duration)224 void FileAsset::SetDuration(int32_t duration)
225 {
226     member_[MEDIA_DATA_DB_DURATION] = duration;
227 }
228 
GetOrientation() const229 int32_t FileAsset::GetOrientation() const
230 {
231     return GetInt32Member(MEDIA_DATA_DB_ORIENTATION);
232 }
233 
SetOrientation(int32_t orientation)234 void FileAsset::SetOrientation(int32_t orientation)
235 {
236     member_[MEDIA_DATA_DB_ORIENTATION] = orientation;
237 }
238 
GetAlbumId() const239 int32_t FileAsset::GetAlbumId() const
240 {
241     return GetInt32Member(MEDIA_DATA_DB_BUCKET_ID);
242 }
243 
SetAlbumId(int32_t albumId)244 void FileAsset::SetAlbumId(int32_t albumId)
245 {
246     member_[MEDIA_DATA_DB_BUCKET_ID] = albumId;
247 }
248 
GetAlbumName() const249 const string &FileAsset::GetAlbumName() const
250 {
251     return GetStrMember(MEDIA_DATA_DB_BUCKET_NAME);
252 }
253 
SetAlbumName(const string & albumName)254 void FileAsset::SetAlbumName(const string &albumName)
255 {
256     member_[MEDIA_DATA_DB_BUCKET_NAME] = albumName;
257 }
258 
GetParent() const259 int32_t FileAsset::GetParent() const
260 {
261     return GetInt32Member(MEDIA_DATA_DB_PARENT_ID);
262 }
263 
SetParent(int32_t parent)264 void FileAsset::SetParent(int32_t parent)
265 {
266     member_[MEDIA_DATA_DB_PARENT_ID] = parent;
267 }
268 
GetAlbumUri() const269 const string &FileAsset::GetAlbumUri() const
270 {
271     return albumUri_;
272 }
273 
SetAlbumUri(const string & albumUri)274 void FileAsset::SetAlbumUri(const string &albumUri)
275 {
276     albumUri_ = albumUri;
277 }
278 
GetDateTaken() const279 int64_t FileAsset::GetDateTaken() const
280 {
281     return GetInt64Member(MEDIA_DATA_DB_DATE_TAKEN);
282 }
283 
SetDateTaken(int64_t dateTaken)284 void FileAsset::SetDateTaken(int64_t dateTaken)
285 {
286     member_[MEDIA_DATA_DB_DATE_TAKEN] = dateTaken;
287 }
288 
GetTimePending() const289 int64_t FileAsset::GetTimePending() const
290 {
291     return GetInt64Member(MEDIA_DATA_DB_TIME_PENDING);
292 }
293 
SetTimePending(int64_t timePending)294 void FileAsset::SetTimePending(int64_t timePending)
295 {
296     member_[MEDIA_DATA_DB_TIME_PENDING] = timePending;
297 }
298 
IsFavorite() const299 bool FileAsset::IsFavorite() const
300 {
301     return GetInt32Member(MEDIA_DATA_DB_IS_FAV);
302 }
303 
SetFavorite(bool isFavorite)304 void FileAsset::SetFavorite(bool isFavorite)
305 {
306     member_[MEDIA_DATA_DB_IS_FAV] = isFavorite;
307 }
308 
GetLatitude()309 double FileAsset::GetLatitude()
310 {
311     return GetDoubleMember(MEDIA_DATA_DB_LATITUDE);
312 }
313 
SetLatitude(double latitude)314 void FileAsset::SetLatitude(double latitude)
315 {
316     member_[MEDIA_DATA_DB_LATITUDE] = latitude;
317 }
318 
GetLongitude()319 double FileAsset::GetLongitude()
320 {
321     return GetDoubleMember(MEDIA_DATA_DB_LONGITUDE);
322 }
323 
SetLongitude(double longitude)324 void FileAsset::SetLongitude(double longitude)
325 {
326     member_[MEDIA_DATA_DB_LONGITUDE] = longitude;
327 }
328 
SetPhotoId(const string & photoId)329 void FileAsset::SetPhotoId(const string &photoId)
330 {
331     member_[MEDIA_DATA_DB_PHOTO_ID] = photoId;
332 }
333 
GetPhotoId() const334 string FileAsset::GetPhotoId() const
335 {
336     return GetStrMember(MEDIA_DATA_DB_PHOTO_ID);
337 }
338 
SetPhotoIdAndQuality(const string & photoId,int photoQuality)339 void FileAsset::SetPhotoIdAndQuality(const string &photoId, int photoQuality)
340 {
341     member_[MEDIA_DATA_DB_PHOTO_ID] = photoId;
342     member_[MEDIA_DATA_DB_PHOTO_QUALITY] = photoQuality;
343 }
344 
GetPhotoIdAndQuality() const345 pair<string, int> FileAsset::GetPhotoIdAndQuality() const
346 {
347     return make_pair(GetStrMember(MEDIA_DATA_DB_PHOTO_ID), GetInt32Member(MEDIA_DATA_DB_PHOTO_QUALITY));
348 }
349 
GetDateTrashed() const350 int64_t FileAsset::GetDateTrashed() const
351 {
352     return GetInt64Member(MEDIA_DATA_DB_DATE_TRASHED);
353 }
354 
SetDateTrashed(int64_t dateTrashed)355 void FileAsset::SetDateTrashed(int64_t dateTrashed)
356 {
357     member_[MEDIA_DATA_DB_DATE_TRASHED] = dateTrashed;
358 }
359 
GetSelfId() const360 const string &FileAsset::GetSelfId() const
361 {
362     return GetStrMember(MEDIA_DATA_DB_SELF_ID);
363 }
364 
SetSelfId(const string & selfId)365 void FileAsset::SetSelfId(const string &selfId)
366 {
367     member_[MEDIA_DATA_DB_SELF_ID] = selfId;
368 }
369 
GetIsTrash() const370 int32_t FileAsset::GetIsTrash() const
371 {
372     if (resultNapiType_ == ResultNapiType::TYPE_USERFILE_MGR ||
373         resultNapiType_ == ResultNapiType::TYPE_PHOTOACCESS_HELPER) {
374         return static_cast<int32_t>(GetInt64Member(MediaColumn::MEDIA_DATE_TRASHED));
375     }
376 
377     return GetInt32Member(MEDIA_DATA_DB_IS_TRASH);
378 }
379 
SetIsTrash(int32_t isTrash)380 void FileAsset::SetIsTrash(int32_t isTrash)
381 {
382     member_[MEDIA_DATA_DB_IS_TRASH] = isTrash;
383 }
384 
GetRecyclePath() const385 const string &FileAsset::GetRecyclePath() const
386 {
387     return GetStrMember(MEDIA_DATA_DB_RECYCLE_PATH);
388 }
389 
SetRecyclePath(const string & recyclePath)390 void FileAsset::SetRecyclePath(const string &recyclePath)
391 {
392     member_[MEDIA_DATA_DB_RECYCLE_PATH] = recyclePath;
393 }
394 
GetOwnerPackage() const395 const string FileAsset::GetOwnerPackage() const
396 {
397     return GetStrMember(MEDIA_DATA_DB_OWNER_PACKAGE);
398 }
399 
SetOwnerPackage(const string & ownerPackage)400 void FileAsset::SetOwnerPackage(const string &ownerPackage)
401 {
402     member_[MEDIA_DATA_DB_OWNER_PACKAGE] = ownerPackage;
403 }
404 
GetOwnerAppId() const405 const string FileAsset::GetOwnerAppId() const
406 {
407     return GetStrMember(MEDIA_DATA_DB_OWNER_APPID);
408 }
409 
SetOwnerAppId(const string & ownerAppId)410 void FileAsset::SetOwnerAppId(const string &ownerAppId)
411 {
412     member_[MEDIA_DATA_DB_OWNER_APPID] = ownerAppId;
413 }
414 
GetResultNapiType() const415 ResultNapiType FileAsset::GetResultNapiType() const
416 {
417     return resultNapiType_;
418 }
419 
GetPackageName() const420 const string FileAsset::GetPackageName() const
421 {
422     return GetStrMember(MediaColumn::MEDIA_PACKAGE_NAME);
423 }
424 
SetPackageName(const string & packageName)425 void FileAsset::SetPackageName(const string &packageName)
426 {
427     member_[MediaColumn::MEDIA_PACKAGE_NAME] = packageName;
428 }
429 
SetResultNapiType(const ResultNapiType type)430 void FileAsset::SetResultNapiType(const ResultNapiType type)
431 {
432     resultNapiType_ = type;
433 }
434 
GetPhotoSubType() const435 int32_t FileAsset::GetPhotoSubType() const
436 {
437     return GetInt32Member(PhotoColumn::PHOTO_SUBTYPE);
438 }
439 
SetPhotoSubType(int32_t photoSubType)440 void FileAsset::SetPhotoSubType(int32_t photoSubType)
441 {
442     member_[PhotoColumn::PHOTO_SUBTYPE] = photoSubType;
443 }
444 
GetOriginalSubType() const445 int32_t FileAsset::GetOriginalSubType() const
446 {
447     return GetInt32Member(PhotoColumn::PHOTO_ORIGINAL_SUBTYPE);
448 }
449 
GetCameraShotKey() const450 const std::string &FileAsset::GetCameraShotKey() const
451 {
452     return GetStrMember(PhotoColumn::CAMERA_SHOT_KEY);
453 }
454 
SetCameraShotKey(const std::string & cameraShotKey)455 void FileAsset::SetCameraShotKey(const std::string &cameraShotKey)
456 {
457     member_[PhotoColumn::CAMERA_SHOT_KEY] = cameraShotKey;
458 }
459 
IsHidden() const460 bool FileAsset::IsHidden() const
461 {
462     return GetInt32Member(MediaColumn::MEDIA_HIDDEN);
463 }
464 
SetHidden(bool isHidden)465 void FileAsset::SetHidden(bool isHidden)
466 {
467     member_[MediaColumn::MEDIA_HIDDEN] = isHidden;
468 }
469 
GetAllExif() const470 const std::string &FileAsset::GetAllExif() const
471 {
472     return GetStrMember(PhotoColumn::PHOTO_ALL_EXIF);
473 }
474 
SetAllExif(const string & allExif)475 void FileAsset::SetAllExif(const string &allExif)
476 {
477     member_[PhotoColumn::PHOTO_ALL_EXIF] = allExif;
478 }
479 
GetFrontCamera() const480 const std::string &FileAsset::GetFrontCamera() const
481 {
482     return GetStrMember(PhotoColumn::PHOTO_FRONT_CAMERA);
483 }
484 
SetFrontCamera(const string & frontCamera)485 void FileAsset::SetFrontCamera(const string &frontCamera)
486 {
487     member_[PhotoColumn::PHOTO_FRONT_CAMERA] = frontCamera;
488 }
489 
GetUserComment() const490 const std::string &FileAsset::GetUserComment() const
491 {
492     return GetStrMember(PhotoColumn::PHOTO_USER_COMMENT);
493 }
494 
SetUserComment(const string & userComment)495 void FileAsset::SetUserComment(const string &userComment)
496 {
497     member_[PhotoColumn::PHOTO_USER_COMMENT] = userComment;
498 }
499 
GetFilePath() const500 const std::string &FileAsset::GetFilePath() const
501 {
502     return GetStrMember(MediaColumn::MEDIA_FILE_PATH);
503 }
504 
SetFilePath(const std::string & filePath)505 void FileAsset::SetFilePath(const std::string &filePath)
506 {
507     member_[MediaColumn::MEDIA_FILE_PATH] = filePath;
508 }
509 
GetPhotoEditTime() const510 int64_t FileAsset::GetPhotoEditTime() const
511 {
512     return GetInt64Member(PhotoColumn::PHOTO_EDIT_TIME);
513 }
514 
SetPhotoEditTime(int64_t photoEditTime)515 void FileAsset::SetPhotoEditTime(int64_t photoEditTime)
516 {
517     member_[PhotoColumn::PHOTO_EDIT_TIME] = photoEditTime;
518 }
519 
GetMovingPhotoEffectMode() const520 int32_t FileAsset::GetMovingPhotoEffectMode() const
521 {
522     return GetInt32Member(PhotoColumn::MOVING_PHOTO_EFFECT_MODE);
523 }
524 
SetMovingPhotoEffectMode(int32_t effectMode)525 void FileAsset::SetMovingPhotoEffectMode(int32_t effectMode)
526 {
527     member_[PhotoColumn::MOVING_PHOTO_EFFECT_MODE] = effectMode;
528 }
529 
GetCoverPosition() const530 int64_t FileAsset::GetCoverPosition() const
531 {
532     return GetInt64Member(PhotoColumn::PHOTO_COVER_POSITION);
533 }
534 
SetCoverPosition(int64_t coverPosition)535 void FileAsset::SetCoverPosition(int64_t coverPosition)
536 {
537     member_[PhotoColumn::PHOTO_COVER_POSITION] = coverPosition;
538 }
539 
GetBurstKey() const540 const std::string &FileAsset::GetBurstKey() const
541 {
542     return GetStrMember(PhotoColumn::PHOTO_BURST_KEY);
543 }
544 
SetBurstKey(const std::string & burstKey)545 void FileAsset::SetBurstKey(const std::string &burstKey)
546 {
547     member_[PhotoColumn::PHOTO_BURST_KEY] = burstKey;
548 }
549 
GetBurstCoverLevel() const550 int32_t FileAsset::GetBurstCoverLevel() const
551 {
552     return GetInt32Member(PhotoColumn::PHOTO_BURST_COVER_LEVEL);
553 }
554 
SetBurstCoverLevel(int32_t burstCoverLevel)555 void FileAsset::SetBurstCoverLevel(int32_t burstCoverLevel)
556 {
557     member_[PhotoColumn::PHOTO_BURST_COVER_LEVEL] = burstCoverLevel;
558 }
559 
GetCEAvailable() const560 int32_t FileAsset::GetCEAvailable() const
561 {
562     return GetInt32Member(PhotoColumn::PHOTO_CE_AVAILABLE);
563 }
564 
SetCEAvailable(int32_t ceAvailable)565 void FileAsset::SetCEAvailable(int32_t ceAvailable)
566 {
567     member_[PhotoColumn::PHOTO_CE_AVAILABLE] = ceAvailable;
568 }
569 
GetDetailTime() const570 const std::string &FileAsset::GetDetailTime() const
571 {
572     return GetStrMember(PhotoColumn::PHOTO_DETAIL_TIME);
573 }
574 
SetDetailTime(const string & detailTime)575 void FileAsset::SetDetailTime(const string &detailTime)
576 {
577     member_[PhotoColumn::PHOTO_DETAIL_TIME] = detailTime;
578 }
579 
GetSupportedWatermarkType() const580 int32_t FileAsset::GetSupportedWatermarkType() const
581 {
582     return GetInt32Member(PhotoColumn::SUPPORTED_WATERMARK_TYPE);
583 }
584 
SetSupportedWatermarkType(int32_t watermarkType)585 void FileAsset::SetSupportedWatermarkType(int32_t watermarkType)
586 {
587     member_[PhotoColumn::SUPPORTED_WATERMARK_TYPE] = watermarkType;
588 }
589 
SetOpenStatus(int32_t fd,int32_t openStatus)590 void FileAsset::SetOpenStatus(int32_t fd, int32_t openStatus)
591 {
592     lock_guard<mutex> lock(openStatusMapMutex_);
593     if (openStatusMap_ == nullptr) {
594         openStatusMap_ = make_shared<unordered_map<int32_t, int32_t>>();
595     }
596     openStatusMap_->insert({fd, openStatus});
597 }
598 
RemoveOpenStatus(int32_t fd)599 void FileAsset::RemoveOpenStatus(int32_t fd)
600 {
601     lock_guard<mutex> lock(openStatusMapMutex_);
602     if (openStatusMap_ == nullptr) {
603         return;
604     }
605     openStatusMap_->erase(fd);
606 }
607 
GetOpenStatus(int32_t fd)608 int32_t FileAsset::GetOpenStatus(int32_t fd)
609 {
610     lock_guard<mutex> lock(openStatusMapMutex_);
611     if (openStatusMap_ == nullptr) {
612         return E_INVALID_VALUES;
613     }
614     if (openStatusMap_->find(fd) != openStatusMap_->end()) {
615         return openStatusMap_->at(fd);
616     } else {
617         MEDIA_ERR_LOG("can not find this fd: [%{public}d]", fd);
618         return E_INVALID_VALUES;
619     }
620 }
621 
GetMemberMap()622 unordered_map<string, variant<int32_t, int64_t, string, double>> &FileAsset::GetMemberMap()
623 {
624     return member_;
625 }
626 
GetMemberValue(const string & name)627 variant<int32_t, int64_t, string, double> &FileAsset::GetMemberValue(const string &name)
628 {
629     return member_[name];
630 }
631 
GetStrMember(const string & name) const632 const string &FileAsset::GetStrMember(const string &name) const
633 {
634     return (member_.count(name) > 0) ? get<string>(member_.at(name)) : DEFAULT_STR;
635 }
636 
GetInt32Member(const string & name) const637 int32_t FileAsset::GetInt32Member(const string &name) const
638 {
639     return (member_.count(name) > 0) ? get<int32_t>(member_.at(name)) : DEFAULT_INT32;
640 }
641 
GetInt64Member(const string & name) const642 int64_t FileAsset::GetInt64Member(const string &name) const
643 {
644     return (member_.count(name) > 0) ? get<int64_t>(member_.at(name)) : DEFAULT_INT64;
645 }
646 
GetDoubleMember(const string & name) const647 double FileAsset::GetDoubleMember(const string &name) const
648 {
649     return (member_.count(name) > 0) ? get<double>(member_.at(name)) : DEFAULT_DOUBLE;
650 }
651 
GetPhotoIndex() const652 int32_t FileAsset::GetPhotoIndex() const
653 {
654     return GetInt32Member(PHOTO_INDEX);
655 }
656 
SetResultTypeMap(const string & colName,ResultSetDataType type)657 void FileAsset::SetResultTypeMap(const string &colName, ResultSetDataType type)
658 {
659     if (resultTypeMap_.count(colName) != 0) {
660         return;
661     }
662     resultTypeMap_.insert(make_pair(colName, type));
663 }
GetAssetJson()664 string FileAsset::GetAssetJson()
665 {
666     json jsonObject;
667     for (auto &[colName, _]  : member_) {
668         if (resultTypeMap_.count(colName) == 0) {
669             continue;
670         }
671         switch (resultTypeMap_.at(colName)) {
672             case TYPE_STRING:
673                 jsonObject[colName] = GetStrMember(colName);
674                 break;
675             case TYPE_INT32:
676                 jsonObject[colName] = GetInt32Member(colName);
677                 break;
678             case TYPE_INT64:
679                 jsonObject[colName] = GetInt64Member(colName);
680                 break;
681             default:
682                 break;
683         }
684     }
685     jsonObject[PHOTO_DATA_IMAGE_IMAGE_DESCRIPTION] =
686         AppFileService::SandboxHelper::Decode(jsonObject[PHOTO_DATA_IMAGE_IMAGE_DESCRIPTION]);
687     return jsonObject.dump();
688 }
689 }  // namespace Media
690 }  // namespace OHOS
691