1 /*
2 * Copyright (c) 2021-2024 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 "inner_common_event_manager.h"
17
18 #include "ces_inner_error_code.h"
19 #include "common_event_constant.h"
20 #include "common_event_record.h"
21 #include "common_event_sticky_manager.h"
22 #include "common_event_subscriber_manager.h"
23 #include "common_event_support.h"
24 #include "common_event_support_mapper.h"
25 #include "event_log_wrapper.h"
26 #include "event_report.h"
27 #include "hitrace_meter_adapter.h"
28 #include "ipc_skeleton.h"
29 #include "nlohmann/json.hpp"
30 #include "os_account_manager_helper.h"
31 #include "parameters.h"
32 #include "system_time.h"
33 #include "want.h"
34
35 namespace OHOS {
36 namespace EventFwk {
37 namespace {
38 const std::string NOTIFICATION_CES_CHECK_SA_PERMISSION = "notification.ces.check.sa.permission";
39 } // namespace
40
41 static const int32_t PUBLISH_SYS_EVENT_INTERVAL = 10; // 10s
42
InnerCommonEventManager()43 InnerCommonEventManager::InnerCommonEventManager() : controlPtr_(std::make_shared<CommonEventControlManager>()),
44 staticSubscriberManager_(std::make_shared<StaticSubscriberManager>())
45 {
46 supportCheckSaPermission_ = OHOS::system::GetParameter(NOTIFICATION_CES_CHECK_SA_PERMISSION, "false");
47 }
48
49 constexpr char HIDUMPER_HELP_MSG[] =
50 "Usage:dump <command> [options]\n"
51 "Description:\n"
52 " -h, --help list available commands\n"
53 " -a, --all dump the info of all events\n"
54 " -e, --event <name> dump the info of a specified event\n";
55
56 const std::unordered_map<std::string, char> HIDUMPER_CMD_MAP = {
57 { "--help", 'h'},
58 { "--all", 'a'},
59 { "--event", 'e'},
60 { "-h", 'h' },
61 { "-a", 'a' },
62 { "-e", 'e' },
63 };
64
65 const std::map<std::string, std::string> EVENT_COUNT_DISALLOW = {
66 { CommonEventSupport::COMMON_EVENT_TIME_TICK, "usual.event.TIME_TICK" },
67 };
68
69 constexpr size_t HIDUMP_OPTION_MAX_SIZE = 2;
70
PublishCommonEvent(const CommonEventData & data,const CommonEventPublishInfo & publishInfo,const sptr<IRemoteObject> & commonEventListener,const struct tm & recordTime,const pid_t & pid,const uid_t & uid,const Security::AccessToken::AccessTokenID & callerToken,const int32_t & userId,const std::string & bundleName,const sptr<IRemoteObject> & service)71 bool InnerCommonEventManager::PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
72 const sptr<IRemoteObject> &commonEventListener, const struct tm &recordTime, const pid_t &pid, const uid_t &uid,
73 const Security::AccessToken::AccessTokenID &callerToken, const int32_t &userId, const std::string &bundleName,
74 const sptr<IRemoteObject> &service)
75 {
76 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
77 EVENT_LOGD("enter %{public}s(pid = %{public}d, uid = %{public}d), event = %{public}s to userId = %{public}d",
78 bundleName.c_str(), pid, uid, data.GetWant().GetAction().c_str(), userId);
79
80 if (data.GetWant().GetAction().empty()) {
81 EVENT_LOGE("the commonEventdata action is null");
82 return false;
83 }
84
85 if ((!publishInfo.IsOrdered()) && (commonEventListener != nullptr)) {
86 EVENT_LOGE("When publishing unordered events, the subscriber object is not required.");
87 return false;
88 }
89
90 std::string action = data.GetWant().GetAction();
91 bool isSystemEvent = DelayedSingleton<CommonEventSupport>::GetInstance()->IsSystemEvent(action);
92 int32_t user = userId;
93 EventComeFrom comeFrom;
94 if (!CheckUserId(pid, uid, callerToken, comeFrom, user)) {
95 SendPublishHiSysEvent(user, bundleName, pid, uid, data.GetWant().GetAction(), false);
96 return false;
97 }
98
99 if (isSystemEvent) {
100 EVENT_LOGD("System common event");
101 if (!comeFrom.isSystemApp && !comeFrom.isSubsystem && !comeFrom.isCemShell) {
102 EVENT_LOGE(
103 "No permission to send a system common event from %{public}s(pid = %{public}d, uid = %{public}d)"
104 ", userId = %{public}d", bundleName.c_str(), pid, uid, userId);
105 SendPublishHiSysEvent(user, bundleName, pid, uid, data.GetWant().GetAction(), false);
106 return false;
107 }
108 }
109
110 if (staticSubscriberManager_ != nullptr) {
111 staticSubscriberManager_->PublishCommonEvent(data, publishInfo, callerToken, user, service, bundleName);
112 }
113
114 CommonEventRecord eventRecord;
115 eventRecord.commonEventData = std::make_shared<CommonEventData>(data);
116 eventRecord.publishInfo = std::make_shared<CommonEventPublishInfo>(publishInfo);
117 eventRecord.recordTime = recordTime;
118 eventRecord.eventRecordInfo.pid = pid;
119 eventRecord.eventRecordInfo.uid = uid;
120 eventRecord.eventRecordInfo.callerToken = callerToken;
121 eventRecord.userId = user;
122 eventRecord.eventRecordInfo.bundleName = bundleName;
123 eventRecord.eventRecordInfo.isSubsystem = comeFrom.isSubsystem;
124 eventRecord.eventRecordInfo.isSystemApp = (comeFrom.isSystemApp || comeFrom.isCemShell);
125 eventRecord.eventRecordInfo.isProxy = comeFrom.isProxy;
126 eventRecord.isSystemEvent = isSystemEvent;
127
128 if (publishInfo.IsSticky()) {
129 if (!ProcessStickyEvent(eventRecord)) {
130 SendPublishHiSysEvent(user, bundleName, pid, uid, data.GetWant().GetAction(), false);
131 return false;
132 }
133 }
134
135 if (!controlPtr_) {
136 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
137 SendPublishHiSysEvent(user, bundleName, pid, uid, data.GetWant().GetAction(), false);
138 return false;
139 }
140 controlPtr_->PublishCommonEvent(eventRecord, commonEventListener);
141
142 std::string mappedSupport = "";
143 if (DelayedSingleton<CommonEventSupportMapper>::GetInstance()->GetMappedSupport(
144 eventRecord.commonEventData->GetWant().GetAction(), mappedSupport)) {
145 Want want = eventRecord.commonEventData->GetWant();
146 want.SetAction(mappedSupport);
147 CommonEventRecord mappedEventRecord = eventRecord;
148 mappedEventRecord.commonEventData->SetWant(want);
149 controlPtr_->PublishCommonEvent(mappedEventRecord, commonEventListener);
150 }
151
152 if (time(nullptr) - sysEventTime >= PUBLISH_SYS_EVENT_INTERVAL &&
153 EVENT_COUNT_DISALLOW.find(data.GetWant().GetAction().c_str()) == EVENT_COUNT_DISALLOW.end()) {
154 SendPublishHiSysEvent(user, bundleName, pid, uid, data.GetWant().GetAction(), true);
155 sysEventTime = time(nullptr);
156 }
157
158 return true;
159 }
160
SubscribeCommonEvent(const CommonEventSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & commonEventListener,const struct tm & recordTime,const pid_t & pid,const uid_t & uid,const Security::AccessToken::AccessTokenID & callerToken,const std::string & bundleName)161 bool InnerCommonEventManager::SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
162 const sptr<IRemoteObject> &commonEventListener, const struct tm &recordTime, const pid_t &pid, const uid_t &uid,
163 const Security::AccessToken::AccessTokenID &callerToken, const std::string &bundleName)
164 {
165 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
166 EVENT_LOGD("enter %{public}s(pid = %{public}d, uid = %{public}d, userId = %{public}d)",
167 bundleName.c_str(), pid, uid, subscribeInfo.GetUserId());
168
169 if (subscribeInfo.GetMatchingSkills().CountEvent() == 0) {
170 EVENT_LOGE("the subscriber has no event");
171 return false;
172 }
173 if (commonEventListener == nullptr) {
174 EVENT_LOGE("InnerCommonEventManager::SubscribeCommonEvent:commonEventListener == nullptr");
175 return false;
176 }
177
178 CommonEventSubscribeInfo subscribeInfo_(subscribeInfo);
179 int32_t userId = subscribeInfo_.GetUserId();
180 EventComeFrom comeFrom;
181 if (!CheckUserId(pid, uid, callerToken, comeFrom, userId)) {
182 return false;
183 }
184 subscribeInfo_.SetUserId(userId);
185
186 std::shared_ptr<CommonEventSubscribeInfo> sp = std::make_shared<CommonEventSubscribeInfo>(subscribeInfo_);
187
188 // create EventRecordInfo here
189 EventRecordInfo eventRecordInfo;
190 eventRecordInfo.pid = pid;
191 eventRecordInfo.uid = uid;
192 eventRecordInfo.callerToken = callerToken;
193 eventRecordInfo.bundleName = bundleName;
194 eventRecordInfo.isSubsystem = comeFrom.isSubsystem;
195 eventRecordInfo.isSystemApp = comeFrom.isSystemApp;
196 eventRecordInfo.isProxy = comeFrom.isProxy;
197
198 // generate subscriber id : pid_uid_subCount_time
199 int64_t now = SystemTime::GetNowSysTime();
200 std::string subId = std::to_string(pid) + "_" + std::to_string(uid) + "_" +
201 std::to_string(subCount.load()) + "_" + std::to_string(now);
202 subCount.fetch_add(1);
203 eventRecordInfo.subId = subId;
204 EVENT_LOGI("SubscribeCommonEvent %{public}s(pid = %{public}d, uid = %{public}d, "
205 "userId = %{public}d, subId = %{public}s)", bundleName.c_str(), pid, uid,
206 subscribeInfo.GetUserId(), subId.c_str());
207
208 auto record = DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->InsertSubscriber(
209 sp, commonEventListener, recordTime, eventRecordInfo);
210
211 PublishStickyEvent(sp, record);
212
213 SendSubscribeHiSysEvent(userId, bundleName, pid, uid, subscribeInfo.GetMatchingSkills().GetEvents());
214 return true;
215 };
216
UnsubscribeCommonEvent(const sptr<IRemoteObject> & commonEventListener)217 bool InnerCommonEventManager::UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener)
218 {
219 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
220 EVENT_LOGD("enter");
221
222 if (commonEventListener == nullptr) {
223 EVENT_LOGE("commonEventListener == nullptr");
224 return false;
225 }
226
227 if (!controlPtr_) {
228 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
229 return false;
230 }
231
232 std::shared_ptr<OrderedEventRecord> sp = controlPtr_->GetMatchingOrderedReceiver(commonEventListener);
233 if (sp) {
234 EVENT_LOGD("Unsubscribe the subscriber who is waiting to receive finish feedback");
235 int32_t code = sp->commonEventData->GetCode();
236 std::string data = sp->commonEventData->GetData();
237 controlPtr_->FinishReceiverAction(sp, code, data, sp->resultAbort);
238 }
239
240 SendUnSubscribeHiSysEvent(commonEventListener);
241 DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->RemoveSubscriber(commonEventListener);
242
243 return true;
244 }
245
GetStickyCommonEvent(const std::string & event,CommonEventData & eventData)246 bool InnerCommonEventManager::GetStickyCommonEvent(const std::string &event, CommonEventData &eventData)
247 {
248 EVENT_LOGD("enter");
249
250 return DelayedSingleton<CommonEventStickyManager>::GetInstance()->GetStickyCommonEvent(event, eventData);
251 }
252
DumpState(const uint8_t & dumpType,const std::string & event,const int32_t & userId,std::vector<std::string> & state)253 void InnerCommonEventManager::DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
254 std::vector<std::string> &state)
255 {
256 EVENT_LOGD("enter");
257
258 switch (dumpType) {
259 case DumpEventType::SUBSCRIBER: {
260 DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->DumpState(event, userId, state);
261 break;
262 }
263 case DumpEventType::STICKY: {
264 DelayedSingleton<CommonEventStickyManager>::GetInstance()->DumpState(event, userId, state);
265 break;
266 }
267 case DumpEventType::PENDING: {
268 if (controlPtr_) {
269 controlPtr_->DumpState(event, userId, state);
270 }
271 break;
272 }
273 case DumpEventType::HISTORY: {
274 if (controlPtr_) {
275 controlPtr_->DumpHistoryState(event, userId, state);
276 }
277 break;
278 }
279 default: {
280 DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->DumpState(event, userId, state);
281 DelayedSingleton<CommonEventStickyManager>::GetInstance()->DumpState(event, userId, state);
282 if (controlPtr_) {
283 controlPtr_->DumpState(event, userId, state);
284 controlPtr_->DumpHistoryState(event, userId, state);
285 }
286 break;
287 }
288 }
289
290 if (!controlPtr_) {
291 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
292 }
293 }
294
FinishReceiver(const sptr<IRemoteObject> & proxy,const int32_t & code,const std::string & receiverData,const bool & abortEvent)295 void InnerCommonEventManager::FinishReceiver(
296 const sptr<IRemoteObject> &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent)
297 {
298 EVENT_LOGD("enter");
299
300 if (!controlPtr_) {
301 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
302 return;
303 }
304
305 std::shared_ptr<OrderedEventRecord> sp = controlPtr_->GetMatchingOrderedReceiver(proxy);
306 if (sp) {
307 controlPtr_->FinishReceiverAction(sp, code, receiverData, abortEvent);
308 }
309
310 return;
311 }
312
Freeze(const uid_t & uid)313 void InnerCommonEventManager::Freeze(const uid_t &uid)
314 {
315 EVENT_LOGD("enter");
316 DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->UpdateFreezeInfo(
317 uid, true, SystemTime::GetNowSysTime());
318 }
319
Unfreeze(const uid_t & uid)320 void InnerCommonEventManager::Unfreeze(const uid_t &uid)
321 {
322 EVENT_LOGD("enter");
323 DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->UpdateFreezeInfo(uid, false);
324 if (!controlPtr_) {
325 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
326 return;
327 }
328 controlPtr_->PublishFreezeCommonEvent(uid);
329 }
330
UnfreezeAll()331 void InnerCommonEventManager::UnfreezeAll()
332 {
333 EVENT_LOGD("enter");
334 DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->UpdateAllFreezeInfos(false);
335 if (!controlPtr_) {
336 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
337 return;
338 }
339 controlPtr_->PublishAllFreezeCommonEvents();
340 }
341
ProcessStickyEvent(const CommonEventRecord & record)342 bool InnerCommonEventManager::ProcessStickyEvent(const CommonEventRecord &record)
343 {
344 EVENT_LOGD("enter");
345 const std::string permission = "ohos.permission.COMMONEVENT_STICKY";
346 bool result = AccessTokenHelper::VerifyAccessToken(record.eventRecordInfo.callerToken, permission);
347 // Only subsystems and system apps with permissions can publish sticky common events
348 if ((result && record.eventRecordInfo.isSystemApp) ||
349 (!record.eventRecordInfo.isProxy && record.eventRecordInfo.isSubsystem)) {
350 DelayedSingleton<CommonEventStickyManager>::GetInstance()->UpdateStickyEvent(record);
351 return true;
352 } else {
353 EVENT_LOGE("No permission to send a sticky common event from %{public}s (pid = %{public}d, uid = %{public}d)",
354 record.eventRecordInfo.bundleName.c_str(), record.eventRecordInfo.pid, record.eventRecordInfo.uid);
355 return false;
356 }
357 }
358
CheckUserId(const pid_t & pid,const uid_t & uid,const Security::AccessToken::AccessTokenID & callerToken,EventComeFrom & comeFrom,int32_t & userId)359 bool InnerCommonEventManager::CheckUserId(const pid_t &pid, const uid_t &uid,
360 const Security::AccessToken::AccessTokenID &callerToken, EventComeFrom &comeFrom, int32_t &userId)
361 {
362 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
363 EVENT_LOGD("enter");
364
365 if (userId < UNDEFINED_USER) {
366 EVENT_LOGE("Invalid User ID %{public}d", userId);
367 return false;
368 }
369
370 comeFrom.isSubsystem = AccessTokenHelper::VerifyNativeToken(callerToken);
371
372 if (!comeFrom.isSubsystem || supportCheckSaPermission_.compare("true") == 0) {
373 if (AccessTokenHelper::VerifyShellToken(callerToken)) {
374 const std::string permission = "ohos.permission.PUBLISH_SYSTEM_COMMON_EVENT";
375 comeFrom.isCemShell = AccessTokenHelper::VerifyAccessToken(callerToken, permission);
376 } else {
377 comeFrom.isSystemApp = DelayedSingleton<BundleManagerHelper>::GetInstance()->CheckIsSystemAppByUid(uid);
378 }
379 }
380 comeFrom.isProxy = pid == UNDEFINED_PID;
381 if ((comeFrom.isSystemApp || comeFrom.isSubsystem || comeFrom.isCemShell) && !comeFrom.isProxy) {
382 if (userId == CURRENT_USER) {
383 DelayedSingleton<OsAccountManagerHelper>::GetInstance()->GetOsAccountLocalIdFromUid(uid, userId);
384 } else if (userId == UNDEFINED_USER) {
385 userId = ALL_USER;
386 }
387 } else {
388 if (userId == UNDEFINED_USER) {
389 DelayedSingleton<OsAccountManagerHelper>::GetInstance()->GetOsAccountLocalIdFromUid(uid, userId);
390 } else {
391 EVENT_LOGE("No permission to subscribe or send a common event to another user from uid = %{public}d", uid);
392 return false;
393 }
394 }
395
396 return true;
397 }
398
PublishStickyEvent(const std::shared_ptr<CommonEventSubscribeInfo> & sp,const std::shared_ptr<EventSubscriberRecord> & subscriberRecord)399 bool InnerCommonEventManager::PublishStickyEvent(
400 const std::shared_ptr<CommonEventSubscribeInfo> &sp, const std::shared_ptr<EventSubscriberRecord> &subscriberRecord)
401 {
402 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
403 EVENT_LOGD("enter");
404
405 if (!sp) {
406 EVENT_LOGE("sp is null");
407 return false;
408 }
409
410 if (!subscriberRecord) {
411 EVENT_LOGE("subscriberRecord is null");
412 return false;
413 }
414
415 std::vector<std::shared_ptr<CommonEventRecord>> commonEventRecords;
416 if (DelayedSingleton<CommonEventStickyManager>::GetInstance()->FindStickyEvents(sp, commonEventRecords)) {
417 return false;
418 }
419
420 for (auto commonEventRecord : commonEventRecords) {
421 if (!commonEventRecord) {
422 EVENT_LOGW("commonEventRecord is nullptr and get next");
423 continue;
424 }
425 EVENT_LOGD("publish sticky event : %{public}s",
426 commonEventRecord->commonEventData->GetWant().GetAction().c_str());
427
428 if (!commonEventRecord->publishInfo->GetBundleName().empty() &&
429 commonEventRecord->publishInfo->GetBundleName() != subscriberRecord->eventRecordInfo.bundleName) {
430 EVENT_LOGW("commonEventRecord assigned to bundleName[%{public}s]",
431 commonEventRecord->publishInfo->GetBundleName().c_str());
432 continue;
433 }
434
435 commonEventRecord->publishInfo->SetOrdered(false);
436 if (!controlPtr_) {
437 EVENT_LOGE("CommonEventControlManager ptr is nullptr");
438 return false;
439 }
440 controlPtr_->PublishStickyCommonEvent(*commonEventRecord, subscriberRecord);
441 }
442
443 return true;
444 }
445
HiDump(const std::vector<std::u16string> & args,std::string & result)446 void InnerCommonEventManager::HiDump(const std::vector<std::u16string> &args, std::string &result)
447 {
448 if (args.size() == 0 || args.size() > HIDUMP_OPTION_MAX_SIZE) {
449 result = "error: unknown option.";
450 return;
451 }
452 std::string cmd = Str16ToStr8(args[0]);
453 if (HIDUMPER_CMD_MAP.find(cmd) == HIDUMPER_CMD_MAP.end()) {
454 result = "error: unknown option.";
455 return;
456 }
457 std::string event;
458 if (args.size() == HIDUMP_OPTION_MAX_SIZE) {
459 event = Str16ToStr8(args[1]);
460 }
461 char cmdValue = HIDUMPER_CMD_MAP.find(cmd)->second;
462 switch (cmdValue) {
463 case 'h' :
464 result = HIDUMPER_HELP_MSG;
465 return;
466 case 'a' :
467 event = "";
468 break;
469 case 'e' :
470 if (event.empty()) {
471 result = "error: request a event value.";
472 return;
473 }
474 break;
475 default:
476 break;
477 }
478 std::vector<std::string> records;
479 DumpState(DumpEventType::ALL, event, ALL_USER, records);
480 for (const auto &record : records) {
481 result.append(record).append("\n");
482 }
483 }
484
SendSubscribeHiSysEvent(int32_t userId,const std::string & subscriberName,int32_t pid,int32_t uid,const std::vector<std::string> & events)485 void InnerCommonEventManager::SendSubscribeHiSysEvent(int32_t userId, const std::string &subscriberName, int32_t pid,
486 int32_t uid, const std::vector<std::string> &events)
487 {
488 EventInfo eventInfo;
489 eventInfo.userId = userId;
490 eventInfo.subscriberName = subscriberName;
491 eventInfo.pid = pid;
492 eventInfo.uid = uid;
493 eventInfo.eventName = std::accumulate(events.begin(), events.end(), std::string(""),
494 [events](std::string eventName, const std::string &str) {
495 return (str == events.front()) ? (eventName + str) : (eventName + "," + str);
496 });
497 EventReport::SendHiSysEvent(SUBSCRIBE, eventInfo);
498 }
499
SendUnSubscribeHiSysEvent(const sptr<IRemoteObject> & commonEventListener)500 void InnerCommonEventManager::SendUnSubscribeHiSysEvent(const sptr<IRemoteObject> &commonEventListener)
501 {
502 auto subscriberRecord = DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->GetSubscriberRecord(
503 commonEventListener);
504 if (subscriberRecord == nullptr) {
505 return;
506 }
507
508 EventInfo eventInfo;
509 if (subscriberRecord->eventSubscribeInfo != nullptr) {
510 eventInfo.userId = subscriberRecord->eventSubscribeInfo->GetUserId();
511 std::vector<std::string> events = subscriberRecord->eventSubscribeInfo->GetMatchingSkills().GetEvents();
512 eventInfo.eventName = std::accumulate(events.begin(), events.end(), std::string(""),
513 [events](std::string eventName, const std::string &str) {
514 return (str == events.front()) ? (eventName + str) : (eventName + "," + str);
515 });
516 }
517 eventInfo.subscriberName = subscriberRecord->eventRecordInfo.bundleName;
518 eventInfo.pid = subscriberRecord->eventRecordInfo.pid;
519 eventInfo.uid = static_cast<int32_t>(subscriberRecord->eventRecordInfo.uid);
520 EventReport::SendHiSysEvent(UNSUBSCRIBE, eventInfo);
521 }
522
SendPublishHiSysEvent(int32_t userId,const std::string & publisherName,int32_t pid,int32_t uid,const std::string & event,bool succeed)523 void InnerCommonEventManager::SendPublishHiSysEvent(int32_t userId, const std::string &publisherName, int32_t pid,
524 int32_t uid, const std::string &event, bool succeed)
525 {
526 EventInfo eventInfo;
527 eventInfo.userId = userId;
528 eventInfo.publisherName = publisherName;
529 eventInfo.pid = pid;
530 eventInfo.uid = uid;
531 eventInfo.eventName = event;
532
533 if (succeed) {
534 EventReport::SendHiSysEvent(PUBLISH, eventInfo);
535 } else {
536 EventReport::SendHiSysEvent(PUBLISH_ERROR, eventInfo);
537 }
538 }
539
RemoveStickyCommonEvent(const std::string & event,uint32_t callerUid)540 int32_t InnerCommonEventManager::RemoveStickyCommonEvent(const std::string &event, uint32_t callerUid)
541 {
542 return DelayedSingleton<CommonEventStickyManager>::GetInstance()->RemoveStickyCommonEvent(event, callerUid);
543 }
544
SetStaticSubscriberState(bool enable)545 int32_t InnerCommonEventManager::SetStaticSubscriberState(bool enable)
546 {
547 if (staticSubscriberManager_ != nullptr) {
548 return staticSubscriberManager_->SetStaticSubscriberState(enable);
549 }
550 return Notification::ERR_NOTIFICATION_CESM_ERROR;
551 }
552
SetStaticSubscriberState(const std::vector<std::string> & events,bool enable)553 int32_t InnerCommonEventManager::SetStaticSubscriberState(const std::vector<std::string> &events, bool enable)
554 {
555 if (staticSubscriberManager_ != nullptr) {
556 return staticSubscriberManager_->SetStaticSubscriberState(events, enable);
557 }
558 return Notification::ERR_NOTIFICATION_CESM_ERROR;
559 }
560 } // namespace EventFwk
561 } // namespace OHOS
562