• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "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     auto record = DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->InsertSubscriber(
199         sp, commonEventListener, recordTime, eventRecordInfo);
200 
201     PublishStickyEvent(sp, record);
202 
203     SendSubscribeHiSysEvent(userId, bundleName, pid, uid, subscribeInfo.GetMatchingSkills().GetEvents());
204     return true;
205 };
206 
UnsubscribeCommonEvent(const sptr<IRemoteObject> & commonEventListener)207 bool InnerCommonEventManager::UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener)
208 {
209     HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
210     EVENT_LOGD("enter");
211 
212     if (commonEventListener == nullptr) {
213         EVENT_LOGE("commonEventListener == nullptr");
214         return false;
215     }
216 
217     if (!controlPtr_) {
218         EVENT_LOGE("CommonEventControlManager ptr is nullptr");
219         return false;
220     }
221 
222     std::shared_ptr<OrderedEventRecord> sp = controlPtr_->GetMatchingOrderedReceiver(commonEventListener);
223     if (sp) {
224         EVENT_LOGD("Unsubscribe the subscriber who is waiting to receive finish feedback");
225         int32_t code = sp->commonEventData->GetCode();
226         std::string data = sp->commonEventData->GetData();
227         controlPtr_->FinishReceiverAction(sp, code, data, sp->resultAbort);
228     }
229 
230     SendUnSubscribeHiSysEvent(commonEventListener);
231     DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->RemoveSubscriber(commonEventListener);
232 
233     return true;
234 }
235 
GetStickyCommonEvent(const std::string & event,CommonEventData & eventData)236 bool InnerCommonEventManager::GetStickyCommonEvent(const std::string &event, CommonEventData &eventData)
237 {
238     EVENT_LOGD("enter");
239 
240     return DelayedSingleton<CommonEventStickyManager>::GetInstance()->GetStickyCommonEvent(event, eventData);
241 }
242 
DumpState(const uint8_t & dumpType,const std::string & event,const int32_t & userId,std::vector<std::string> & state)243 void InnerCommonEventManager::DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
244     std::vector<std::string> &state)
245 {
246     EVENT_LOGD("enter");
247 
248     switch (dumpType) {
249         case DumpEventType::SUBSCRIBER: {
250             DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->DumpState(event, userId, state);
251             break;
252         }
253         case DumpEventType::STICKY: {
254             DelayedSingleton<CommonEventStickyManager>::GetInstance()->DumpState(event, userId, state);
255             break;
256         }
257         case DumpEventType::PENDING: {
258             if (controlPtr_) {
259                 controlPtr_->DumpState(event, userId, state);
260             }
261             break;
262         }
263         case DumpEventType::HISTORY: {
264             if (controlPtr_) {
265                 controlPtr_->DumpHistoryState(event, userId, state);
266             }
267             break;
268         }
269         default: {
270             DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->DumpState(event, userId, state);
271             DelayedSingleton<CommonEventStickyManager>::GetInstance()->DumpState(event, userId, state);
272             if (controlPtr_) {
273                 controlPtr_->DumpState(event, userId, state);
274                 controlPtr_->DumpHistoryState(event, userId, state);
275             }
276             break;
277         }
278     }
279 
280     if (!controlPtr_) {
281         EVENT_LOGE("CommonEventControlManager ptr is nullptr");
282     }
283 }
284 
FinishReceiver(const sptr<IRemoteObject> & proxy,const int32_t & code,const std::string & receiverData,const bool & abortEvent)285 void InnerCommonEventManager::FinishReceiver(
286     const sptr<IRemoteObject> &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent)
287 {
288     EVENT_LOGD("enter");
289 
290     if (!controlPtr_) {
291         EVENT_LOGE("CommonEventControlManager ptr is nullptr");
292         return;
293     }
294 
295     std::shared_ptr<OrderedEventRecord> sp = controlPtr_->GetMatchingOrderedReceiver(proxy);
296     if (sp) {
297         controlPtr_->FinishReceiverAction(sp, code, receiverData, abortEvent);
298     }
299 
300     return;
301 }
302 
Freeze(const uid_t & uid)303 void InnerCommonEventManager::Freeze(const uid_t &uid)
304 {
305     EVENT_LOGD("enter");
306     DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->UpdateFreezeInfo(
307         uid, true, SystemTime::GetNowSysTime());
308 }
309 
Unfreeze(const uid_t & uid)310 void InnerCommonEventManager::Unfreeze(const uid_t &uid)
311 {
312     EVENT_LOGD("enter");
313     DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->UpdateFreezeInfo(uid, false);
314     if (!controlPtr_) {
315         EVENT_LOGE("CommonEventControlManager ptr is nullptr");
316         return;
317     }
318     controlPtr_->PublishFreezeCommonEvent(uid);
319 }
320 
UnfreezeAll()321 void InnerCommonEventManager::UnfreezeAll()
322 {
323     EVENT_LOGD("enter");
324     DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->UpdateAllFreezeInfos(false);
325     if (!controlPtr_) {
326         EVENT_LOGE("CommonEventControlManager ptr is nullptr");
327         return;
328     }
329     controlPtr_->PublishAllFreezeCommonEvents();
330 }
331 
ProcessStickyEvent(const CommonEventRecord & record)332 bool InnerCommonEventManager::ProcessStickyEvent(const CommonEventRecord &record)
333 {
334     EVENT_LOGD("enter");
335     const std::string permission = "ohos.permission.COMMONEVENT_STICKY";
336     bool result = AccessTokenHelper::VerifyAccessToken(record.eventRecordInfo.callerToken, permission);
337     // Only subsystems and system apps with permissions can publish sticky common events
338     if ((result && record.eventRecordInfo.isSystemApp) ||
339         (!record.eventRecordInfo.isProxy && record.eventRecordInfo.isSubsystem)) {
340         DelayedSingleton<CommonEventStickyManager>::GetInstance()->UpdateStickyEvent(record);
341         return true;
342     } else {
343         EVENT_LOGE("No permission to send a sticky common event from %{public}s (pid = %{public}d, uid = %{public}d)",
344             record.eventRecordInfo.bundleName.c_str(), record.eventRecordInfo.pid, record.eventRecordInfo.uid);
345         return false;
346     }
347 }
348 
CheckUserId(const pid_t & pid,const uid_t & uid,const Security::AccessToken::AccessTokenID & callerToken,EventComeFrom & comeFrom,int32_t & userId)349 bool InnerCommonEventManager::CheckUserId(const pid_t &pid, const uid_t &uid,
350     const Security::AccessToken::AccessTokenID &callerToken, EventComeFrom &comeFrom, int32_t &userId)
351 {
352     HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
353     EVENT_LOGD("enter");
354 
355     if (userId < UNDEFINED_USER) {
356         EVENT_LOGE("Invalid User ID %{public}d", userId);
357         return false;
358     }
359 
360     comeFrom.isSubsystem = AccessTokenHelper::VerifyNativeToken(callerToken);
361 
362     if (!comeFrom.isSubsystem || supportCheckSaPermission_.compare("true") == 0) {
363         if (AccessTokenHelper::VerifyShellToken(callerToken)) {
364             const std::string permission = "ohos.permission.PUBLISH_SYSTEM_COMMON_EVENT";
365             comeFrom.isCemShell = AccessTokenHelper::VerifyAccessToken(callerToken, permission);
366         } else {
367             comeFrom.isSystemApp = DelayedSingleton<BundleManagerHelper>::GetInstance()->CheckIsSystemAppByUid(uid);
368         }
369     }
370     comeFrom.isProxy = pid == UNDEFINED_PID;
371     if ((comeFrom.isSystemApp || comeFrom.isSubsystem || comeFrom.isCemShell) && !comeFrom.isProxy) {
372         if (userId == CURRENT_USER) {
373             DelayedSingleton<OsAccountManagerHelper>::GetInstance()->GetOsAccountLocalIdFromUid(uid, userId);
374         } else if (userId == UNDEFINED_USER) {
375             userId = ALL_USER;
376         }
377     } else {
378         if (userId == UNDEFINED_USER) {
379             DelayedSingleton<OsAccountManagerHelper>::GetInstance()->GetOsAccountLocalIdFromUid(uid, userId);
380         } else {
381             EVENT_LOGE("No permission to subscribe or send a common event to another user from uid = %{public}d", uid);
382             return false;
383         }
384     }
385 
386     return true;
387 }
388 
PublishStickyEvent(const std::shared_ptr<CommonEventSubscribeInfo> & sp,const std::shared_ptr<EventSubscriberRecord> & subscriberRecord)389 bool InnerCommonEventManager::PublishStickyEvent(
390     const std::shared_ptr<CommonEventSubscribeInfo> &sp, const std::shared_ptr<EventSubscriberRecord> &subscriberRecord)
391 {
392     HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
393     EVENT_LOGD("enter");
394 
395     if (!sp) {
396         EVENT_LOGE("sp is null");
397         return false;
398     }
399 
400     if (!subscriberRecord) {
401         EVENT_LOGE("subscriberRecord is null");
402         return false;
403     }
404 
405     std::vector<std::shared_ptr<CommonEventRecord>> commonEventRecords;
406     if (DelayedSingleton<CommonEventStickyManager>::GetInstance()->FindStickyEvents(sp, commonEventRecords)) {
407         return false;
408     }
409 
410     for (auto commonEventRecord : commonEventRecords) {
411         if (!commonEventRecord) {
412             EVENT_LOGW("commonEventRecord is nullptr and get next");
413             continue;
414         }
415         EVENT_LOGD("publish sticky event : %{public}s",
416             commonEventRecord->commonEventData->GetWant().GetAction().c_str());
417 
418         if (!commonEventRecord->publishInfo->GetBundleName().empty() &&
419             commonEventRecord->publishInfo->GetBundleName() != subscriberRecord->eventRecordInfo.bundleName) {
420             EVENT_LOGW("commonEventRecord assigned to bundleName[%{public}s]",
421                 commonEventRecord->publishInfo->GetBundleName().c_str());
422             continue;
423         }
424 
425         commonEventRecord->publishInfo->SetOrdered(false);
426         if (!controlPtr_) {
427             EVENT_LOGE("CommonEventControlManager ptr is nullptr");
428             return false;
429         }
430         controlPtr_->PublishStickyCommonEvent(*commonEventRecord, subscriberRecord);
431     }
432 
433     return true;
434 }
435 
HiDump(const std::vector<std::u16string> & args,std::string & result)436 void InnerCommonEventManager::HiDump(const std::vector<std::u16string> &args, std::string &result)
437 {
438     if (args.size() == 0 || args.size() > HIDUMP_OPTION_MAX_SIZE) {
439         result = "error: unknown option.";
440         return;
441     }
442     std::string cmd = Str16ToStr8(args[0]);
443     if (HIDUMPER_CMD_MAP.find(cmd) == HIDUMPER_CMD_MAP.end()) {
444         result = "error: unknown option.";
445         return;
446     }
447     std::string event;
448     if (args.size() == HIDUMP_OPTION_MAX_SIZE) {
449         event = Str16ToStr8(args[1]);
450     }
451     char cmdValue = HIDUMPER_CMD_MAP.find(cmd)->second;
452     switch (cmdValue) {
453         case 'h' :
454             result = HIDUMPER_HELP_MSG;
455             return;
456         case 'a' :
457             event = "";
458             break;
459         case 'e' :
460             if (event.empty()) {
461                 result = "error: request a event value.";
462                 return;
463             }
464             break;
465         default:
466             break;
467     }
468     std::vector<std::string> records;
469     DumpState(DumpEventType::ALL, event, ALL_USER, records);
470     for (const auto &record : records) {
471         result.append(record).append("\n");
472     }
473 }
474 
SendSubscribeHiSysEvent(int32_t userId,const std::string & subscriberName,int32_t pid,int32_t uid,const std::vector<std::string> & events)475 void InnerCommonEventManager::SendSubscribeHiSysEvent(int32_t userId, const std::string &subscriberName, int32_t pid,
476     int32_t uid, const std::vector<std::string> &events)
477 {
478     EventInfo eventInfo;
479     eventInfo.userId = userId;
480     eventInfo.subscriberName = subscriberName;
481     eventInfo.pid = pid;
482     eventInfo.uid = uid;
483     eventInfo.eventName = std::accumulate(events.begin(), events.end(), std::string(""),
484         [events](std::string eventName, const std::string &str) {
485             return (str == events.front()) ? (eventName + str) : (eventName + "," + str);
486         });
487     EventReport::SendHiSysEvent(SUBSCRIBE, eventInfo);
488 }
489 
SendUnSubscribeHiSysEvent(const sptr<IRemoteObject> & commonEventListener)490 void InnerCommonEventManager::SendUnSubscribeHiSysEvent(const sptr<IRemoteObject> &commonEventListener)
491 {
492     auto subscriberRecord = DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->GetSubscriberRecord(
493         commonEventListener);
494     if (subscriberRecord == nullptr) {
495         return;
496     }
497 
498     EventInfo eventInfo;
499     if (subscriberRecord->eventSubscribeInfo != nullptr) {
500         eventInfo.userId = subscriberRecord->eventSubscribeInfo->GetUserId();
501         std::vector<std::string> events = subscriberRecord->eventSubscribeInfo->GetMatchingSkills().GetEvents();
502         eventInfo.eventName = std::accumulate(events.begin(), events.end(), std::string(""),
503             [events](std::string eventName, const std::string &str) {
504                 return (str == events.front()) ? (eventName + str) : (eventName + "," + str);
505             });
506     }
507     eventInfo.subscriberName = subscriberRecord->eventRecordInfo.bundleName;
508     eventInfo.pid = subscriberRecord->eventRecordInfo.pid;
509     eventInfo.uid = static_cast<int32_t>(subscriberRecord->eventRecordInfo.uid);
510     EventReport::SendHiSysEvent(UNSUBSCRIBE, eventInfo);
511 }
512 
SendPublishHiSysEvent(int32_t userId,const std::string & publisherName,int32_t pid,int32_t uid,const std::string & event,bool succeed)513 void InnerCommonEventManager::SendPublishHiSysEvent(int32_t userId, const std::string &publisherName, int32_t pid,
514     int32_t uid, const std::string &event, bool succeed)
515 {
516     EventInfo eventInfo;
517     eventInfo.userId = userId;
518     eventInfo.publisherName = publisherName;
519     eventInfo.pid = pid;
520     eventInfo.uid = uid;
521     eventInfo.eventName = event;
522 
523     if (succeed) {
524         EventReport::SendHiSysEvent(PUBLISH, eventInfo);
525     } else {
526         EventReport::SendHiSysEvent(PUBLISH_ERROR, eventInfo);
527     }
528 }
529 
RemoveStickyCommonEvent(const std::string & event,uint32_t callerUid)530 int32_t InnerCommonEventManager::RemoveStickyCommonEvent(const std::string &event, uint32_t callerUid)
531 {
532     return DelayedSingleton<CommonEventStickyManager>::GetInstance()->RemoveStickyCommonEvent(event, callerUid);
533 }
534 
SetStaticSubscriberState(bool enable)535 int32_t InnerCommonEventManager::SetStaticSubscriberState(bool enable)
536 {
537     if (staticSubscriberManager_ != nullptr) {
538         return staticSubscriberManager_->SetStaticSubscriberState(enable);
539     }
540     return Notification::ERR_NOTIFICATION_CESM_ERROR;
541 }
542 }  // namespace EventFwk
543 }  // namespace OHOS
544