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 "common_event_manager_service.h"
17 
18 #include "ability_manager_helper.h"
19 #include "access_token_helper.h"
20 #include "accesstoken_kit.h"
21 #include "bundle_manager_helper.h"
22 #include "common_event_constant.h"
23 #include "datetime_ex.h"
24 #include "event_log_wrapper.h"
25 #include "hitrace_meter_adapter.h"
26 #include "ipc_skeleton.h"
27 #include "parameters.h"
28 #include "publish_manager.h"
29 #include "refbase.h"
30 #include "system_ability_definition.h"
31 #include "os_account_manager_helper.h"
32 #include "xcollie/watchdog.h"
33 #include "ces_inner_error_code.h"
34 #include "system_time.h"
35 #include <mutex>
36 #include <new>
37 
38 namespace OHOS {
39 namespace EventFwk {
40 namespace {
41 const std::string NOTIFICATION_CES_CHECK_SA_PERMISSION = "notification.ces.check.sa.permission";
42 }  // namespace
43 
44 using namespace OHOS::Notification;
45 
46 sptr<CommonEventManagerService> CommonEventManagerService::instance_;
47 std::mutex CommonEventManagerService::instanceMutex_;
48 
GetInstance()49 sptr<CommonEventManagerService> CommonEventManagerService::GetInstance()
50 {
51     if (instance_ == nullptr) {
52         std::lock_guard<std::mutex> lock(instanceMutex_);
53         if (instance_ == nullptr) {
54             instance_ = new (std::nothrow) CommonEventManagerService();
55             if (instance_ == nullptr) {
56                 EVENT_LOGE("failed to create CommonEventManagerService!");
57             }
58         }
59     }
60     return instance_;
61 }
62 
CommonEventManagerService()63 CommonEventManagerService::CommonEventManagerService()
64     : serviceRunningState_(ServiceRunningState::STATE_NOT_START),
65       runner_(nullptr),
66       handler_(nullptr)
67 {
68     supportCheckSaPermission_ = OHOS::system::GetParameter(NOTIFICATION_CES_CHECK_SA_PERMISSION, "false");
69     EVENT_LOGD("instance created");
70 }
71 
~CommonEventManagerService()72 CommonEventManagerService::~CommonEventManagerService()
73 {
74     EVENT_LOGD("instance destroyed");
75 }
76 
Init()77 ErrCode __attribute__((weak)) CommonEventManagerService::Init()
78 {
79     EVENT_LOGD("ready to init");
80     innerCommonEventManager_ = std::make_shared<InnerCommonEventManager>();
81     if (!innerCommonEventManager_) {
82         EVENT_LOGE("Failed to init without inner service");
83         return ERR_INVALID_OPERATION;
84     }
85 
86     commonEventSrvQueue_ = std::make_shared<ffrt::queue>("CesSrvMain");
87     serviceRunningState_ = ServiceRunningState::STATE_RUNNING;
88 
89     return ERR_OK;
90 }
91 
IsReady() const92 bool CommonEventManagerService::IsReady() const
93 {
94     if (!innerCommonEventManager_) {
95         EVENT_LOGE("innerCommonEventManager is null");
96         return false;
97     }
98 
99     if (!commonEventSrvQueue_) {
100         EVENT_LOGE("queue object is null");
101         return false;
102     }
103 
104     return true;
105 }
106 
PublishCommonEvent(const CommonEventData & event,const CommonEventPublishInfo & publishinfo,const sptr<IRemoteObject> & commonEventListener,const int32_t & userId)107 int32_t CommonEventManagerService::PublishCommonEvent(const CommonEventData &event,
108     const CommonEventPublishInfo &publishinfo, const sptr<IRemoteObject> &commonEventListener,
109     const int32_t &userId)
110 {
111     EVENT_LOGD("enter");
112 
113     if (!IsReady()) {
114         EVENT_LOGE("CommonEventManagerService not ready");
115         return ERR_NOTIFICATION_CESM_ERROR;
116     }
117 
118     if (userId != ALL_USER && userId != CURRENT_USER && userId != UNDEFINED_USER) {
119         bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
120         if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
121             EVENT_LOGE("publish to special user must be system application.");
122             return ERR_NOTIFICATION_CES_COMMON_NOT_SYSTEM_APP;
123         }
124     }
125 
126     return PublishCommonEventDetailed(event,
127         publishinfo,
128         commonEventListener,
129         IPCSkeleton::GetCallingPid(),
130         IPCSkeleton::GetCallingUid(),
131         IPCSkeleton::GetCallingTokenID(),
132         userId);
133 }
134 
PublishCommonEvent(const CommonEventData & event,const CommonEventPublishInfo & publishinfo,const sptr<IRemoteObject> & commonEventListener,const uid_t & uid,const int32_t & callerToken,const int32_t & userId)135 bool CommonEventManagerService::PublishCommonEvent(const CommonEventData &event,
136     const CommonEventPublishInfo &publishinfo, const sptr<IRemoteObject> &commonEventListener, const uid_t &uid,
137     const int32_t &callerToken, const int32_t &userId)
138 {
139     EVENT_LOGD("enter");
140 
141     if (!IsReady()) {
142         EVENT_LOGE("CommonEventManagerService not ready");
143         return false;
144     }
145 
146     auto callingUid = IPCSkeleton::GetCallingUid();
147     if (callingUid != FOUNDATION_UID) {
148         EVENT_LOGE("Only foundation can publish common event as proxy uid = %{public}d.", callingUid);
149         return false;
150     }
151 
152     return PublishCommonEventDetailed(
153         event, publishinfo, commonEventListener, UNDEFINED_PID, uid, callerToken, userId) == ERR_OK ? true : false;
154 }
155 
PublishCommonEventDetailed(const CommonEventData & event,const CommonEventPublishInfo & publishinfo,const sptr<IRemoteObject> & commonEventListener,const pid_t & pid,const uid_t & uid,const int32_t & clientToken,const int32_t & userId)156 int32_t CommonEventManagerService::PublishCommonEventDetailed(const CommonEventData &event,
157     const CommonEventPublishInfo &publishinfo, const sptr<IRemoteObject> &commonEventListener, const pid_t &pid,
158     const uid_t &uid, const int32_t &clientToken, const int32_t &userId)
159 {
160     HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
161 
162     if (AccessTokenHelper::IsDlpHap(clientToken)) {
163         EVENT_LOGE("DLP hap not allowed to send common event");
164         return ERR_NOTIFICATION_CES_NOT_SA_SYSTEM_APP;
165     }
166     struct tm recordTime = {0};
167     if (!GetSystemCurrentTime(&recordTime)) {
168         EVENT_LOGE("Failed to GetSystemCurrentTime");
169         return ERR_NOTIFICATION_SYS_ERROR;
170     }
171     int32_t errCode = CheckUserIdParams(userId);
172     if (errCode != ERR_OK) {
173         return errCode;
174     }
175 
176     if (DelayedSingleton<PublishManager>::GetInstance()->CheckIsFloodAttack(uid)) {
177         EVENT_LOGE("Too many common events have been sent in a short period from (pid = %{public}d, uid = "
178                    "%{public}d, userId = %{public}d)", pid, uid, userId);
179         return ERR_NOTIFICATION_CES_COMMON_PARAM_INVALID;
180     }
181 
182     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
183     wptr<CommonEventManagerService> weakThis = this;
184     std::function<void()> publishCommonEventFunc = [wp,
185         event,
186         publishinfo,
187         commonEventListener,
188         recordTime,
189         pid,
190         uid,
191         clientToken,
192         userId,
193         weakThis] () {
194         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
195         if (innerCommonEventManager == nullptr) {
196             EVENT_LOGE("innerCommonEventManager not exist");
197             return;
198         }
199         std::string bundleName = "";
200         if (!AccessTokenHelper::VerifyNativeToken(clientToken)) {
201             bundleName = DelayedSingleton<BundleManagerHelper>::GetInstance()->GetBundleName(uid);
202         }
203         sptr<CommonEventManagerService> commonEventManagerService = weakThis.promote();
204         if (commonEventManagerService == nullptr) {
205             EVENT_LOGE("CommonEventManager not exist");
206             return;
207         }
208         bool ret = innerCommonEventManager->PublishCommonEvent(event,
209             publishinfo,
210             commonEventListener,
211             recordTime,
212             pid,
213             uid,
214             clientToken,
215             userId,
216             bundleName,
217             commonEventManagerService);
218         if (!ret) {
219             EVENT_LOGE("failed to publish event %{public}s", event.GetWant().GetAction().c_str());
220         }
221     };
222     EVENT_LOGI("Start to submit publish commonEvent <%{public}d>", uid);
223     commonEventSrvQueue_->submit(publishCommonEventFunc);
224     return ERR_OK;
225 }
226 
SubscribeCommonEvent(const CommonEventSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & commonEventListener,const int32_t instanceKey)227 int32_t CommonEventManagerService::SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
228     const sptr<IRemoteObject> &commonEventListener, const int32_t instanceKey)
229 {
230     HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
231     EVENT_LOGD("enter");
232 
233     if (!IsReady()) {
234         EVENT_LOGE("CommonEventManagerService not ready");
235         return ERR_NOTIFICATION_CES_COMMON_PARAM_INVALID;
236     }
237 
238     struct tm recordTime = {0};
239     if (!GetSystemCurrentTime(&recordTime)) {
240         EVENT_LOGE("Failed to GetSystemCurrentTime");
241         return ERR_NOTIFICATION_CES_COMMON_PARAM_INVALID;
242     }
243 
244     int32_t errCode = CheckUserIdParams(subscribeInfo.GetUserId());
245     if (errCode != ERR_OK) {
246         return errCode;
247     }
248 
249     auto callingUid = IPCSkeleton::GetCallingUid();
250     auto callingPid = IPCSkeleton::GetCallingPid();
251     Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
252     std::string bundleName = "";
253     if (!AccessTokenHelper::VerifyNativeToken(callerToken)) {
254         bundleName = DelayedSingleton<BundleManagerHelper>::GetInstance()->GetBundleName(callingUid);
255     }
256     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
257     int64_t startTime = SystemTime::GetNowSysTime();
258     std::function<void()> subscribeCommonEventFunc = [wp,
259         subscribeInfo,
260         commonEventListener,
261         recordTime,
262         callingPid,
263         callingUid,
264         callerToken,
265         bundleName,
266         instanceKey,
267         startTime] () {
268         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
269         if (innerCommonEventManager == nullptr) {
270             EVENT_LOGE("innerCommonEventManager not exist");
271             return;
272         }
273         bool ret = innerCommonEventManager->SubscribeCommonEvent(subscribeInfo,
274             commonEventListener,
275             recordTime,
276             callingPid,
277             callingUid,
278             callerToken,
279             bundleName,
280             instanceKey,
281             startTime);
282         if (!ret) {
283             EVENT_LOGE("failed to subscribe event");
284         }
285     };
286 
287     EVENT_LOGI("Start to submit subscribe commonEvent <%{public}d>", callingUid);
288     commonEventSrvQueue_->submit(subscribeCommonEventFunc);
289     return ERR_OK;
290 }
291 
UnsubscribeCommonEvent(const sptr<IRemoteObject> & commonEventListener)292 int32_t CommonEventManagerService::UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener)
293 {
294     HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
295     EVENT_LOGD("enter");
296 
297     if (!IsReady()) {
298         EVENT_LOGE("CommonEventManagerService not ready");
299         return ERR_NOTIFICATION_CES_COMMON_PARAM_INVALID;
300     }
301 
302     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
303     std::function<void()> unsubscribeCommonEventFunc = [wp, commonEventListener] () {
304         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
305         if (innerCommonEventManager == nullptr) {
306             EVENT_LOGE("innerCommonEventManager not exist");
307             return;
308         }
309         bool ret = innerCommonEventManager->UnsubscribeCommonEvent(commonEventListener);
310         if (!ret) {
311             EVENT_LOGE("failed to unsubscribe event");
312         }
313     };
314 
315     commonEventSrvQueue_->submit(unsubscribeCommonEventFunc);
316     return ERR_OK;
317 }
318 
GetStickyCommonEvent(const std::string & event,CommonEventData & eventData)319 bool CommonEventManagerService::GetStickyCommonEvent(const std::string &event, CommonEventData &eventData)
320 {
321     EVENT_LOGD("enter");
322 
323     if (!IsReady()) {
324         EVENT_LOGE("CommonEventManagerService not ready");
325         return false;
326     }
327 
328     if (event.empty()) {
329         EVENT_LOGE("event is empty");
330         return false;
331     }
332     auto callerToken = IPCSkeleton::GetCallingTokenID();
333     bool isSubsystem = AccessTokenHelper::VerifyNativeToken(callerToken);
334     if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
335         EVENT_LOGE("Not system application or subsystem request.");
336         return ERR_NOTIFICATION_CES_COMMON_NOT_SYSTEM_APP;
337     }
338     auto callingUid = IPCSkeleton::GetCallingUid();
339     std::string bundleName = DelayedSingleton<BundleManagerHelper>::GetInstance()->GetBundleName(callingUid);
340     const std::string permission = "ohos.permission.COMMONEVENT_STICKY";
341     bool ret = AccessTokenHelper::VerifyAccessToken(callerToken, permission);
342     if (!ret) {
343         EVENT_LOGE("No permission to get a sticky common event from %{public}s (uid = %{public}d)",
344             bundleName.c_str(),
345             callingUid);
346         return false;
347     }
348 
349     return innerCommonEventManager_->GetStickyCommonEvent(event, eventData);
350 }
351 
DumpState(const uint8_t & dumpType,const std::string & event,const int32_t & userId,std::vector<std::string> & state)352 bool CommonEventManagerService::DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
353     std::vector<std::string> &state)
354 {
355     EVENT_LOGD("enter");
356 
357     auto callerToken = IPCSkeleton::GetCallingTokenID();
358     if (!AccessTokenHelper::VerifyShellToken(callerToken) && !AccessTokenHelper::VerifyNativeToken(callerToken)) {
359         EVENT_LOGE("Not subsystem or shell request");
360         return false;
361     }
362     if (!IsReady()) {
363         EVENT_LOGE("CommonEventManagerService not ready");
364         return false;
365     }
366 
367     innerCommonEventManager_->DumpState(dumpType, event, userId, state);
368 
369     return true;
370 }
371 
FinishReceiver(const sptr<IRemoteObject> & proxy,const int32_t & code,const std::string & receiverData,const bool & abortEvent)372 bool CommonEventManagerService::FinishReceiver(
373     const sptr<IRemoteObject> &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent)
374 {
375     EVENT_LOGD("enter");
376 
377     if (!IsReady()) {
378         EVENT_LOGE("CommonEventManagerService not ready");
379         return false;
380     }
381     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
382     std::function<void()> finishReceiverFunc = [wp, proxy, code, receiverData, abortEvent] () {
383         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
384         if (innerCommonEventManager == nullptr) {
385             EVENT_LOGE("innerCommonEventManager not exist");
386             return;
387         }
388         innerCommonEventManager->FinishReceiver(proxy, code, receiverData, abortEvent);
389     };
390 
391     commonEventSrvQueue_->submit(finishReceiverFunc);
392     return true;
393 }
394 
Freeze(const uid_t & uid)395 bool CommonEventManagerService::Freeze(const uid_t &uid)
396 {
397     EVENT_LOGD("enter");
398 
399     auto tokenId = IPCSkeleton::GetCallingTokenID();
400     if (!AccessTokenHelper::VerifyNativeToken(tokenId) ||
401         AccessTokenHelper::GetCallingProcessName(tokenId) != RESOURCE_MANAGER_PROCESS_NAME) {
402         EVENT_LOGE("Not subsystem request");
403         return false;
404     }
405 
406     if (!IsReady()) {
407         EVENT_LOGE("CommonEventManagerService not ready");
408         return false;
409     }
410     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
411     std::function<void()> freezeFunc = [wp, uid] () {
412         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
413         if (innerCommonEventManager == nullptr) {
414             EVENT_LOGE("innerCommonEventManager not exist");
415             return;
416         }
417         innerCommonEventManager->Freeze(uid);
418     };
419 
420     commonEventSrvQueue_->submit(freezeFunc);
421     return true;
422 }
423 
Unfreeze(const uid_t & uid)424 bool CommonEventManagerService::Unfreeze(const uid_t &uid)
425 {
426     EVENT_LOGD("enter");
427 
428     auto tokenId = IPCSkeleton::GetCallingTokenID();
429     if (!AccessTokenHelper::VerifyNativeToken(tokenId) ||
430         AccessTokenHelper::GetCallingProcessName(tokenId) != RESOURCE_MANAGER_PROCESS_NAME) {
431         EVENT_LOGE("Not subsystem request");
432         return false;
433     }
434 
435     if (!IsReady()) {
436         EVENT_LOGE("CommonEventManagerService not ready");
437         return false;
438     }
439 
440     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
441     std::function<void()> unfreezeFunc = [wp, uid] () {
442         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
443         if (innerCommonEventManager == nullptr) {
444             EVENT_LOGE("innerCommonEventManager not exist");
445             return;
446         }
447         innerCommonEventManager->Unfreeze(uid);
448     };
449 
450     commonEventSrvQueue_->submit(unfreezeFunc);
451     return true;
452 }
453 
UnfreezeAll()454 bool CommonEventManagerService::UnfreezeAll()
455 {
456     EVENT_LOGD("enter");
457 
458     auto tokenId = IPCSkeleton::GetCallingTokenID();
459     if (!AccessTokenHelper::VerifyNativeToken(tokenId) ||
460         AccessTokenHelper::GetCallingProcessName(tokenId) != RESOURCE_MANAGER_PROCESS_NAME) {
461         EVENT_LOGE("Not subsystem request");
462         return false;
463     }
464 
465     if (!IsReady()) {
466         EVENT_LOGE("CommonEventManagerService not ready");
467         return false;
468     }
469 
470     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
471     std::function<void()> unfreezeAllFunc = [wp] () {
472         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
473         if (innerCommonEventManager == nullptr) {
474             EVENT_LOGE("innerCommonEventManager not exist");
475             return;
476         }
477         innerCommonEventManager->UnfreezeAll();
478     };
479 
480     commonEventSrvQueue_->submit(unfreezeAllFunc);
481     return true;
482 }
483 
Dump(int fd,const std::vector<std::u16string> & args)484 int CommonEventManagerService::Dump(int fd, const std::vector<std::u16string> &args)
485 {
486     EVENT_LOGD("enter");
487 
488     auto callerToken = IPCSkeleton::GetCallingTokenID();
489     if (!AccessTokenHelper::VerifyShellToken(callerToken) && !AccessTokenHelper::VerifyNativeToken(callerToken)) {
490         EVENT_LOGE("Not subsystem or shell request");
491         return ERR_NOTIFICATION_CES_COMMON_PERMISSION_DENIED;
492     }
493     if (!IsReady()) {
494         EVENT_LOGE("CommonEventManagerService not ready");
495         return ERR_INVALID_VALUE;
496     }
497     std::string result;
498     innerCommonEventManager_->HiDump(args, result);
499     int ret = dprintf(fd, "%s\n", result.c_str());
500     if (ret < 0) {
501         EVENT_LOGE("dprintf error");
502         return ERR_INVALID_VALUE;
503     }
504     return ERR_OK;
505 }
506 
RemoveStickyCommonEvent(const std::string & event)507 int32_t CommonEventManagerService::RemoveStickyCommonEvent(const std::string &event)
508 {
509     EVENT_LOGI("enter");
510 
511     if (!IsReady()) {
512         EVENT_LOGE("CommonEventManagerService not ready");
513         return ERR_NOTIFICATION_CESM_ERROR;
514     }
515 
516     auto tokenId = IPCSkeleton::GetCallingTokenID();
517     bool isSubsystem = AccessTokenHelper::VerifyNativeToken(tokenId);
518     if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
519         EVENT_LOGE("Not system application or subsystem request.");
520         return ERR_NOTIFICATION_CES_COMMON_NOT_SYSTEM_APP;
521     }
522 
523     const std::string permission = "ohos.permission.COMMONEVENT_STICKY";
524     bool ret = AccessTokenHelper::VerifyAccessToken(tokenId, permission);
525     if (!ret && (!isSubsystem || supportCheckSaPermission_.compare("true") == 0)) {
526         EVENT_LOGE("No permission.");
527         return ERR_NOTIFICATION_CES_COMMON_PERMISSION_DENIED;
528     }
529 
530     return innerCommonEventManager_->RemoveStickyCommonEvent(event, IPCSkeleton::GetCallingUid());
531 }
532 
SetStaticSubscriberState(bool enable)533 int32_t CommonEventManagerService::SetStaticSubscriberState(bool enable)
534 {
535     if (!AccessTokenHelper::IsSystemApp()) {
536         EVENT_LOGE("Not system application");
537         return ERR_NOTIFICATION_CES_COMMON_NOT_SYSTEM_APP;
538     }
539 
540     return innerCommonEventManager_->SetStaticSubscriberState(enable);
541 }
542 
SetStaticSubscriberState(const std::vector<std::string> & events,bool enable)543 int32_t CommonEventManagerService::SetStaticSubscriberState(const std::vector<std::string> &events, bool enable)
544 {
545     if (!AccessTokenHelper::IsSystemApp()) {
546         EVENT_LOGE("Not system application.");
547         return ERR_NOTIFICATION_CES_COMMON_NOT_SYSTEM_APP;
548     }
549     return innerCommonEventManager_->SetStaticSubscriberState(events, enable);
550 }
551 
SetFreezeStatus(std::set<int> pidList,bool isFreeze)552 bool CommonEventManagerService::SetFreezeStatus(std::set<int> pidList, bool isFreeze)
553 {
554     EVENT_LOGD("enter");
555     auto tokenId = IPCSkeleton::GetCallingTokenID();
556     if (!AccessTokenHelper::VerifyNativeToken(tokenId) ||
557         AccessTokenHelper::GetCallingProcessName(tokenId) != RESOURCE_MANAGER_PROCESS_NAME) {
558         EVENT_LOGE("Not subsystem request");
559         return false;
560     }
561 
562     if (!IsReady()) {
563         EVENT_LOGE("CommonEventManagerService not ready");
564         return false;
565     }
566 
567     std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
568     std::function<void()> setFreezeStatusFunc = [wp, pidList, isFreeze] () {
569         std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
570         if (innerCommonEventManager == nullptr) {
571             EVENT_LOGE("innerCommonEventManager not exist");
572             return;
573         }
574         innerCommonEventManager->SetFreezeStatus(pidList, isFreeze);
575     };
576 
577     commonEventSrvQueue_->submit(setFreezeStatusFunc);
578     return true;
579 }
580 
CheckUserIdParams(const int32_t & userId)581 int32_t CommonEventManagerService::CheckUserIdParams(const int32_t &userId)
582 {
583     if (userId != ALL_USER && userId != CURRENT_USER && userId != UNDEFINED_USER
584         && !OsAccountManagerHelper::GetInstance()->CheckUserExists(userId)) {
585         EVENT_LOGE("UserId %{public}d is not exists in OsAccount", userId);
586         return ERR_NOTIFICATION_CES_USERID_INVALID;
587     }
588     return ERR_OK;
589 }
590 }  // namespace EventFwk
591 }  // namespace OHOS
592