• 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 "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 struct AlbumCounts {
35     int count;
36     int hiddenCount;
37     int imageCount;
38     int videoCount;
39 };
40 
41 class MediaLibraryRdbUtils {
42 public:
43     EXPORT static void UpdateSystemAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
44         const std::vector<std::string> &subtypes = {});
45     EXPORT static void UpdateUserAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
46         const std::vector<std::string> &userAlbumIds = {});
47     EXPORT static void UpdateSourceAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
48         const std::vector<std::string> &sourceAlbumIds = {});
49     static void UpdateUserAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
50         const std::vector<std::string> &uris);
51     EXPORT static void UpdateAnalysisAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
52         const std::vector<std::string> &uris);
53     static void UpdateSourceAlbumByUri(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
54         const std::vector<std::string> &uris);
55 
56     static void AddQueryFilter(NativeRdb::AbsRdbPredicates &predicates);
57     EXPORT static void UpdateSysAlbumHiddenState(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
58         const std::vector<std::string> &subtypes = {});
59     EXPORT static void UpdateAnalysisAlbumInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
60         const std::vector<std::string> &userAlbumIds = {}, const std::vector<std::string> &fileIds = {});
61     EXPORT static void UpdateAnalysisAlbumByFile(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
62         const std::vector<std::string> &fileIds, const std::vector<int> &albumTypes);
63     EXPORT static void UpdateAllAlbums(std::shared_ptr<MediaLibraryRdbStore> rdbStore,
64         const std::vector<std::string> &uris = {});
65 
66     EXPORT static int32_t RefreshAllAlbums(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
67         std::function<void(PhotoAlbumType, PhotoAlbumSubType, int)> refreshProcessHandler,
68         std::function<void()> refreshCallback);
69     EXPORT static int32_t IsNeedRefreshByCheckTable(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
70         bool &signal);
71 
72     EXPORT static void UpdateSystemAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
73         const std::vector<std::string> &subtypes = {});
74     EXPORT static void UpdateUserAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
75         const std::vector<std::string> &userAlbumIds = {});
76     EXPORT static void UpdateAnalysisAlbumCountInternal(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
77         const std::vector<std::string> &subtypes = {});
78     EXPORT static void UpdateAllAlbumsForCloud(const std::shared_ptr<MediaLibraryRdbStore> rdbStore);
79     EXPORT static void UpdateAllAlbumsCountForCloud(const std::shared_ptr<MediaLibraryRdbStore> rdbStore);
80 
81     EXPORT static bool IsNeedRefreshAlbum();
82     EXPORT static void SetNeedRefreshAlbum(bool isNeedRefresh);
83     EXPORT static bool IsInRefreshTask();
84     EXPORT static int32_t GetAlbumIdsForPortrait(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
85         std::vector<std::string> &portraitAlbumIds);
86     EXPORT static int32_t GetAlbumSubtypeArgument(const NativeRdb::RdbPredicates &predicates);
87     EXPORT static void AddVirtualColumnsOfDateType(std::vector<std::string>& columns);
88     EXPORT static void AddQueryIndex(NativeRdb::AbsPredicates& predicates, const std::vector<std::string>& columns);
89     EXPORT static bool HasDataToAnalysis(const std::shared_ptr<MediaLibraryRdbStore> rdbStore);
90     EXPORT static int32_t UpdateTrashedAssetOnAlbum(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
91         NativeRdb::RdbPredicates &predicates);
92     EXPORT static int32_t UpdateOwnerAlbumId(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
93         const std::vector<DataShare::DataShareValuesBucket> &values, std::vector<int32_t> &updateIds);
94     EXPORT static int32_t UpdateRemoveAsset(const std::shared_ptr<MediaLibraryRdbStore> rdbStore,
95         const std::vector<std::string> &whereIdArgs);
96 
97 private:
98     static std::atomic<bool> isNeedRefreshAlbum;
99     static std::atomic<bool> isInRefreshTask;
100     static std::mutex sRefreshAlbumMutex_;
101 };
102 } // namespace OHOS::Media
103 #endif // OHOS_MEDIALIBRARY_RDB_UTILS_H
104