• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "userfile_manager_types.h"
29 #include "datashare_values_bucket.h"
30 namespace OHOS::Media {
31 #define EXPORT __attribute__ ((visibility ("default")))
32 
33 enum NotifyAlbumType : uint16_t {
34     NO_NOTIFY = 0x00,
35     SYS_ALBUM = 0x01,
36     SYS_ALBUM_HIDDEN = 0X02,
37     USER_ALBUM = 0X04,
38     SOURCE_ALBUM = 0X08,
39     ANA_ALBUM = 0X10,
40 };
41 
42 enum AlbumOperationType : int32_t {
43     DEFAULT = 0,
44     DELETE_PHOTO,
45     RECOVER_PHOTO,
46     HIDE_PHOTO,
47     UNHIDE_PHOTO,
48 };
49 
50 struct AlbumCounts {
51     int count;
52     int hiddenCount;
53     int imageCount;
54     int videoCount;
55 };
56 
57 class MediaLibraryRdbUtils {
58 public:
59     EXPORT static void UpdateSystemAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
60         const std::vector<std::string> &subtypes = {}, bool shouldNotify = false);
61     EXPORT static void UpdateUserAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
62         const std::vector<std::string> &userAlbumIds = {}, bool shouldNotify = false);
63     EXPORT static void UpdateSourceAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
64         const std::vector<std::string> &sourceAlbumIds = {}, bool shouldNotify = false);
65     EXPORT static void UpdateCommonAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
66         const std::vector<std::string> &albumIds = {}, bool shouldNotify = false);
67     static void UpdateUserAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
68         const std::vector<std::string> &uris, bool shouldNotify = false);
69     EXPORT static void UpdateAnalysisAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
70         const std::vector<std::string> &uris);
71     static void UpdateSourceAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
72         const std::vector<std::string> &uris, bool shouldNotify = false);
73     static void UpdateCommonAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
74         const std::vector<std::string> &uris, bool shouldNotify = false);
75 
76     static void AddQueryFilter(NativeRdb::AbsRdbPredicates &predicates);
77     EXPORT static void UpdateSysAlbumHiddenState(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
78         const std::vector<std::string> &subtypes = {});
79     EXPORT static void UpdateAnalysisAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
80         const std::vector<std::string> &userAlbumIds = {}, const std::vector<std::string> &fileIds = {});
81     EXPORT static void UpdateAnalysisAlbumByFile(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
82         const std::vector<std::string> &fileIds, const std::vector<int> &albumTypes);
83     EXPORT static void UpdateAllAlbums(std::shared_ptr<MediaLibraryRdbStore> rdbStore,
84         const std::vector<std::string> &uris = {}, NotifyAlbumType type = NotifyAlbumType::NO_NOTIFY,
85         bool isBackUpAndRestore = false, AlbumOperationType albumOperationType = AlbumOperationType::DEFAULT);
86 
87     EXPORT static int32_t RefreshAllAlbums(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
88         std::function<void(PhotoAlbumType, PhotoAlbumSubType, int)> refreshProcessHandler,
89         std::function<void()> refreshCallback);
90     EXPORT static int32_t IsNeedRefreshByCheckTable(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
91         bool &signal);
92 
93     EXPORT static void UpdateSystemAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
94         const std::vector<std::string> &subtypes = {});
95     EXPORT static void UpdateSystemAlbumsByUris(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
96         AlbumOperationType albumOperationType, const std::vector<std::string> &uris = {},
97         NotifyAlbumType type = NotifyAlbumType::NO_NOTIFY);
98     EXPORT static void UpdateUserAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
99         const std::vector<std::string> &userAlbumIds = {});
100     EXPORT static void UpdateAnalysisAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
101         const std::vector<std::string> &subtypes = {});
102     EXPORT static void UpdateAllAlbumsForCloud(const std::shared_ptr<MediaLibraryRdbStore> rdbStore);
103     EXPORT static void UpdateAllAlbumsCountForCloud(const std::shared_ptr<MediaLibraryRdbStore> rdbStore);
104 
105     EXPORT static bool IsNeedRefreshAlbum();
106     EXPORT static void SetNeedRefreshAlbum(bool isNeedRefresh);
107     EXPORT static bool IsInRefreshTask();
108     EXPORT static int32_t GetAlbumIdsForPortrait(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
109         std::vector<std::string> &portraitAlbumIds);
110     EXPORT static int32_t GetAlbumSubtypeArgument(const NativeRdb::RdbPredicates &predicates);
111     EXPORT static void AddVirtualColumnsOfDateType(std::vector<std::string>& columns);
112     EXPORT static void AddQueryIndex(NativeRdb::AbsPredicates& predicates, const std::vector<std::string>& columns);
113     EXPORT static bool HasDataToAnalysis(const std::shared_ptr<MediaLibraryRdbStore> rdbStore);
114     EXPORT static int32_t UpdateTrashedAssetOnAlbum(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
115         NativeRdb::RdbPredicates &predicates);
116     EXPORT static int32_t UpdateOwnerAlbumId(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
117         const std::vector<DataShare::DataShareValuesBucket> &values, std::vector<int32_t> &updateIds);
118     EXPORT static int32_t UpdateRemovedAssetToTrash(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
119         const std::vector<std::string> &whereIdArgs);
120     EXPORT static int32_t UpdateThumbnailRelatedDataToDefault(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
121         const int64_t fileId);
122     EXPORT static void TransformAppId2TokenId(const std::shared_ptr<MediaLibraryRdbStore> &store);
123     EXPORT static int32_t FillOneAlbumCountAndCoverUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
124         int32_t albumId, PhotoAlbumSubType subtype, std::string &sql);
125     EXPORT static void UpdateSystemAlbumExcludeSource(bool shouldNotify = false);
126     EXPORT static int32_t UpdateHighlightPlayInfo(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
127         const std::string &albumId);
128     static bool AnalyzePhotosData();
129     static bool AnalyzePhotosDataAsync();
130 
131 private:
132     static std::atomic<bool> isNeedRefreshAlbum;
133     static std::atomic<bool> isInRefreshTask;
134     static std::mutex sRefreshAlbumMutex_;
135 };
136 } // namespace OHOS::Media
137 #endif // OHOS_MEDIALIBRARY_RDB_UTILS_H
138