• 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 #define MLOG_TAG "AccurateRefresh::AlbumChangeNotifyExecution"
17 
18 #include "album_change_notify_execution.h"
19 #include "accurate_debug_log.h"
20 #include "medialibrary_notify_new.h"
21 
22 using namespace std;
23 using namespace OHOS::Media::Notification;
24 namespace OHOS {
25 namespace Media::AccurateRefresh {
26 
Notify(vector<AlbumChangeData> changeDatas)27 void AlbumChangeNotifyExecution::Notify(vector<AlbumChangeData> changeDatas)
28 {
29     for (auto &changeData : changeDatas) {
30         if (changeData.operation_ == RDB_OPERATION_ADD) {
31             InsertNotifyInfo(ALBUM_OPERATION_ADD, changeData);
32         } else if (changeData.operation_ == RDB_OPERATION_REMOVE) {
33             InsertNotifyInfo(ALBUM_OPERATION_REMOVE, changeData);
34         } else if (changeData.operation_ == RDB_OPERATION_UPDATE) {
35             auto subType = changeData.infoAfterChange_.albumSubType_;
36             // 隐藏相册
37             if (subType == static_cast<int32_t>(PhotoAlbumSubType::HIDDEN)) {
38                 InsertNotifyInfo(ALBUM_OPERATION_UPDATE_HIDDEN, changeData);
39                 continue;
40             }
41             // 回收站相册
42             if (subType == static_cast<int32_t>(PhotoAlbumSubType::TRASH)) {
43                 InsertNotifyInfo(ALBUM_OPERATION_UPDATE_TRASH, changeData);
44                 continue;
45             }
46 
47             // 相册删除逻辑
48             bool isDelete = changeData.infoAfterChange_.dirty_ == static_cast<int32_t>(DirtyType::TYPE_DELETED) &&
49                 changeData.infoBeforeChange_.dirty_ != static_cast<int32_t>(DirtyType::TYPE_DELETED);
50             if (isDelete) {
51                 changeData.isDelete_ = true;
52                 InsertNotifyInfo(ALBUM_OPERATION_REMOVE, changeData);
53                 continue;
54             }
55             if (changeData.IsAlbumHiddenInfoChange()) {
56                 InsertNotifyInfo(ALBUM_OPERATION_UPDATE_HIDDEN, changeData);
57             }
58             if (changeData.IsAlbumInfoChange()) {
59                 InsertNotifyInfo(ALBUM_OPERATION_UPDATE, changeData);
60             }
61         }
62     }
63 
64     for (auto &item : notifyInfos_) {
65         NotifyInfoInner notifyInfo;
66         notifyInfo.tableType = NotifyTableType::PHOTO_ALBUM;
67         notifyInfo.operationType = item.first;
68         NotifyLevel level;
69         notifyInfo.notifyLevel = level;
70         auto &changeDatas = item.second;
71         for (auto &changeData : changeDatas) {
72             notifyInfo.infos.push_back(changeData);
73             ACCURATE_INFO("notify PHOTO_ALBUM info: operationType(0x%{public}x), level(%{public}d), info(%{public}s)",
74                 static_cast<int32_t>(item.first),
75                 static_cast<int32_t>(notifyInfo.notifyLevel.priority), changeData.ToString().c_str());
76         }
77         // 调用发送通知接口
78         Notification::MediaLibraryNotifyNew::AddItem(notifyInfo);
79     }
80 }
81 
InsertNotifyInfo(AlbumRefreshOperation operation,const AlbumChangeData & changeData)82 void AlbumChangeNotifyExecution::InsertNotifyInfo(AlbumRefreshOperation operation, const AlbumChangeData &changeData)
83 {
84     AlbumChangeData albumChangeData = changeData;
85     ACCURATE_DEBUG("origin data: %{public}s", changeData.ToString(true).c_str());
86     // screenshot do not need to send notify
87     bool isSrceenshot =
88         albumChangeData.infoBeforeChange_.albumSubType_ == static_cast<int32_t>(PhotoAlbumSubType::SCREENSHOT) ||
89         albumChangeData.infoAfterChange_.albumSubType_ == static_cast<int32_t>(PhotoAlbumSubType::SCREENSHOT);
90     CHECK_AND_RETURN_LOG(!isSrceenshot, "album subtype is screenshot(1029)");
91     // end
92     if (operation == ALBUM_OPERATION_ADD) {
93         albumChangeData.infoBeforeChange_.albumId_ = INVALID_INT32_VALUE;
94         ACCURATE_DEBUG("modify remove data: %{public}s", albumChangeData.ToString(true).c_str());
95     } else if (operation == ALBUM_OPERATION_REMOVE) {
96         albumChangeData.infoAfterChange_.albumId_ = INVALID_INT32_VALUE;
97         ACCURATE_DEBUG("modify remove data: %{public}s", albumChangeData.ToString(true).c_str());
98     }
99     auto iter = notifyInfos_.find(operation);
100     if (iter == notifyInfos_.end()) {
101         vector<AlbumChangeData> infos;
102         infos.push_back(albumChangeData);
103         notifyInfos_.emplace(operation, infos);
104         return;
105     } else {
106         auto &infos = iter->second;
107         infos.push_back(albumChangeData);
108     }
109 }
110 
111 } // namespace Media
112 } // namespace OHOS