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_ACCURATE_REFRESH_H 17 #define OHOS_MEDIALIBRARY_ALBUM_ACCURATE_REFRESH_H 18 19 #include <functional> 20 #include <string> 21 #include <vector> 22 #include <unordered_map> 23 24 #include "abs_rdb_predicates.h" 25 26 #include "accurate_refresh_base.h" 27 #include "album_change_info.h" 28 #include "album_data_manager.h" 29 #include "album_change_notify_execution.h" 30 31 namespace OHOS { 32 namespace Media::AccurateRefresh { 33 #define EXPORT __attribute__ ((visibility ("default"))) 34 35 class EXPORT AlbumAccurateRefresh : public AccurateRefreshBase { 36 public: AlbumAccurateRefresh()37 AlbumAccurateRefresh() : AccurateRefreshBase() {}; 38 AlbumAccurateRefresh(std::shared_ptr<TransactionOperations> trans); AlbumAccurateRefresh(const std::string & targetBusiness)39 AlbumAccurateRefresh(const std::string &targetBusiness) : AccurateRefreshBase(targetBusiness, nullptr) {} 40 AlbumAccurateRefresh(const std::string &targetBusiness, std::shared_ptr<TransactionOperations> trans); ~AlbumAccurateRefresh()41 virtual ~AlbumAccurateRefresh() {} 42 // init的查询语句 43 int32_t Init() override; 44 int32_t Init(const NativeRdb::AbsRdbPredicates &predicates) override; 45 int32_t Init(const std::string &sql, const std::vector<NativeRdb::ValueObject> bindArgs) override; 46 int32_t Init(const std::vector<int32_t> &albumIds) override; 47 48 // 更新modified数据信息;数据库操作只是缓存数据,需要执行这个函数触发对比修改前后的数据 49 int32_t UpdateModifiedDatas(); 50 51 // notify album change infos based on init datas and modified datas. 52 int32_t Notify(std::shared_ptr<DfxRefreshManager> dfxRefreshManager = nullptr); 53 54 // 根据传递的assetChangeDatas进行通知,不需要dataManager_处理 55 int32_t Notify(std::vector<AlbumChangeData> albumChangeDatas, 56 std::shared_ptr<DfxRefreshManager> dfxRefreshManager = nullptr); 57 58 int32_t NotifyAddAlbums(const std::vector<std::string> &albumIdsStr); 59 60 std::unordered_map<int32_t, AlbumChangeInfo> GetInitAlbumInfos(); 61 62 using AccurateRefreshBase::LogicalDeleteReplaceByUpdate; 63 int32_t LogicalDeleteReplaceByUpdate(MediaLibraryCommand &cmd, int32_t &deletedRows) override; 64 int32_t LogicalDeleteReplaceByUpdate(const NativeRdb::AbsRdbPredicates &predicates, int32_t &deletedRows) override; 65 static int32_t NotifyForReCheck(); 66 bool IsCoverContentChange(string &fileId); 67 void NotifyAlbumsCoverChange(string &fileId, vector<int32_t> &albumIds); 68 69 protected: 70 int32_t UpdateModifiedDatasInner(const std::vector<int> &albumIds, RdbOperation operation, 71 PendingInfo pendingInfo = PendingInfo()) override; 72 std::string GetReturningKeyName() override; 73 bool IsValidTable(std::string tableName) override; 74 75 private: 76 int32_t DeleteCommon(std::function<int32_t(NativeRdb::ValuesBucket &)> updateExe); 77 78 private: 79 AlbumDataManager dataManager_; 80 AlbumChangeNotifyExecution notifyExe_; 81 }; 82 83 } // namespace Media 84 } // namespace OHOS 85 86 #endif