1 /*
2 * Copyright (c) 2023 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 #include "acquire_data_subscribe_manager.h"
17 #include <cinttypes>
18 #include <functional>
19 #include "acquire_data_callback_proxy.h"
20 #include "database_manager.h"
21 #include "security_guard_define.h"
22 #include "security_collector_subscribe_info.h"
23 #include "security_guard_log.h"
24 #include "ffrt.h"
25 #include "event_define.h"
26 #include "i_model_info.h"
27 #include "config_data_manager.h"
28 #include "collector_manager.h"
29 #include "data_collection.h"
30 #include "security_event_filter.h"
31 #include "data_format.h"
32
33 namespace OHOS::Security::SecurityGuard {
34 namespace {
35 constexpr size_t MAX_CACHE_EVENT_SIZE = 64 * 1024;
36 constexpr int64_t MAX_DURATION_TEN_SECOND = 10 * 1000;
37 constexpr int64_t MAX_FILTER_SIZE = 256;
38 constexpr size_t MAX_SUBS_SIZE = 10;
39 std::mutex g_mutex{};
40 std::map<sptr<IRemoteObject>, AcquireDataSubscribeManager::SubscriberInfo> g_subscriberInfoMap{};
41 }
42
GetInstance()43 AcquireDataSubscribeManager& AcquireDataSubscribeManager::GetInstance()
44 {
45 static AcquireDataSubscribeManager instance;
46 return instance;
47 }
48
AcquireDataSubscribeManager()49 AcquireDataSubscribeManager::AcquireDataSubscribeManager() : listener_(std::make_shared<DbListener>()) {}
50
InsertSubscribeRecord(const SecurityCollector::SecurityCollectorSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & callback)51 int AcquireDataSubscribeManager::InsertSubscribeRecord(
52 const SecurityCollector::SecurityCollectorSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &callback)
53 {
54 EventCfg config;
55 bool isSuccess = ConfigDataManager::GetInstance().GetEventConfig(subscribeInfo.GetEvent().eventId, config);
56 if (!isSuccess) {
57 SGLOGE("GetEventConfig error");
58 return BAD_PARAM;
59 }
60
61 std::lock_guard<std::mutex> lock(g_mutex);
62 SubscriberInfo subInfo {};
63 if (g_subscriberInfoMap.size() >= MAX_SUBS_SIZE) {
64 SGLOGE("has been max subscriber size");
65 return BAD_PARAM;
66 }
67 if (g_subscriberInfoMap.count(callback) == 0) {
68 subInfo.subscribe.emplace_back(subscribeInfo);
69 subInfo.timer = std::make_shared<CleanupTimer>();
70 subInfo.timer->Start(callback, MAX_DURATION_TEN_SECOND);
71 g_subscriberInfoMap[callback] = subInfo;
72 } else {
73 g_subscriberInfoMap.at(callback).subscribe.emplace_back(subscribeInfo);
74 }
75
76 int32_t code = DatabaseManager::GetInstance().SubscribeDb({subscribeInfo.GetEvent().eventId}, listener_);
77 if (code != SUCCESS) {
78 SGLOGE("SubscribeDb error");
79 return code;
80 }
81 code = SubscribeSc(subscribeInfo.GetEvent().eventId, callback);
82 if (code != SUCCESS) {
83 SGLOGE("SubscribeSc error");
84 return code;
85 }
86 SGLOGI("InsertSubscribeRecord subscriberInfoMap_size %{public}zu", g_subscriberInfoMap.size());
87 for (const auto &i : g_subscriberInfoMap) {
88 SGLOGI("InsertSubscribeRecord subscriberInfoMap_subscribe_size %{public}zu", i.second.subscribe.size());
89 }
90 return SUCCESS;
91 }
92
SubscribeScInSg(int64_t eventId,const sptr<IRemoteObject> & callback)93 int AcquireDataSubscribeManager::SubscribeScInSg(int64_t eventId, const sptr<IRemoteObject> &callback)
94 {
95 SecurityCollector::Event event {};
96 event.eventId = eventId;
97 auto collectorListenner = std::make_shared<CollectorListenner>(event);
98 SGLOGI("Scheduling start collector, eventId:%{public}" PRId64, eventId);
99 if (eventToListenner_.count(eventId) != 0) {
100 return SUCCESS;
101 }
102 if (!SecurityCollector::DataCollection::GetInstance().StartCollectors({eventId}, collectorListenner)) {
103 SGLOGI("Subscribe SG failed, eventId=%{public}" PRId64, eventId);
104 return FAILED;
105 }
106 eventToListenner_.emplace(eventId, collectorListenner);
107 if (muteCache_.count(eventId) == 0) {
108 return SUCCESS;
109 }
110 for (const auto &iter : muteCache_.at(eventId)) {
111 for (const auto &it : iter.second) {
112 if (it.eventId == eventId && it.isSetMute == true &&
113 !SecurityCollector::DataCollection::GetInstance().Mute(
114 it, callbackHashMapNotSetMute_[iter.first])) {
115 SGLOGE("Mute SG failed, eventId=%{public}" PRId64, eventId);
116 }
117 callbackHashMap_[iter.first] = callbackHashMapNotSetMute_[iter.first];
118 if (it.eventId == eventId && it.isSetMute == false &&
119 !SecurityCollector::DataCollection::GetInstance().Unmute(
120 it, callbackHashMapNotSetMute_[iter.first])) {
121 SGLOGE("Unmute SG failed, eventId=%{public}" PRId64, eventId);
122 }
123 }
124 }
125 return SUCCESS;
126 }
127
SubscribeScInSc(int64_t eventId,const sptr<IRemoteObject> & callback)128 int AcquireDataSubscribeManager::SubscribeScInSc(int64_t eventId, const sptr<IRemoteObject> &callback)
129 {
130 if (scSubscribeMap_.count(eventId) != 0) {
131 return SUCCESS;
132 }
133 SecurityCollector::Event scEvent;
134 scEvent.eventId = eventId;
135 auto subscriber = std::make_shared<AcquireDataSubscribeManager::SecurityCollectorSubscriber>(scEvent);
136 int code = SecurityCollector::CollectorManager::GetInstance().Subscribe(subscriber);
137 if (code != SUCCESS) {
138 SGLOGI("Subscribe SC failed, code=%{public}d", code);
139 return code;
140 }
141 scSubscribeMap_[eventId] = subscriber;
142 if (muteCache_.count(eventId) == 0) {
143 return SUCCESS;
144 }
145 SGLOGI("Subscribe SC muteCache_ size, code=%{public}zu eventId=%{public}" PRId64,
146 muteCache_.at(eventId).size(), eventId);
147 for (const auto &iter : muteCache_.at(eventId)) {
148 for (auto it : iter.second) {
149 if (it.eventId == eventId && it.isSetMute == true) {
150 code = SecurityCollector::CollectorManager::GetInstance().Mute(
151 it, callbackHashMapNotSetMute_[iter.first]);
152 }
153 callbackHashMap_[iter.first] = callbackHashMapNotSetMute_[iter.first];
154 if (it.eventId == eventId && it.isSetMute == false) {
155 code = SecurityCollector::CollectorManager::GetInstance().Unmute(
156 it, callbackHashMapNotSetMute_[iter.first]);
157 }
158 }
159 }
160 if (code != SUCCESS) {
161 SGLOGE("mute or unmute has some err code=%{public}d", code);
162 }
163 return SUCCESS;
164 }
165
SubscribeSc(int64_t eventId,const sptr<IRemoteObject> & callback)166 int AcquireDataSubscribeManager::SubscribeSc(int64_t eventId, const sptr<IRemoteObject> &callback)
167 {
168 EventCfg config {};
169 bool isSuccess = ConfigDataManager::GetInstance().GetEventConfig(eventId, config);
170 if (!isSuccess) {
171 SGLOGE("GetEventConfig error");
172 return BAD_PARAM;
173 }
174 if (config.eventType != static_cast<uint32_t>(EventTypeEnum::SUBSCRIBE_COLL)) {
175 return SUCCESS;
176 }
177 // 订阅SG
178 if (config.prog == "security_guard") {
179 return SubscribeScInSg(eventId, callback);
180 }
181
182 // 订阅SC
183 return SubscribeScInSc(eventId, callback);
184 }
185
UnSubscribeSc(int64_t eventId)186 int AcquireDataSubscribeManager::UnSubscribeSc(int64_t eventId)
187 {
188 EventCfg config;
189 bool isSuccess = ConfigDataManager::GetInstance().GetEventConfig(eventId, config);
190 if (!isSuccess) {
191 SGLOGE("GetEventConfig error");
192 return BAD_PARAM;
193 }
194 if (config.eventType != static_cast<uint32_t>(EventTypeEnum::SUBSCRIBE_COLL)) {
195 return SUCCESS;
196 }
197 // 解订阅SG
198 if (config.prog == "security_guard") {
199 if (eventToListenner_.count(eventId) == 0) {
200 SGLOGE("not find evenId in linstener, eventId=%{public}" PRId64, eventId);
201 return FAILED;
202 }
203 if (!SecurityCollector::DataCollection::GetInstance().StopCollectors({eventId})) {
204 SGLOGE("UnSubscribe SG failed, eventId=%{public}" PRId64, eventId);
205 return FAILED;
206 }
207 eventToListenner_.erase(eventId);
208 return SUCCESS;
209 }
210 // 解订阅SC
211 auto it = scSubscribeMap_.find(eventId);
212 if (it == scSubscribeMap_.end()) {
213 SGLOGE("event not subscribe eventId=%{public}" PRId64, eventId);
214 return FAILED;
215 }
216 int ret = SecurityCollector::CollectorManager::GetInstance().Unsubscribe(it->second);
217 if (ret != SUCCESS) {
218 SGLOGE("UnSubscribe SC failed, ret=%{public}d", ret);
219 return ret;
220 }
221 it->second = nullptr;
222 scSubscribeMap_.erase(it);
223 SGLOGI("UnSubscribeSc scSubscribeMap_size %{public}zu", scSubscribeMap_.size());
224 return SUCCESS;
225 }
226
UnSubscribeScAndDb(int64_t eventId)227 int AcquireDataSubscribeManager::UnSubscribeScAndDb(int64_t eventId)
228 {
229 int ret = DatabaseManager::GetInstance().UnSubscribeDb({eventId}, listener_);
230 if (ret != SUCCESS) {
231 SGLOGE("UnSubscribeDb error");
232 return ret;
233 }
234 ret = UnSubscribeSc(eventId);
235 if (ret != SUCCESS) {
236 SGLOGE("UnSubscribeSc error");
237 return ret;
238 }
239 return ret;
240 }
241
RemoveSubscribeRecord(int64_t eventId,const sptr<IRemoteObject> & callback)242 int AcquireDataSubscribeManager::RemoveSubscribeRecord(int64_t eventId, const sptr<IRemoteObject> &callback)
243 {
244 std::lock_guard<std::mutex> lock(g_mutex);
245 auto iter = g_subscriberInfoMap.find(callback);
246 if (iter == g_subscriberInfoMap.end()) {
247 SGLOGI("not find caller in g_subscriberInfoMap");
248 return SUCCESS;
249 }
250 // first erase current callback subscribed info
251 for (auto it = g_subscriberInfoMap.at(callback).subscribe.begin();
252 it != g_subscriberInfoMap.at(callback).subscribe.end(); it++) {
253 if (it->GetEvent().eventId == eventId) {
254 g_subscriberInfoMap.at(callback).subscribe.erase(it);
255 break;
256 }
257 }
258 // second erase current callback when subscribed member is empty
259 if (g_subscriberInfoMap.at(callback).subscribe.empty()) {
260 g_subscriberInfoMap.erase(iter);
261 }
262
263 for (const auto &it : g_subscriberInfoMap) {
264 for (const auto &i : it.second.subscribe) {
265 if (i.GetEvent().eventId == eventId) {
266 return SUCCESS;
267 }
268 }
269 }
270 SGLOGI("RemoveSubscribeRecord subscriberInfoMap__size %{public}zu", g_subscriberInfoMap.size());
271 for (const auto &i : g_subscriberInfoMap) {
272 SGLOGI("RemoveSubscribeRecord subscriberInfoMap_subscribe_size %{public}zu", i.second.subscribe.size());
273 }
274 return UnSubscribeScAndDb(eventId);
275 }
276
RemoveSubscribeRecordOnRemoteDied(const sptr<IRemoteObject> & callback)277 void AcquireDataSubscribeManager::RemoveSubscribeRecordOnRemoteDied(const sptr<IRemoteObject> &callback)
278 {
279 std::lock_guard<std::mutex> lock(g_mutex);
280 std::set<int64_t> eventIdNeedUnSub {};
281 std::set<int64_t> currentEventId {};
282 for (const auto &i : g_subscriberInfoMap[callback].subscribe) {
283 eventIdNeedUnSub.insert(i.GetEvent().eventId);
284 }
285 g_subscriberInfoMap.erase(callback);
286 for (const auto &i : g_subscriberInfoMap) {
287 for (const auto &iter : i.second.subscribe) {
288 currentEventId.insert(iter.GetEvent().eventId);
289 }
290 }
291 for (const auto &i : eventIdNeedUnSub) {
292 if (currentEventId.count(i) == 0) {
293 (void)UnSubscribeScAndDb(i);
294 }
295 }
296 SGLOGI("RemoveSubscribeRecordOnRemoteDied subscriberInfoMap__size %{public}zu", g_subscriberInfoMap.size());
297 for (const auto &i : g_subscriberInfoMap) {
298 SGLOGI("RemoveSubscribeRecordOnRemoteDied subscriberInfoMap_subscribe_size %{public}zu",
299 i.second.subscribe.size());
300 }
301 callbackHashMap_.erase(callback);
302 callbackHashMapNotSetMute_.erase(callback);
303 for (auto &iter : muteCache_) {
304 auto it = iter.second.find(callback);
305 if (it != iter.second.end()) {
306 it = iter.second.erase(it);
307 SGLOGI("erase callback muteCache_ %{public}zu", iter.second.size());
308 continue;
309 }
310 }
311 }
312
ClearEventCache(const sptr<IRemoteObject> & remote)313 void AcquireDataSubscribeManager::CleanupTimer::ClearEventCache(const sptr<IRemoteObject> &remote)
314 {
315 std::lock_guard<std::mutex> lock(g_mutex);
316 SGLOGD("timer running");
317 if (g_subscriberInfoMap.count(remote) == 0) {
318 SGLOGI("not found callback");
319 return;
320 }
321 std::vector<SecurityCollector::Event> tmp = g_subscriberInfoMap.at(remote).events;
322 if (tmp.empty()) {
323 return;
324 }
325 auto proxy = iface_cast<IAcquireDataCallback>(remote);
326 if (proxy == nullptr) {
327 SGLOGE("proxy is null");
328 return;
329 }
330 auto task = [proxy, tmp] () {
331 proxy->OnNotify(tmp);
332 };
333 ffrt::submit(task);
334 g_subscriberInfoMap.at(remote).events.clear();
335 g_subscriberInfoMap.at(remote).eventsBuffSize = 0;
336 }
337
BatchUpload(sptr<IRemoteObject> obj,const std::vector<SecurityCollector::Event> & events)338 void AcquireDataSubscribeManager::BatchUpload(sptr<IRemoteObject> obj,
339 const std::vector<SecurityCollector::Event> &events)
340 {
341 auto proxy = iface_cast<IAcquireDataCallback>(obj);
342 if (proxy == nullptr) {
343 SGLOGI("proxy is null");
344 return;
345 }
346 auto task = [proxy, events] () {
347 proxy->OnNotify(events);
348 };
349 SGLOGD("upload event to subscribe");
350 ffrt::submit(task);
351 }
352
UploadEvent(const SecurityCollector::Event & event)353 void AcquireDataSubscribeManager::UploadEvent(const SecurityCollector::Event &event)
354 {
355 if (!DataFormat::CheckRiskContent(event.content)) {
356 SGLOGE("CheckRiskContent error");
357 return;
358 }
359 SecEvent secEvent {
360 .eventId = event.eventId,
361 .version = event.version,
362 .date = event.timestamp,
363 .content = event.content
364 };
365 auto task = [secEvent, event] () mutable {
366 int code = DatabaseManager::GetInstance().InsertEvent(USER_SOURCE, secEvent, event.eventSubscribes);
367 if (code != SUCCESS) {
368 SGLOGE("insert event error, %{public}d", code);
369 }
370 };
371 ffrt::submit(task);
372 }
373
BatchPublish(const SecurityCollector::Event & event)374 bool AcquireDataSubscribeManager::BatchPublish(const SecurityCollector::Event &event)
375 {
376 for (auto &it : g_subscriberInfoMap) {
377 for (const auto &i : it.second.subscribe) {
378 if (i.GetEvent().eventId != event.eventId) {
379 continue;
380 }
381 // has set mute, but this event not belong the sub, means the filter of this sub set has work
382 if (callbackHashMap_.count(it.first) != 0 &&
383 event.eventSubscribes.count(callbackHashMap_.at(it.first)) == 0) {
384 continue;
385 }
386 if (!ConfigDataManager::GetInstance().GetIsBatchUpload(i.GetEventGroup())) {
387 BatchUpload(it.first, {event});
388 continue;
389 }
390 SGLOGD("publish eventid=%{public}" PRId64, event.eventId);
391 for (auto iter : event.eventSubscribes) {
392 SGLOGD("publish eventSubscribes =%{public}s", iter.c_str());
393 }
394 it.second.events.emplace_back(event);
395 it.second.eventsBuffSize += sizeof(event);
396 SGLOGD("cache batch upload event to subscribe %{public}zu", it.second.eventsBuffSize);
397 if (it.second.eventsBuffSize >= MAX_CACHE_EVENT_SIZE) {
398 BatchUpload(it.first, it.second.events);
399 SGLOGI("upload events to batch subscribe, size is %{public}zu", it.second.eventsBuffSize);
400 it.second.events.clear();
401 it.second.eventsBuffSize = 0;
402 }
403 break;
404 }
405 }
406 return true;
407 }
408
OnChange(uint32_t optType,const SecEvent & events,const std::set<std::string> & eventSubscribes)409 void AcquireDataSubscribeManager::DbListener::OnChange(uint32_t optType, const SecEvent &events,
410 const std::set<std::string> &eventSubscribes)
411 {
412 std::lock_guard<std::mutex> lock(g_mutex);
413 SecurityCollector::Event event {
414 .eventId = events.eventId,
415 .version = events.version,
416 .content = events.content,
417 .timestamp = events.date,
418 .eventSubscribes = eventSubscribes
419 };
420 AcquireDataSubscribeManager::GetInstance().BatchPublish(event);
421 }
422
OnNotify(const SecurityCollector::Event & event)423 void AcquireDataSubscribeManager::CollectorListenner::OnNotify(const SecurityCollector::Event &event)
424 {
425 AcquireDataSubscribeManager::GetInstance().UploadEvent(event);
426 }
OnNotify(const SecurityCollector::Event & event)427 int32_t AcquireDataSubscribeManager::SecurityCollectorSubscriber::OnNotify(const SecurityCollector::Event &event)
428 {
429 AcquireDataSubscribeManager::GetInstance().UploadEvent(event);
430 return 0;
431 }
432
GetEventId()433 int64_t AcquireDataSubscribeManager::CollectorListenner::GetEventId()
434 {
435 return event_.eventId;
436 }
437
InsertSubscribeMute(const SecurityEventFilter & subscribeMute,const sptr<IRemoteObject> & callback,const std::string & sdkFlag)438 int AcquireDataSubscribeManager::InsertSubscribeMute(const SecurityEventFilter &subscribeMute,
439 const sptr<IRemoteObject> &callback, const std::string &sdkFlag)
440 {
441 std::lock_guard<std::mutex> lock(g_mutex);
442 SGLOGI("in AcquireDataSubscribeManager InsertSubscribeMute");
443 SecurityCollector::SecurityCollectorEventMuteFilter collectorFilter {};
444 SecurityGuard::EventMuteFilter sgFilter = subscribeMute.GetMuteFilter();
445 collectorFilter.eventId = sgFilter.eventId;
446 collectorFilter.mutes = sgFilter.mutes;
447 collectorFilter.type = static_cast<SecurityCollector::SecurityCollectorEventMuteType>(sgFilter.type);
448 collectorFilter.isSetMute = true;
449 EventCfg config {};
450 bool isSuccess = ConfigDataManager::GetInstance().GetEventConfig(collectorFilter.eventId, config);
451 if (!isSuccess) {
452 SGLOGE("GetEventConfig error");
453 return BAD_PARAM;
454 }
455 if (muteCache_[subscribeMute.GetMuteFilter().eventId][callback].size() >= MAX_FILTER_SIZE) {
456 SGLOGI("current callback eventid size err, eventId=%{public}" PRId64, collectorFilter.eventId);
457 return BAD_PARAM;
458 }
459
460 if (config.prog == "security_guard") {
461 if (eventToListenner_.count(sgFilter.eventId) == 0) {
462 SGLOGI("current collector not start eventId=%{public}" PRId64, sgFilter.eventId);
463 muteCache_[subscribeMute.GetMuteFilter().eventId][callback].emplace_back(collectorFilter);
464 callbackHashMapNotSetMute_[callback] = sdkFlag;
465 return SUCCESS;
466 }
467 if (!SecurityCollector::DataCollection::GetInstance().Mute(collectorFilter, sdkFlag)) {
468 SGLOGI("Mute SG failed, eventId=%{public}" PRId64, collectorFilter.eventId);
469 return FAILED;
470 }
471 callbackHashMap_[callback] = sdkFlag;
472 return SUCCESS;
473 }
474 if (scSubscribeMap_.count(sgFilter.eventId) == 0) {
475 SGLOGI("current sc collector not start eventId=%{public}" PRId64, sgFilter.eventId);
476 muteCache_[subscribeMute.GetMuteFilter().eventId][callback].emplace_back(collectorFilter);
477 callbackHashMapNotSetMute_[callback] = sdkFlag;
478 return SUCCESS;
479 }
480 int ret = SecurityCollector::CollectorManager::GetInstance().Mute(collectorFilter, sdkFlag);
481 if (ret != SUCCESS) {
482 SGLOGE("InsertSubscribeMute failed, ret=%{public}d", ret);
483 return ret;
484 }
485 callbackHashMap_[callback] = sdkFlag;
486 return SUCCESS;
487 }
488
RemoveSubscribeMute(const SecurityEventFilter & subscribeMute,const sptr<IRemoteObject> & callback,const std::string & sdkFlag)489 int AcquireDataSubscribeManager::RemoveSubscribeMute(const SecurityEventFilter &subscribeMute,
490 const sptr<IRemoteObject> &callback, const std::string &sdkFlag)
491 {
492 std::lock_guard<std::mutex> lock(g_mutex);
493 SGLOGI("in AcquireDataSubscribeManager RemoveSubscribeMute");
494 SecurityCollector::SecurityCollectorEventMuteFilter collectorFilter {};
495 SecurityGuard::EventMuteFilter sgFilter = subscribeMute.GetMuteFilter();
496 collectorFilter.eventId = sgFilter.eventId;
497 collectorFilter.mutes = sgFilter.mutes;
498 collectorFilter.type = static_cast<SecurityCollector::SecurityCollectorEventMuteType>(sgFilter.type);
499 collectorFilter.isSetMute = false;
500 EventCfg config {};
501 bool isSuccess = ConfigDataManager::GetInstance().GetEventConfig(collectorFilter.eventId, config);
502 if (!isSuccess) {
503 SGLOGE("GetEventConfig error");
504 return BAD_PARAM;
505 }
506 if (muteCache_[sgFilter.eventId][callback].size() >= MAX_FILTER_SIZE) {
507 SGLOGI("current callback eventid size err, eventId=%{public}" PRId64, collectorFilter.eventId);
508 return BAD_PARAM;
509 }
510
511 if (config.prog == "security_guard") {
512 if (eventToListenner_.count(sgFilter.eventId) == 0) {
513 SGLOGI("current collector not start eventId=%{public}" PRId64, sgFilter.eventId);
514 muteCache_[subscribeMute.GetMuteFilter().eventId][callback].emplace_back(collectorFilter);
515 callbackHashMapNotSetMute_[callback] = sdkFlag;
516 return SUCCESS;
517 }
518 if (!SecurityCollector::DataCollection::GetInstance().Unmute(collectorFilter, sdkFlag)) {
519 SGLOGI("Unmute SG failed, eventId=%{public}" PRId64, collectorFilter.eventId);
520 return FAILED;
521 }
522 return SUCCESS;
523 }
524 if (scSubscribeMap_.count(sgFilter.eventId) == 0) {
525 SGLOGI("current sc collector not start eventId=%{public}" PRId64, sgFilter.eventId);
526 muteCache_[subscribeMute.GetMuteFilter().eventId][callback].emplace_back(collectorFilter);
527 callbackHashMapNotSetMute_[callback] = sdkFlag;
528 return SUCCESS;
529 }
530 int ret = SecurityCollector::CollectorManager::GetInstance().Unmute(collectorFilter, sdkFlag);
531 if (ret != SUCCESS) {
532 SGLOGE("RemoveSubscribeMute failed, ret=%{public}d", ret);
533 return ret;
534 }
535 return SUCCESS;
536 }
537 }