1 /* 2 * Copyright (C) 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 #ifndef OHOS_MEDIALIBRARY_RDB_UTILS_H 17 #define OHOS_MEDIALIBRARY_RDB_UTILS_H 18 19 #include <atomic> 20 #include <functional> 21 #include <memory> 22 #include <string> 23 #include <map> 24 25 #include "medialibrary_rdbstore.h" 26 #include "rdb_predicates.h" 27 #include "rdb_store.h" 28 #include "uri.h" 29 #include "userfile_manager_types.h" 30 #include "datashare_values_bucket.h" 31 namespace OHOS::Media { 32 #define EXPORT __attribute__ ((visibility ("default"))) 33 34 enum NotifyAlbumType : uint16_t { 35 NO_NOTIFY = 0x00, 36 SYS_ALBUM = 0x01, 37 SYS_ALBUM_HIDDEN = 0X02, 38 USER_ALBUM = 0X04, 39 SOURCE_ALBUM = 0X08, 40 ANA_ALBUM = 0X10, 41 }; 42 43 struct AlbumCounts { 44 int count; 45 int hiddenCount; 46 int imageCount; 47 int videoCount; 48 }; 49 50 class MediaLibraryRdbUtils { 51 public: 52 EXPORT static void UpdateSystemAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 53 const std::vector<std::string> &subtypes = {}, bool shouldNotify = false); 54 EXPORT static void UpdateUserAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 55 const std::vector<std::string> &userAlbumIds = {}, bool shouldNotify = false); 56 EXPORT static void UpdateSourceAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 57 const std::vector<std::string> &sourceAlbumIds = {}, bool shouldNotify = false); 58 static void UpdateUserAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 59 const std::vector<std::string> &uris, bool shouldNotify = false); 60 EXPORT static void UpdateAnalysisAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 61 const std::vector<std::string> &uris); 62 static void UpdateSourceAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 63 const std::vector<std::string> &uris, bool shouldNotify = false); 64 65 static void AddQueryFilter(NativeRdb::AbsRdbPredicates &predicates); 66 EXPORT static void UpdateSysAlbumHiddenState(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 67 const std::vector<std::string> &subtypes = {}); 68 EXPORT static void UpdateAnalysisAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 69 const std::vector<std::string> &userAlbumIds = {}, const std::vector<std::string> &fileIds = {}); 70 EXPORT static void UpdateAnalysisAlbumByFile(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 71 const std::vector<std::string> &fileIds, const std::vector<int> &albumTypes); 72 EXPORT static void UpdateAllAlbums(std::shared_ptr<MediaLibraryRdbStore> rdbStore, 73 const std::vector<std::string> &uris = {}, NotifyAlbumType type = NotifyAlbumType::NO_NOTIFY); 74 75 EXPORT static int32_t RefreshAllAlbums(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 76 std::function<void(PhotoAlbumType, PhotoAlbumSubType, int)> refreshProcessHandler, 77 std::function<void()> refreshCallback); 78 EXPORT static int32_t IsNeedRefreshByCheckTable(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 79 bool &signal); 80 81 EXPORT static void UpdateSystemAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 82 const std::vector<std::string> &subtypes = {}); 83 EXPORT static void UpdateUserAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 84 const std::vector<std::string> &userAlbumIds = {}); 85 EXPORT static void UpdateAnalysisAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 86 const std::vector<std::string> &subtypes = {}); 87 EXPORT static void UpdateAllAlbumsForCloud(const std::shared_ptr<MediaLibraryRdbStore> rdbStore); 88 EXPORT static void UpdateAllAlbumsCountForCloud(const std::shared_ptr<MediaLibraryRdbStore> rdbStore); 89 90 EXPORT static bool IsNeedRefreshAlbum(); 91 EXPORT static void SetNeedRefreshAlbum(bool isNeedRefresh); 92 EXPORT static bool IsInRefreshTask(); 93 EXPORT static int32_t GetAlbumIdsForPortrait(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 94 std::vector<std::string> &portraitAlbumIds); 95 EXPORT static int32_t GetAlbumSubtypeArgument(const NativeRdb::RdbPredicates &predicates); 96 EXPORT static void AddVirtualColumnsOfDateType(std::vector<std::string>& columns); 97 EXPORT static void AddQueryIndex(NativeRdb::AbsPredicates& predicates, const std::vector<std::string>& columns); 98 EXPORT static bool HasDataToAnalysis(const std::shared_ptr<MediaLibraryRdbStore> rdbStore); 99 EXPORT static int32_t UpdateTrashedAssetOnAlbum(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 100 NativeRdb::RdbPredicates &predicates); 101 EXPORT static int32_t UpdateOwnerAlbumId(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 102 const std::vector<DataShare::DataShareValuesBucket> &values, std::vector<int32_t> &updateIds); 103 EXPORT static int32_t UpdateRemovedAssetToTrash(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 104 const std::vector<std::string> &whereIdArgs); 105 EXPORT static int32_t UpdateThumbnailRelatedDataToDefault(const std::shared_ptr<MediaLibraryRdbStore> rdbStore, 106 const int64_t fileId); 107 private: 108 static std::atomic<bool> isNeedRefreshAlbum; 109 static std::atomic<bool> isInRefreshTask; 110 static std::mutex sRefreshAlbumMutex_; 111 }; 112 } // namespace OHOS::Media 113 #endif // OHOS_MEDIALIBRARY_RDB_UTILS_H 114