• 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_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> &notifyInfos,
36         std::vector<MediaChangeInfo> &mediaChangeInfos);
37     EXPORT static void AddAlbum(const std::string &albumId);
38 private:
39     static MediaChangeInfo BuildMediaChangeInfo(NotifyInfoInner &notifyInfoInner,
40         bool isForRecheck, NotifyType notifyType, NotifyUriType notifyUriType);
41     static std::vector<MediaChangeInfo> HandleAssetAdd(NotifyInfoInner &notifyInfoInner);
42     static std::vector<MediaChangeInfo> HandleAssetAddHidden(NotifyInfoInner &notifyInfoInner);
43     static std::vector<MediaChangeInfo> HandleAssetAddTrash(NotifyInfoInner &notifyInfoInner);
44     static std::vector<MediaChangeInfo> HandleAssetRemove(NotifyInfoInner &notifyInfoInner);
45     static std::vector<MediaChangeInfo> HandleAssetRemoveHidden(NotifyInfoInner &notifyInfoInner);
46     static std::vector<MediaChangeInfo> HandleAssetRemoveTrash(NotifyInfoInner &notifyInfoInner);
47     static std::vector<MediaChangeInfo> HandleAssetUpdateNormal(NotifyInfoInner &notifyInfoInner);
48     static std::vector<MediaChangeInfo> HandleAssetUpdateRemoveNormal(NotifyInfoInner &notifyInfoInner);
49     static std::vector<MediaChangeInfo> HandleAssetUpdateAddNormal(NotifyInfoInner &notifyInfoInner);
50     static std::vector<MediaChangeInfo> HandleAssetUpdateHidden(NotifyInfoInner &notifyInfoInner);
51     static std::vector<MediaChangeInfo> HandleAssetUpdateRemoveHidden(NotifyInfoInner &notifyInfoInner);
52     static std::vector<MediaChangeInfo> HandleAssetUpdateAddHidden(NotifyInfoInner &notifyInfoInner);
53     static std::vector<MediaChangeInfo> HandleAssetUpdateTrash(NotifyInfoInner &notifyInfoInner);
54     static std::vector<MediaChangeInfo> HandleAssetUpdateAddTrash(NotifyInfoInner &notifyInfoInner);
55     static std::vector<MediaChangeInfo> HandleAssetUpdateRemoveTrash(NotifyInfoInner &notifyInfoInner);
56     static std::vector<MediaChangeInfo> HandleAssetTrash(NotifyInfoInner &notifyInfoInner);
57     static std::vector<MediaChangeInfo> HandleAssetUntrash(NotifyInfoInner &notifyInfoInner);
58     static std::vector<MediaChangeInfo> HandleAssetHidden(NotifyInfoInner &notifyInfoInner);
59     static std::vector<MediaChangeInfo> HandleAssetUnhidden(NotifyInfoInner &notifyInfoInner);
60     static std::vector<MediaChangeInfo> HandleAssetRecheck(NotifyInfoInner &notifyInfoInner);
61 
62     static std::vector<MediaChangeInfo> HandleAlbumAdd(NotifyInfoInner &notifyInfoInner);
63     static std::vector<MediaChangeInfo> HandleAlbumRemove(NotifyInfoInner &notifyInfoInner);
64     static std::vector<MediaChangeInfo> HandleAlbumUpdate(NotifyInfoInner &notifyInfoInner);
65     static std::vector<MediaChangeInfo> HandleAlbumUpdateHidden(NotifyInfoInner &notifyInfoInner);
66     static std::vector<MediaChangeInfo> HandleAlbumUpdateTrash(NotifyInfoInner &notifyInfoInner);
67     static std::vector<MediaChangeInfo> HandleAlbumRecheck(NotifyInfoInner &notifyInfoInner);
68     static std::vector<MediaChangeInfo> HandleAlbumAddAndUpdate(NotifyInfoInner &notifyInfoInner);
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