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