• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetCloudId() const139 const string &FileAsset::GetCloudId() const
140 {
141     return GetStrMember(PhotoColumn::PHOTO_CLOUD_ID);
142 }
143 
SetCloudId(const string & cloudId)144 void FileAsset::SetCloudId(const string &cloudId)
145 {
146     member_[PhotoColumn::PHOTO_CLOUD_ID] = cloudId;
147 }
148 
GetDateAdded() const149 int64_t FileAsset::GetDateAdded() const
150 {
151     return GetInt64Member(MEDIA_DATA_DB_DATE_ADDED);
152 }
153 
SetDateAdded(int64_t dateAdded)154 void FileAsset::SetDateAdded(int64_t dateAdded)
155 {
156     member_[MEDIA_DATA_DB_DATE_ADDED] = dateAdded;
157 }
158 
GetDateModified() const159 int64_t FileAsset::GetDateModified() const
160 {
161     return GetInt64Member(MEDIA_DATA_DB_DATE_MODIFIED);
162 }
163 
SetDateModified(int64_t dateModified)164 void FileAsset::SetDateModified(int64_t dateModified)
165 {
166     member_[MEDIA_DATA_DB_DATE_MODIFIED] = dateModified;
167 }
168 
GetTitle() const169 const string &FileAsset::GetTitle() const
170 {
171     return GetStrMember(MEDIA_DATA_DB_TITLE);
172 }
173 
SetTitle(const string & title)174 void FileAsset::SetTitle(const string &title)
175 {
176     member_[MEDIA_DATA_DB_TITLE] = title;
177 }
178 
GetArtist() const179 const string &FileAsset::GetArtist() const
180 {
181     return GetStrMember(MEDIA_DATA_DB_ARTIST);
182 }
183 
SetArtist(const string & artist)184 void FileAsset::SetArtist(const string &artist)
185 {
186     member_[MEDIA_DATA_DB_ARTIST] = artist;
187 }
188 
GetAlbum() const189 const string &FileAsset::GetAlbum() const
190 {
191     return GetStrMember(MEDIA_DATA_DB_ALBUM);
192 }
193 
SetAlbum(const string & album)194 void FileAsset::SetAlbum(const string &album)
195 {
196     member_[MEDIA_DATA_DB_ALBUM] = album;
197 }
198 
GetPosition() const199 int32_t FileAsset::GetPosition() const
200 {
201     return GetInt32Member(MEDIA_DATA_DB_POSITION);
202 }
203 
SetPosition(int32_t position)204 void FileAsset::SetPosition(int32_t position)
205 {
206     member_[MEDIA_DATA_DB_POSITION] = position;
207 }
208 
GetWidth() const209 int32_t FileAsset::GetWidth() const
210 {
211     return GetInt32Member(MEDIA_DATA_DB_WIDTH);
212 }
213 
SetWidth(int32_t width)214 void FileAsset::SetWidth(int32_t width)
215 {
216     member_[MEDIA_DATA_DB_WIDTH] = width;
217 }
218 
GetHeight() const219 int32_t FileAsset::GetHeight() const
220 {
221     return GetInt32Member(MEDIA_DATA_DB_HEIGHT);
222 }
223 
SetHeight(int32_t height)224 void FileAsset::SetHeight(int32_t height)
225 {
226     member_[MEDIA_DATA_DB_HEIGHT] = height;
227 }
228 
GetDuration() const229 int32_t FileAsset::GetDuration() const
230 {
231     return GetInt32Member(MEDIA_DATA_DB_DURATION);
232 }
233 
SetDuration(int32_t duration)234 void FileAsset::SetDuration(int32_t duration)
235 {
236     member_[MEDIA_DATA_DB_DURATION] = duration;
237 }
238 
GetOrientation() const239 int32_t FileAsset::GetOrientation() const
240 {
241     return GetInt32Member(MEDIA_DATA_DB_ORIENTATION);
242 }
243 
SetOrientation(int32_t orientation)244 void FileAsset::SetOrientation(int32_t orientation)
245 {
246     member_[MEDIA_DATA_DB_ORIENTATION] = orientation;
247 }
248 
GetAlbumId() const249 int32_t FileAsset::GetAlbumId() const
250 {
251     return GetInt32Member(MEDIA_DATA_DB_BUCKET_ID);
252 }
253 
SetAlbumId(int32_t albumId)254 void FileAsset::SetAlbumId(int32_t albumId)
255 {
256     member_[MEDIA_DATA_DB_BUCKET_ID] = albumId;
257 }
258 
GetOwnerAlbumId() const259 int32_t FileAsset::GetOwnerAlbumId() const
260 {
261     return GetInt32Member(PhotoColumn::PHOTO_OWNER_ALBUM_ID);
262 }
263 
SetOwnerAlbumId(int32_t ownerAlbumId)264 void FileAsset::SetOwnerAlbumId(int32_t ownerAlbumId)
265 {
266     member_[PhotoColumn::PHOTO_OWNER_ALBUM_ID] = ownerAlbumId;
267 }
268 
GetAlbumName() const269 const string &FileAsset::GetAlbumName() const
270 {
271     return GetStrMember(MEDIA_DATA_DB_BUCKET_NAME);
272 }
273 
SetAlbumName(const string & albumName)274 void FileAsset::SetAlbumName(const string &albumName)
275 {
276     member_[MEDIA_DATA_DB_BUCKET_NAME] = albumName;
277 }
278 
GetParent() const279 int32_t FileAsset::GetParent() const
280 {
281     return GetInt32Member(MEDIA_DATA_DB_PARENT_ID);
282 }
283 
SetParent(int32_t parent)284 void FileAsset::SetParent(int32_t parent)
285 {
286     member_[MEDIA_DATA_DB_PARENT_ID] = parent;
287 }
288 
GetAlbumUri() const289 const string &FileAsset::GetAlbumUri() const
290 {
291     return albumUri_;
292 }
293 
SetAlbumUri(const string & albumUri)294 void FileAsset::SetAlbumUri(const string &albumUri)
295 {
296     albumUri_ = albumUri;
297 }
298 
GetDateTaken() const299 int64_t FileAsset::GetDateTaken() const
300 {
301     return GetInt64Member(MEDIA_DATA_DB_DATE_TAKEN);
302 }
303 
SetDateTaken(int64_t dateTaken)304 void FileAsset::SetDateTaken(int64_t dateTaken)
305 {
306     member_[MEDIA_DATA_DB_DATE_TAKEN] = dateTaken;
307 }
308 
GetTimePending() const309 int64_t FileAsset::GetTimePending() const
310 {
311     return GetInt64Member(MEDIA_DATA_DB_TIME_PENDING);
312 }
313 
SetTimePending(int64_t timePending)314 void FileAsset::SetTimePending(int64_t timePending)
315 {
316     member_[MEDIA_DATA_DB_TIME_PENDING] = timePending;
317 }
318 
IsFavorite() const319 bool FileAsset::IsFavorite() const
320 {
321     return GetInt32Member(MEDIA_DATA_DB_IS_FAV);
322 }
323 
SetFavorite(bool isFavorite)324 void FileAsset::SetFavorite(bool isFavorite)
325 {
326     member_[MEDIA_DATA_DB_IS_FAV] = isFavorite;
327 }
328 
IsRecentShow() const329 bool FileAsset::IsRecentShow() const
330 {
331     return GetInt32Member(PhotoColumn::PHOTO_IS_RECENT_SHOW);
332 }
333 
SetRecentShow(bool isRecentShow)334 void FileAsset::SetRecentShow(bool isRecentShow)
335 {
336     member_[PhotoColumn::PHOTO_IS_RECENT_SHOW] = isRecentShow;
337 }
338 
GetLatitude()339 double FileAsset::GetLatitude()
340 {
341     return GetDoubleMember(MEDIA_DATA_DB_LATITUDE);
342 }
343 
SetLatitude(double latitude)344 void FileAsset::SetLatitude(double latitude)
345 {
346     member_[MEDIA_DATA_DB_LATITUDE] = latitude;
347 }
348 
GetLongitude()349 double FileAsset::GetLongitude()
350 {
351     return GetDoubleMember(MEDIA_DATA_DB_LONGITUDE);
352 }
353 
SetLongitude(double longitude)354 void FileAsset::SetLongitude(double longitude)
355 {
356     member_[MEDIA_DATA_DB_LONGITUDE] = longitude;
357 }
358 
SetPhotoId(const string & photoId)359 void FileAsset::SetPhotoId(const string &photoId)
360 {
361     member_[MEDIA_DATA_DB_PHOTO_ID] = photoId;
362 }
363 
GetPhotoId() const364 string FileAsset::GetPhotoId() const
365 {
366     return GetStrMember(MEDIA_DATA_DB_PHOTO_ID);
367 }
368 
SetPhotoIdAndQuality(const string & photoId,int photoQuality)369 void FileAsset::SetPhotoIdAndQuality(const string &photoId, int photoQuality)
370 {
371     member_[MEDIA_DATA_DB_PHOTO_ID] = photoId;
372     member_[MEDIA_DATA_DB_PHOTO_QUALITY] = photoQuality;
373 }
374 
GetPhotoIdAndQuality() const375 pair<string, int> FileAsset::GetPhotoIdAndQuality() const
376 {
377     return make_pair(GetStrMember(MEDIA_DATA_DB_PHOTO_ID), GetInt32Member(MEDIA_DATA_DB_PHOTO_QUALITY));
378 }
379 
GetDateTrashed() const380 int64_t FileAsset::GetDateTrashed() const
381 {
382     return GetInt64Member(MEDIA_DATA_DB_DATE_TRASHED);
383 }
384 
SetDateTrashed(int64_t dateTrashed)385 void FileAsset::SetDateTrashed(int64_t dateTrashed)
386 {
387     member_[MEDIA_DATA_DB_DATE_TRASHED] = dateTrashed;
388 }
389 
GetSelfId() const390 const string &FileAsset::GetSelfId() const
391 {
392     return GetStrMember(MEDIA_DATA_DB_SELF_ID);
393 }
394 
SetSelfId(const string & selfId)395 void FileAsset::SetSelfId(const string &selfId)
396 {
397     member_[MEDIA_DATA_DB_SELF_ID] = selfId;
398 }
399 
GetIsTrash() const400 int32_t FileAsset::GetIsTrash() const
401 {
402     bool cond = (resultNapiType_ == ResultNapiType::TYPE_USERFILE_MGR ||
403         resultNapiType_ == ResultNapiType::TYPE_PHOTOACCESS_HELPER);
404     CHECK_AND_RETURN_RET(!cond, static_cast<int32_t>(GetInt64Member(MediaColumn::MEDIA_DATE_TRASHED)));
405     return GetInt32Member(MEDIA_DATA_DB_IS_TRASH);
406 }
407 
SetIsTrash(int32_t isTrash)408 void FileAsset::SetIsTrash(int32_t isTrash)
409 {
410     member_[MEDIA_DATA_DB_IS_TRASH] = isTrash;
411 }
412 
GetRecyclePath() const413 const string &FileAsset::GetRecyclePath() const
414 {
415     return GetStrMember(MEDIA_DATA_DB_RECYCLE_PATH);
416 }
417 
SetRecyclePath(const string & recyclePath)418 void FileAsset::SetRecyclePath(const string &recyclePath)
419 {
420     member_[MEDIA_DATA_DB_RECYCLE_PATH] = recyclePath;
421 }
422 
GetOwnerPackage() const423 const string FileAsset::GetOwnerPackage() const
424 {
425     return GetStrMember(MEDIA_DATA_DB_OWNER_PACKAGE);
426 }
427 
SetOwnerPackage(const string & ownerPackage)428 void FileAsset::SetOwnerPackage(const string &ownerPackage)
429 {
430     member_[MEDIA_DATA_DB_OWNER_PACKAGE] = ownerPackage;
431 }
432 
GetOwnerAppId() const433 const string FileAsset::GetOwnerAppId() const
434 {
435     return GetStrMember(MEDIA_DATA_DB_OWNER_APPID);
436 }
437 
SetOwnerAppId(const string & ownerAppId)438 void FileAsset::SetOwnerAppId(const string &ownerAppId)
439 {
440     member_[MEDIA_DATA_DB_OWNER_APPID] = ownerAppId;
441 }
442 
GetResultNapiType() const443 ResultNapiType FileAsset::GetResultNapiType() const
444 {
445     return resultNapiType_;
446 }
447 
GetPackageName() const448 const string FileAsset::GetPackageName() const
449 {
450     return GetStrMember(MediaColumn::MEDIA_PACKAGE_NAME);
451 }
452 
SetPackageName(const string & packageName)453 void FileAsset::SetPackageName(const string &packageName)
454 {
455     member_[MediaColumn::MEDIA_PACKAGE_NAME] = packageName;
456 }
457 
SetResultNapiType(const ResultNapiType type)458 void FileAsset::SetResultNapiType(const ResultNapiType type)
459 {
460     resultNapiType_ = type;
461 }
462 
GetPhotoSubType() const463 int32_t FileAsset::GetPhotoSubType() const
464 {
465     return GetInt32Member(PhotoColumn::PHOTO_SUBTYPE);
466 }
467 
SetPhotoSubType(int32_t photoSubType)468 void FileAsset::SetPhotoSubType(int32_t photoSubType)
469 {
470     member_[PhotoColumn::PHOTO_SUBTYPE] = photoSubType;
471 }
472 
GetOriginalSubType() const473 int32_t FileAsset::GetOriginalSubType() const
474 {
475     return GetInt32Member(PhotoColumn::PHOTO_ORIGINAL_SUBTYPE);
476 }
477 
GetCameraShotKey() const478 const std::string &FileAsset::GetCameraShotKey() const
479 {
480     return GetStrMember(PhotoColumn::CAMERA_SHOT_KEY);
481 }
482 
SetCameraShotKey(const std::string & cameraShotKey)483 void FileAsset::SetCameraShotKey(const std::string &cameraShotKey)
484 {
485     member_[PhotoColumn::CAMERA_SHOT_KEY] = cameraShotKey;
486 }
487 
IsHidden() const488 bool FileAsset::IsHidden() const
489 {
490     return GetInt32Member(MediaColumn::MEDIA_HIDDEN);
491 }
492 
SetHidden(bool isHidden)493 void FileAsset::SetHidden(bool isHidden)
494 {
495     member_[MediaColumn::MEDIA_HIDDEN] = isHidden;
496 }
497 
GetAllExif() const498 const std::string &FileAsset::GetAllExif() const
499 {
500     return GetStrMember(PhotoColumn::PHOTO_ALL_EXIF);
501 }
502 
SetAllExif(const string & allExif)503 void FileAsset::SetAllExif(const string &allExif)
504 {
505     member_[PhotoColumn::PHOTO_ALL_EXIF] = allExif;
506 }
507 
GetFrontCamera() const508 const std::string &FileAsset::GetFrontCamera() const
509 {
510     return GetStrMember(PhotoColumn::PHOTO_FRONT_CAMERA);
511 }
512 
SetFrontCamera(const string & frontCamera)513 void FileAsset::SetFrontCamera(const string &frontCamera)
514 {
515     member_[PhotoColumn::PHOTO_FRONT_CAMERA] = frontCamera;
516 }
517 
GetUserComment() const518 const std::string &FileAsset::GetUserComment() const
519 {
520     return GetStrMember(PhotoColumn::PHOTO_USER_COMMENT);
521 }
522 
SetUserComment(const string & userComment)523 void FileAsset::SetUserComment(const string &userComment)
524 {
525     member_[PhotoColumn::PHOTO_USER_COMMENT] = userComment;
526 }
527 
GetFilePath() const528 const std::string &FileAsset::GetFilePath() const
529 {
530     return GetStrMember(MediaColumn::MEDIA_FILE_PATH);
531 }
532 
SetFilePath(const std::string & filePath)533 void FileAsset::SetFilePath(const std::string &filePath)
534 {
535     member_[MediaColumn::MEDIA_FILE_PATH] = filePath;
536 }
537 
GetPhotoEditTime() const538 int64_t FileAsset::GetPhotoEditTime() const
539 {
540     return GetInt64Member(PhotoColumn::PHOTO_EDIT_TIME);
541 }
542 
SetPhotoEditTime(int64_t photoEditTime)543 void FileAsset::SetPhotoEditTime(int64_t photoEditTime)
544 {
545     member_[PhotoColumn::PHOTO_EDIT_TIME] = photoEditTime;
546 }
547 
GetMovingPhotoEffectMode() const548 int32_t FileAsset::GetMovingPhotoEffectMode() const
549 {
550     return GetInt32Member(PhotoColumn::MOVING_PHOTO_EFFECT_MODE);
551 }
552 
SetMovingPhotoEffectMode(int32_t effectMode)553 void FileAsset::SetMovingPhotoEffectMode(int32_t effectMode)
554 {
555     member_[PhotoColumn::MOVING_PHOTO_EFFECT_MODE] = effectMode;
556 }
557 
GetCoverPosition() const558 int64_t FileAsset::GetCoverPosition() const
559 {
560     return GetInt64Member(PhotoColumn::PHOTO_COVER_POSITION);
561 }
562 
SetCoverPosition(int64_t coverPosition)563 void FileAsset::SetCoverPosition(int64_t coverPosition)
564 {
565     member_[PhotoColumn::PHOTO_COVER_POSITION] = coverPosition;
566 }
567 
GetBurstKey() const568 const std::string &FileAsset::GetBurstKey() const
569 {
570     return GetStrMember(PhotoColumn::PHOTO_BURST_KEY);
571 }
572 
SetBurstKey(const std::string & burstKey)573 void FileAsset::SetBurstKey(const std::string &burstKey)
574 {
575     member_[PhotoColumn::PHOTO_BURST_KEY] = burstKey;
576 }
577 
GetBurstCoverLevel() const578 int32_t FileAsset::GetBurstCoverLevel() const
579 {
580     return GetInt32Member(PhotoColumn::PHOTO_BURST_COVER_LEVEL);
581 }
582 
SetBurstCoverLevel(int32_t burstCoverLevel)583 void FileAsset::SetBurstCoverLevel(int32_t burstCoverLevel)
584 {
585     member_[PhotoColumn::PHOTO_BURST_COVER_LEVEL] = burstCoverLevel;
586 }
587 
GetCEAvailable() const588 int32_t FileAsset::GetCEAvailable() const
589 {
590     return GetInt32Member(PhotoColumn::PHOTO_CE_AVAILABLE);
591 }
592 
SetCEAvailable(int32_t ceAvailable)593 void FileAsset::SetCEAvailable(int32_t ceAvailable)
594 {
595     member_[PhotoColumn::PHOTO_CE_AVAILABLE] = ceAvailable;
596 }
597 
GetDetailTime() const598 const std::string &FileAsset::GetDetailTime() const
599 {
600     return GetStrMember(PhotoColumn::PHOTO_DETAIL_TIME);
601 }
602 
SetDetailTime(const string & detailTime)603 void FileAsset::SetDetailTime(const string &detailTime)
604 {
605     member_[PhotoColumn::PHOTO_DETAIL_TIME] = detailTime;
606 }
607 
GetSupportedWatermarkType() const608 int32_t FileAsset::GetSupportedWatermarkType() const
609 {
610     return GetInt32Member(PhotoColumn::SUPPORTED_WATERMARK_TYPE);
611 }
612 
SetSupportedWatermarkType(int32_t watermarkType)613 void FileAsset::SetSupportedWatermarkType(int32_t watermarkType)
614 {
615     member_[PhotoColumn::SUPPORTED_WATERMARK_TYPE] = watermarkType;
616 }
617 
GetIsAuto() const618 int32_t FileAsset::GetIsAuto() const
619 {
620     return GetInt32Member(PhotoColumn::PHOTO_IS_AUTO);
621 }
622 
SetIsAuto(int32_t isAuto)623 void FileAsset::SetIsAuto(int32_t isAuto)
624 {
625     member_[PhotoColumn::PHOTO_IS_AUTO] = isAuto;
626 }
627 
GetDirty() const628 int32_t FileAsset::GetDirty() const
629 {
630     return GetInt32Member(MEDIA_DATA_DB_DIRTY);
631 }
632 
SetDirty(int32_t dirty)633 void FileAsset::SetDirty(int32_t dirty)
634 {
635     member_[MEDIA_DATA_DB_DIRTY] = dirty;
636 }
637 
GetMediaSuffix() const638 std::string FileAsset::GetMediaSuffix() const
639 {
640     return GetStrMember(PhotoColumn::PHOTO_MEDIA_SUFFIX);
641 }
642 
SetMediaSuffix(const std::string & mediaSuffix)643 void FileAsset::SetMediaSuffix(const std::string &mediaSuffix)
644 {
645     member_[PhotoColumn::PHOTO_MEDIA_SUFFIX] = mediaSuffix;
646 }
647 
SetOpenStatus(int32_t fd,int32_t openStatus)648 void FileAsset::SetOpenStatus(int32_t fd, int32_t openStatus)
649 {
650     lock_guard<mutex> lock(openStatusMapMutex_);
651     if (openStatusMap_ == nullptr) {
652         openStatusMap_ = make_shared<unordered_map<int32_t, int32_t>>();
653     }
654     openStatusMap_->insert({fd, openStatus});
655 }
656 
RemoveOpenStatus(int32_t fd)657 void FileAsset::RemoveOpenStatus(int32_t fd)
658 {
659     lock_guard<mutex> lock(openStatusMapMutex_);
660     CHECK_AND_RETURN(openStatusMap_ != nullptr);
661     openStatusMap_->erase(fd);
662 }
663 
GetOpenStatus(int32_t fd)664 int32_t FileAsset::GetOpenStatus(int32_t fd)
665 {
666     lock_guard<mutex> lock(openStatusMapMutex_);
667     CHECK_AND_RETURN_RET(openStatusMap_ != nullptr, E_INVALID_VALUES);
668 
669     if (openStatusMap_->find(fd) != openStatusMap_->end()) {
670         return openStatusMap_->at(fd);
671     } else {
672         MEDIA_ERR_LOG("can not find this fd: [%{public}d]", fd);
673         return E_INVALID_VALUES;
674     }
675 }
676 
GetMemberMap()677 unordered_map<string, variant<int32_t, int64_t, string, double>> &FileAsset::GetMemberMap()
678 {
679     return member_;
680 }
681 
GetMemberValue(const string & name)682 variant<int32_t, int64_t, string, double> &FileAsset::GetMemberValue(const string &name)
683 {
684     return member_[name];
685 }
686 
GetStrMember(const string & name) const687 const string &FileAsset::GetStrMember(const string &name) const
688 {
689     return (member_.count(name) > 0) ? get<string>(member_.at(name)) : DEFAULT_STR;
690 }
691 
GetInt32Member(const string & name) const692 int32_t FileAsset::GetInt32Member(const string &name) const
693 {
694     return (member_.count(name) > 0) ? get<int32_t>(member_.at(name)) : DEFAULT_INT32;
695 }
696 
GetInt64Member(const string & name) const697 int64_t FileAsset::GetInt64Member(const string &name) const
698 {
699     return (member_.count(name) > 0) ? get<int64_t>(member_.at(name)) : DEFAULT_INT64;
700 }
701 
GetDoubleMember(const string & name) const702 double FileAsset::GetDoubleMember(const string &name) const
703 {
704     return (member_.count(name) > 0) ? get<double>(member_.at(name)) : DEFAULT_DOUBLE;
705 }
706 
GetPhotoIndex() const707 int32_t FileAsset::GetPhotoIndex() const
708 {
709     return GetInt32Member(PHOTO_INDEX);
710 }
711 
GetUserId()712 int32_t FileAsset::GetUserId()
713 {
714     return userId_;
715 }
716 
SetUserId(int32_t userId)717 void FileAsset::SetUserId(int32_t userId)
718 {
719     userId_ = userId;
720 }
721 
SetResultTypeMap(const string & colName,ResultSetDataType type)722 void FileAsset::SetResultTypeMap(const string &colName, ResultSetDataType type)
723 {
724     lock_guard<mutex> lock(resultTypeMapMutex_);
725     if (resultTypeMap_.count(colName) != 0) {
726         return;
727     }
728     resultTypeMap_.insert(make_pair(colName, type));
729 }
730 
GetAssetJson()731 string FileAsset::GetAssetJson()
732 {
733     json jsonObject;
734     for (auto &[colName, _]  : member_) {
735         if (resultTypeMap_.count(colName) == 0) {
736             continue;
737         }
738         switch (resultTypeMap_.at(colName)) {
739             case TYPE_STRING:
740                 jsonObject[colName] = GetStrMember(colName);
741                 break;
742             case TYPE_INT32:
743                 jsonObject[colName] = GetInt32Member(colName);
744                 break;
745             case TYPE_INT64:
746                 jsonObject[colName] = GetInt64Member(colName);
747                 break;
748             default:
749                 break;
750         }
751     }
752     jsonObject[PHOTO_DATA_IMAGE_IMAGE_DESCRIPTION] =
753         AppFileService::SandboxHelper::Decode(jsonObject[PHOTO_DATA_IMAGE_IMAGE_DESCRIPTION]);
754     return jsonObject.dump();
755 }
756 }  // namespace Media
757 }  // namespace OHOS
758