• 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_ASSET_ACCURATE_REFRESH_H
17 #define OHOS_MEDIALIBRARY_ASSET_ACCURATE_REFRESH_H
18 
19 #include <functional>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "abs_rdb_predicates.h"
25 
26 #include "medialibrary_rdb_utils.h"
27 #include "accurate_refresh_base.h"
28 #include "photo_asset_change_info.h"
29 #include "asset_data_manager.h"
30 #include "album_refresh_execution.h"
31 #include "asset_change_notify_execution.h"
32 
33 namespace OHOS {
34 namespace Media::AccurateRefresh {
35 #define EXPORT __attribute__ ((visibility ("default")))
36 
37 class EXPORT AssetAccurateRefresh : public AccurateRefreshBase {
38 public:
AssetAccurateRefresh()39     AssetAccurateRefresh() : AccurateRefreshBase() {};
40     AssetAccurateRefresh(std::shared_ptr<TransactionOperations> trans);
AssetAccurateRefresh(const std::string & targetBusiness)41     AssetAccurateRefresh(const std::string &targetBusiness) : AccurateRefreshBase(targetBusiness, nullptr) {}
42     AssetAccurateRefresh(const std::string &targetBusiness, std::shared_ptr<TransactionOperations> trans);
SetDfxRefreshManager(std::shared_ptr<DfxRefreshManager> dfxRefreshManager)43     void SetDfxRefreshManager(std::shared_ptr<DfxRefreshManager> dfxRefreshManager)
44     {
45         refreshManager = dfxRefreshManager;
46     }
~AssetAccurateRefresh()47     virtual ~AssetAccurateRefresh() {}
48     // 初始化datamanager,新增场景下使用,不需要初始化数据,Init只需要执行一次
49     int32_t Init() override;
50 
51     // delete/update 场景下初始化数据,Init只需要执行一次
52     int32_t Init(const NativeRdb::AbsRdbPredicates &predicates) override; // init的查询语句
53     int32_t Init(const std::string &sql, const std::vector<NativeRdb::ValueObject> bindArgs) override; // 查询语句
54     int32_t Init(const std::vector<int32_t> &fileIds) override; // 删除/更新指定fileIds场景使用
55 
56     // 更新modified数据信息;数据库操作只是缓存数据,需要执行这个函数触发对比修改前后的数据
57     int32_t UpdateModifiedDatas();
58 
59     // refresh album based on init datas and modified datas.
60     int32_t RefreshAlbum(NotifyAlbumType notifyAlbumType = NO_NOTIFY, bool isRefreshWithDateModified = true);
61 
62     // 根据传递的assetChangeDatas更新相册,不需要dataManager_处理
63     int32_t RefreshAlbum(const std::vector<PhotoAssetChangeData> &assetChangeDatas,
64         NotifyAlbumType notifyAlbumType = NO_NOTIFY, bool isRefreshWithDateModified = true);
65 
66     // 只刷新相册内容,不刷新相册date_modified
67     int32_t RefreshAlbumNoDateModified(NotifyAlbumType notifyAlbumType = NO_NOTIFY);
68 
69     // notify assest change infos based on init datas and modified datas.
70     int32_t Notify();
71 
72     // 根据传递的assetChangeDatas进行通知,不需要dataManager_处理
73     int32_t Notify(const std::vector<PhotoAssetChangeData> &assetChangeDatas);
74     using AccurateRefreshBase::LogicalDeleteReplaceByUpdate;
75     int32_t LogicalDeleteReplaceByUpdate(MediaLibraryCommand &cmd, int32_t &deletedRows) override;
76     int32_t LogicalDeleteReplaceByUpdate(const NativeRdb::AbsRdbPredicates &predicates, int32_t &deletedRows) override;
77 
78     int32_t SetContentChanged(int32_t fileId, bool isChanged);
79     int32_t SetThumbnailStatus(int32_t fileId, int32_t status);
80     static int32_t NotifyForReCheck();
81 
82 protected:
83     int32_t UpdateModifiedDatasInner(const std::vector<int> &fileIds, RdbOperation operation,
84         PendingInfo pendingInfo = PendingInfo()) override;
85     std::string GetReturningKeyName() override;
86     bool IsValidTable(std::string tableName) override;
87 private:
88     int32_t DeleteCommon(std::function<int32_t(NativeRdb::ValuesBucket &)> updateExe);
89     int32_t RefreshAllAlbum(NotifyAlbumType notifyAlbumType, bool isRefreshWithDateModified = true);
90 
91 private:
92     AssetDataManager dataManager_;
93     AlbumRefreshExecution albumRefreshExe_;
94     AssetChangeNotifyExecution notifyExe_;
95     std::shared_ptr<DfxRefreshManager> refreshManager;
96     // 资产数据查询锁,查询资产信息放入MultiThreadAssetChangeInfoMgr中,防止同一资产多线程访问
97     static std::mutex assetQueryMutex_;
98 };
99 } // namespace Media
100 } // namespace OHOS
101 
102 #endif