• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_ALBUM_REFRESH_EXECUTION_H
17 #define OHOS_MEDIALIBRARY_ALBUM_REFRESH_EXECUTION_H
18 
19 #include <functional>
20 #include <unordered_map>
21 #include <vector>
22 #include <set>
23 #include <sstream>
24 
25 #include "medialibrary_rdb_utils.h"
26 #include "photo_asset_change_info.h"
27 #include "album_change_info.h"
28 #include "userfile_manager_types.h"
29 #include "album_accurate_refresh.h"
30 #include "system_album_info_calculation.h"
31 #include "dfx_refresh_manager.h"
32 
33 namespace OHOS {
34 namespace Media::AccurateRefresh {
35 
36 class AlbumRefreshExecution {
37 public:
38     int32_t RefreshAlbum(const std::vector<PhotoAssetChangeData> &assetChangeDatas,
39         NotifyAlbumType notifyAlbumType = NO_NOTIFY, bool isRefreshWithDateModified = true);
40     int32_t Notify();
41     int32_t RefreshAllAlbum(NotifyAlbumType notifyAlbumType, bool isRefreshWithDateModified = true);
SetDfxRefreshManager(std::shared_ptr<DfxRefreshManager> dfxRefreshManager)42     void SetDfxRefreshManager(std::shared_ptr<DfxRefreshManager> dfxRefreshManager)
43     {
44         dfxRefreshManager_ = dfxRefreshManager;
45     }
46 
47 private:
48     std::vector<int32_t> GetAlbumIds();
49     // 计算相册增量信息
50     int32_t CalRefreshInfos(const std::vector<PhotoAssetChangeData> &assetChangeDatas);
51 
52     // 计算修改后相册信息
53     int32_t CalAlbumsInfos();
54     // 计算相册普通和隐藏信息
55     bool CalAlbumInfos(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo, int32_t subType);
56     // 计算相册信息
57     bool CalAlbumInfo(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo, int32_t subType);
58     // 计算相册隐藏信息
59     bool CalHiddenAlbumInfo(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo, int32_t subType);
60     // 计算相册count
61     bool CalAlbumCount(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo);
62     // 计算相册hidden count
63     bool CalAlbumHiddenCount(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo);
64     // 计算相册的封面
65     bool CalAlbumCover(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo, int32_t subType);
66     // 计算相册的隐藏封面
67     bool CalAlbumHiddenCover(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo);
68     // 相册封面手动设置场景下计算封面处理
69     bool CalCoverSetCover(AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo);
70 
71     // 更新所有相册
72     int32_t UpdateAllAlbums(NotifyAlbumType notifyAlbumType);
73     // 相册增量更新,从refresh info中增量更新
74     int32_t AccurateUpdateAlbums(NotifyAlbumType notifyAlbumType);
75     // 相册强制更新,从Photos表查询获取
76     int32_t ForceUpdateAlbums(int32_t albumId, bool isHidden, NotifyAlbumType notifyAlbumType);
77     // 从Photos表中获取相册信息
78     int32_t GetUpdateValues(NativeRdb::ValuesBucket &values, const AlbumChangeInfo &albumInfo, bool isHidden,
79         NotifyType &type);
80 
81     bool IsValidCover(const PhotoAssetChangeInfo &assetInfo);
82 
83     // 清空albumInfo中普通信息,执行后增量刷新不刷新普通信息字段
84     void ClearAlbumInfo(AlbumChangeInfo &albumInfo);
85     // 清空albumInfo中隐藏信息,执行后增量刷新不刷新隐藏信息字段
86     void ClearHiddenAlbumInfo(AlbumChangeInfo &albumInfo);
87 
88     // 老通知发送
89     void CheckNotifyOldNotification(NotifyAlbumType notifyAlbumType, const AlbumChangeInfo &albumInfo,
90         NotifyType type);
91 
92     // 测试增量数据和强制数据是否一致
93     void CheckHiddenAlbumInfo(NativeRdb::ValuesBucket &values, std::stringstream &ss);
94     void CheckAlbumInfo(NativeRdb::ValuesBucket &values, std::stringstream &ss);
95     void CheckUpdateAlbumInfo(const AlbumChangeInfo &albumInfo, bool isHidden);
96     void CheckUpdateValues(const AlbumChangeInfo &albumInfo, const AlbumRefreshInfo &refreshInfo,
97         NativeRdb::ValuesBucket &values);
98     bool CheckSetHiddenAlbumInfo(AlbumChangeInfo &albumInfo);
99     void CheckInitSystemCalculation();
100 
101 private:
102     // 系统相册
103     static std::unordered_map<PhotoAlbumSubType, SystemAlbumInfoCalculation> systemTypeAlbumCalculations_;
104     static std::unordered_map<int32_t, SystemAlbumInfoCalculation> systemAlbumCalculations_;
105     std::unordered_map<int32_t, AlbumRefreshInfo> systemAlbumRefreshInfos_;
106 
107     // 用户相册和来源相册
108     std::unordered_map<int32_t, AlbumRefreshInfo> ownerAlbumRefreshInfos_;
109 
110     // 所有相册refreshInfo
111     std::unordered_map<int32_t, AlbumRefreshInfo> albumRefreshInfos_;
112     // 修改前相册信息
113     std::unordered_map<int32_t, AlbumChangeInfo> initAlbumInfos_;
114 
115     AlbumAccurateRefresh albumRefresh_;
116 
117     std::shared_ptr<DfxRefreshManager> dfxRefreshManager_;
118 
119     // 需要刷新的相册信息
120     std::unordered_map<int32_t, std::pair<AlbumRefreshInfo, AlbumChangeInfo>> refreshAlbums_;
121 
122     // 需要强制刷新的相册信息
123     std::set<int32_t> forceRefreshAlbums_;
124     std::set<int32_t> forceRefreshHiddenAlbums_;
125 
126     static std::mutex albumRefreshMtx_;
127 
128     bool isRefreshWithDateModified_ = true;
129 };
130 
131 } // namespace Media
132 } // namespace OHOS
133 
134 #endif