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_MEDIA_NOTIFICATION_CLASSIFICATION_H 17 #define OHOS_MEDIA_NOTIFICATION_CLASSIFICATION_H 18 19 #include <vector> 20 #include <unordered_map> 21 #include <functional> 22 #include <variant> 23 24 #include "notify_info_inner.h" 25 #include "media_change_info.h" 26 27 namespace OHOS { 28 namespace Media { 29 namespace Notification { 30 #define EXPORT __attribute__ ((visibility ("default"))) 31 class NotificationClassification { 32 public: 33 EXPORT NotificationClassification(); 34 EXPORT ~NotificationClassification(); 35 EXPORT static void ConvertNotification(std::vector<NotifyInfoInner> ¬ifyInfos, 36 std::vector<MediaChangeInfo> &mediaChangeInfos); 37 EXPORT static void AddAlbum(const std::string &albumId); 38 private: 39 static MediaChangeInfo BuildMediaChangeInfo(NotifyInfoInner ¬ifyInfoInner, 40 bool isForRecheck, NotifyType notifyType, NotifyUriType notifyUriType); 41 static std::vector<MediaChangeInfo> HandleAssetAdd(NotifyInfoInner ¬ifyInfoInner); 42 static std::vector<MediaChangeInfo> HandleAssetAddHidden(NotifyInfoInner ¬ifyInfoInner); 43 static std::vector<MediaChangeInfo> HandleAssetAddTrash(NotifyInfoInner ¬ifyInfoInner); 44 static std::vector<MediaChangeInfo> HandleAssetRemove(NotifyInfoInner ¬ifyInfoInner); 45 static std::vector<MediaChangeInfo> HandleAssetRemoveHidden(NotifyInfoInner ¬ifyInfoInner); 46 static std::vector<MediaChangeInfo> HandleAssetRemoveTrash(NotifyInfoInner ¬ifyInfoInner); 47 static std::vector<MediaChangeInfo> HandleAssetUpdateNormal(NotifyInfoInner ¬ifyInfoInner); 48 static std::vector<MediaChangeInfo> HandleAssetUpdateRemoveNormal(NotifyInfoInner ¬ifyInfoInner); 49 static std::vector<MediaChangeInfo> HandleAssetUpdateAddNormal(NotifyInfoInner ¬ifyInfoInner); 50 static std::vector<MediaChangeInfo> HandleAssetUpdateHidden(NotifyInfoInner ¬ifyInfoInner); 51 static std::vector<MediaChangeInfo> HandleAssetUpdateRemoveHidden(NotifyInfoInner ¬ifyInfoInner); 52 static std::vector<MediaChangeInfo> HandleAssetUpdateAddHidden(NotifyInfoInner ¬ifyInfoInner); 53 static std::vector<MediaChangeInfo> HandleAssetUpdateTrash(NotifyInfoInner ¬ifyInfoInner); 54 static std::vector<MediaChangeInfo> HandleAssetUpdateAddTrash(NotifyInfoInner ¬ifyInfoInner); 55 static std::vector<MediaChangeInfo> HandleAssetUpdateRemoveTrash(NotifyInfoInner ¬ifyInfoInner); 56 static std::vector<MediaChangeInfo> HandleAssetTrash(NotifyInfoInner ¬ifyInfoInner); 57 static std::vector<MediaChangeInfo> HandleAssetUntrash(NotifyInfoInner ¬ifyInfoInner); 58 static std::vector<MediaChangeInfo> HandleAssetHidden(NotifyInfoInner ¬ifyInfoInner); 59 static std::vector<MediaChangeInfo> HandleAssetUnhidden(NotifyInfoInner ¬ifyInfoInner); 60 static std::vector<MediaChangeInfo> HandleAssetRecheck(NotifyInfoInner ¬ifyInfoInner); 61 62 static std::vector<MediaChangeInfo> HandleAlbumAdd(NotifyInfoInner ¬ifyInfoInner); 63 static std::vector<MediaChangeInfo> HandleAlbumRemove(NotifyInfoInner ¬ifyInfoInner); 64 static std::vector<MediaChangeInfo> HandleAlbumUpdate(NotifyInfoInner ¬ifyInfoInner); 65 static std::vector<MediaChangeInfo> HandleAlbumUpdateHidden(NotifyInfoInner ¬ifyInfoInner); 66 static std::vector<MediaChangeInfo> HandleAlbumUpdateTrash(NotifyInfoInner ¬ifyInfoInner); 67 static std::vector<MediaChangeInfo> HandleAlbumRecheck(NotifyInfoInner ¬ifyInfoInner); 68 static std::vector<MediaChangeInfo> HandleAlbumAddAndUpdate(NotifyInfoInner ¬ifyInfoInner); 69 private: 70 static std::unordered_map<std::variant<AssetRefreshOperation, AlbumRefreshOperation>, 71 std::function<std::vector<MediaChangeInfo>(NotifyInfoInner&)>> classificationMap; 72 // 存储使用触发器创建的albumId 73 static std::unordered_set<int32_t> addAlbumIdSet_; 74 static std::mutex addAlbumIdMutex_; 75 }; 76 } // namespace Notification 77 } // namespace Media 78 } // namespace OHOS 79 80 #endif // OHOS_MEDIA_NOTIFICATION_CLASSIFICATION_H