• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "im_common_event_manager.h"
17 #include "full_ime_info_manager.h"
18 #include "ime_info_inquirer.h"
19 #include "iservice_registry.h"
20 #include "itypes_util.h"
21 #include "inputmethod_message_handler.h"
22 #include "os_account_adapter.h"
23 #include "peruser_session.h"
24 #include "system_ability_definition.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
28 using namespace MessageID;
29 sptr<ImCommonEventManager> ImCommonEventManager::instance_;
30 std::mutex ImCommonEventManager::instanceLock_;
31 using namespace OHOS::EventFwk;
32 constexpr const char *COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED = "usual.event.imf.input_panel_status_changed";
33 constexpr const char *COMMON_EVENT_PARAM_USER_ID = "userId";
34 constexpr const char *COMMON_EVENT_PARAM_PANEL_STATE = "panelState";
35 constexpr const char *COMMON_EVENT_PARAM_PANEL_RECT = "panelRect";
36 constexpr const char *EVENT_LARGE_MEMORY_STATUS_CHANGED = "usual.event.memmgr.large_memory_status_changed";
37 constexpr const char *EVENT_MEMORY_STATE = "memory_state";
38 constexpr const char *EVENT_PARAM_UID = "uid";
ImCommonEventManager()39 ImCommonEventManager::ImCommonEventManager()
40 {
41 }
42 
~ImCommonEventManager()43 ImCommonEventManager::~ImCommonEventManager()
44 {
45 }
46 
GetInstance()47 sptr<ImCommonEventManager> ImCommonEventManager::GetInstance()
48 {
49     if (instance_ == nullptr) {
50         std::lock_guard<std::mutex> autoLock(instanceLock_);
51         if (instance_ == nullptr) {
52             IMSA_HILOGI("instance_ is nullptr.");
53             instance_ = new (std::nothrow) ImCommonEventManager();
54         }
55     }
56     return instance_;
57 }
58 
SubscribeEvent()59 bool ImCommonEventManager::SubscribeEvent()
60 {
61     EventFwk::MatchingSkills matchingSkills;
62     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
63     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED);
64     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
65     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED);
66     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
67     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED);
68     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY);
69     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED);
70     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
71     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED);
72     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED);
73     matchingSkills.AddEvent(EVENT_LARGE_MEMORY_STATUS_CHANGED);
74 
75     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
76 
77     std::shared_ptr<EventSubscriber> subscriber = std::make_shared<EventSubscriber>(subscriberInfo);
78     auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
79     if (abilityManager == nullptr) {
80         IMSA_HILOGE("SubscribeEvent abilityManager is nullptr!");
81         return false;
82     }
83     sptr<ISystemAbilityStatusChange> listener = new (std::nothrow) SystemAbilityStatusChangeListener([subscriber]() {
84         bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
85         IMSA_HILOGI("SubscribeCommonEvent ret: %{public}d", subscribeResult);
86     });
87     if (listener == nullptr) {
88         IMSA_HILOGE("SubscribeEvent listener is nullptr!");
89         return false;
90     }
91     int32_t ret = abilityManager->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, listener);
92     if (ret != ERR_OK) {
93         IMSA_HILOGE("SubscribeEvent SubscribeSystemAbility failed. ret: %{public}d", ret);
94         return false;
95     }
96     return true;
97 }
98 
SubscribeKeyboardEvent(const Handler & handler)99 bool ImCommonEventManager::SubscribeKeyboardEvent(const Handler &handler)
100 {
101     IMSA_HILOGI("ImCommonEventManager::SubscribeKeyboardEvent start.");
102     auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
103     if (abilityManager == nullptr) {
104         IMSA_HILOGE("SubscribeKeyboardEvent abilityManager is nullptr!");
105         return false;
106     }
107     sptr<ISystemAbilityStatusChange> listener = new (std::nothrow) SystemAbilityStatusChangeListener([handler]() {
108         if (handler != nullptr) {
109             handler();
110         }
111     });
112     if (listener == nullptr) {
113         IMSA_HILOGE("listener is nullptr!");
114         return false;
115     }
116     int32_t ret = abilityManager->SubscribeSystemAbility(MULTIMODAL_INPUT_SERVICE_ID, listener);
117     if (ret != ERR_OK) {
118         IMSA_HILOGE("failed to SubscribeSystemAbility, ret: %{public}d!", ret);
119         return false;
120     }
121     return true;
122 }
123 
SubscribeWindowManagerService(const Handler & handler)124 bool ImCommonEventManager::SubscribeWindowManagerService(const Handler &handler)
125 {
126     IMSA_HILOGI("start.");
127     return SubscribeManagerServiceCommon(handler, WINDOW_MANAGER_SERVICE_ID);
128 }
129 
SubscribeMemMgrService(const Handler & handler)130 bool ImCommonEventManager::SubscribeMemMgrService(const Handler &handler)
131 {
132     return SubscribeManagerServiceCommon(handler, MEMORY_MANAGER_SA_ID);
133 }
134 
SubscribeAccountManagerService(Handler handler)135 bool ImCommonEventManager::SubscribeAccountManagerService(Handler handler)
136 {
137     return SubscribeManagerServiceCommon(handler, SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN);
138 }
139 
SubscribePasteboardService(const Handler & handler)140 bool ImCommonEventManager::SubscribePasteboardService(const Handler &handler)
141 {
142     return SubscribeManagerServiceCommon(handler, PASTEBOARD_SERVICE_ID);
143 }
144 
UnsubscribeEvent()145 bool ImCommonEventManager::UnsubscribeEvent()
146 {
147     return true;
148 }
149 
EventSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)150 ImCommonEventManager::EventSubscriber::EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
151     : EventFwk::CommonEventSubscriber(subscribeInfo)
152 {
153     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_SWITCHED] =
154         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
155             return that->StartUser(data);
156         };
157     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_STOPPED] =
158         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
159             return that->StopUser(data);
160         };
161     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_REMOVED] =
162         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
163             return that->RemoveUser(data);
164         };
165     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED] =
166         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
167             return that->RemovePackage(data);
168         };
169     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED] =
170         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
171             return that->OnBundleScanFinished(data);
172         };
173     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY] =
174         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
175             return that->OnDataShareReady(data);
176         };
177     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED] =
178         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
179             return that->AddPackage(data);
180         };
181     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED] =
182         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
183             return that->ChangePackage(data);
184         };
185     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED] =
186         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
187             return that->HandleBootCompleted(data);
188         };
189     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED] =
190         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
191             return that->OnScreenUnlock(data);
192         };
193     EventManagerFunc_[CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED] =
194         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
195             return that->OnScreenLock(data);
196         };
197     EventManagerFunc_[EVENT_LARGE_MEMORY_STATUS_CHANGED] =
198         [] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
199             return that->HandleLargeMemoryStateUpdate(data);
200         };
201 }
202 
OnReceiveEvent(const EventFwk::CommonEventData & data)203 void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data)
204 {
205     auto const &want = data.GetWant();
206     std::string action = want.GetAction();
207     IMSA_HILOGD("ImCommonEventManager::action: %{public}s!", action.c_str());
208     auto iter = EventManagerFunc_.find(action);
209     if (iter != EventManagerFunc_.end()) {
210         EventManagerFunc_[action] (this, data);
211     }
212 }
213 
StopUser(const CommonEventData & data)214 void ImCommonEventManager::EventSubscriber::StopUser(const CommonEventData &data)
215 {
216     HandleUserEvent(MessageID::MSG_ID_USER_STOP, data);
217 }
218 
StartUser(const CommonEventData & data)219 void ImCommonEventManager::EventSubscriber::StartUser(const CommonEventData &data)
220 {
221     HandleUserEvent(MessageID::MSG_ID_USER_START, data);
222 }
223 
RemoveUser(const CommonEventData & data)224 void ImCommonEventManager::EventSubscriber::RemoveUser(const CommonEventData &data)
225 {
226     HandleUserEvent(MessageID::MSG_ID_USER_REMOVED, data);
227 }
228 
HandleLargeMemoryStateUpdate(const EventFwk::CommonEventData & data)229 void ImCommonEventManager::EventSubscriber::HandleLargeMemoryStateUpdate(const EventFwk::CommonEventData &data)
230 {
231     auto const &want = data.GetWant();
232     int32_t uid = want.GetIntParam(EVENT_PARAM_UID, OsAccountAdapter::INVALID_UID);
233     int32_t memoryState = want.GetIntParam(EVENT_MEMORY_STATE, MiscServices::LargeMemoryState::LARGE_MEMORY_NOT_NEED);
234     if (uid == OsAccountAdapter::INVALID_UID) {
235         IMSA_HILOGE("Invaild uid received!");
236         return;
237     }
238     MessageParcel *parcel = new (std::nothrow) MessageParcel();
239     if (parcel == nullptr) {
240         IMSA_HILOGE("Parcel is nullptr!");
241         return;
242     }
243     if (!ITypesUtil::Marshal(*parcel, uid, memoryState)) {
244         IMSA_HILOGE("Failed to write message parcel.");
245         delete parcel;
246         return;
247     }
248     Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_UPDATE_LARGE_MEMORY_STATE, parcel);
249     if (msg == nullptr) {
250         IMSA_HILOGE("Failed to create Message!");
251         delete parcel;
252         return;
253     }
254     MessageHandler *msgHandle = MessageHandler::Instance();
255     if (msgHandle == nullptr) {
256         IMSA_HILOGE("MessageHandler is nullptr!");
257         delete parcel;
258         delete msg;
259         return;
260     }
261     msgHandle->SendMessage(msg);
262 }
263 
HandleUserEvent(int32_t messageId,const EventFwk::CommonEventData & data)264 void ImCommonEventManager::EventSubscriber::HandleUserEvent(int32_t messageId, const EventFwk::CommonEventData &data)
265 {
266     auto userId = data.GetCode();
267     MessageParcel *parcel = new (std::nothrow) MessageParcel();
268     if (parcel == nullptr) {
269         return;
270     }
271     IMSA_HILOGD("userId:%{public}d, messageId:%{public}d", userId, messageId);
272     parcel->WriteInt32(userId);
273     Message *msg = new (std::nothrow) Message(messageId, parcel);
274     if (msg == nullptr) {
275         delete parcel;
276         return;
277     }
278     MessageHandler::Instance()->SendMessage(msg);
279 }
280 
OnBundleScanFinished(const EventFwk::CommonEventData & data)281 void ImCommonEventManager::EventSubscriber::OnBundleScanFinished(const EventFwk::CommonEventData &data)
282 {
283     IMSA_HILOGI("ImCommonEventManager start.");
284     auto parcel = new (std::nothrow) MessageParcel();
285     if (parcel == nullptr) {
286         IMSA_HILOGE("failed to create MessageParcel!");
287         return;
288     }
289     auto msg = new (std::nothrow) Message(MessageID::MSG_ID_BUNDLE_SCAN_FINISHED, parcel);
290     if (msg == nullptr) {
291         IMSA_HILOGE("failed to create Message!");
292         delete parcel;
293         return;
294     }
295     MessageHandler::Instance()->SendMessage(msg);
296 }
297 
OnDataShareReady(const EventFwk::CommonEventData & data)298 void ImCommonEventManager::EventSubscriber::OnDataShareReady(const EventFwk::CommonEventData &data)
299 {
300     IMSA_HILOGI("ImCommonEventManager start.");
301     auto parcel = new (std::nothrow) MessageParcel();
302     if (parcel == nullptr) {
303         IMSA_HILOGE("failed to create MessageParcel!");
304         return;
305     }
306     auto msg = new (std::nothrow) Message(MessageID::MSG_ID_DATA_SHARE_READY, parcel);
307     if (msg == nullptr) {
308         IMSA_HILOGE("failed to create Message!");
309         delete parcel;
310         return;
311     }
312     MessageHandler::Instance()->SendMessage(msg);
313 }
314 
RemovePackage(const CommonEventData & data)315 void ImCommonEventManager::EventSubscriber::RemovePackage(const CommonEventData &data)
316 {
317     HandlePackageEvent(MessageID::MSG_ID_PACKAGE_REMOVED, data);
318 }
319 
AddPackage(const EventFwk::CommonEventData & data)320 void ImCommonEventManager::EventSubscriber::AddPackage(const EventFwk::CommonEventData &data)
321 {
322     HandlePackageEvent(MessageID::MSG_ID_PACKAGE_ADDED, data);
323 }
324 
ChangePackage(const EventFwk::CommonEventData & data)325 void ImCommonEventManager::EventSubscriber::ChangePackage(const EventFwk::CommonEventData &data)
326 {
327     HandlePackageEvent(MessageID::MSG_ID_PACKAGE_CHANGED, data);
328 }
329 
HandlePackageEvent(int32_t messageId,const EventFwk::CommonEventData & data)330 void ImCommonEventManager::EventSubscriber::HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data)
331 {
332     auto const &want = data.GetWant();
333     auto element = want.GetElement();
334     std::string bundleName = element.GetBundleName();
335     int32_t userId = want.GetIntParam("userId", OsAccountAdapter::INVALID_USER_ID);
336     if (userId == OsAccountAdapter::INVALID_USER_ID) {
337         IMSA_HILOGE("invalid user id, messageId:%{public}d", messageId);
338         return;
339     }
340     IMSA_HILOGD(
341         "messageId:%{public}d, bundleName:%{public}s, userId:%{public}d", messageId, bundleName.c_str(), userId);
342     if (messageId == MessageID::MSG_ID_PACKAGE_REMOVED) {
343         if (!FullImeInfoManager::GetInstance().Has(userId, bundleName)) {
344             return;
345         }
346     } else {
347         if (!ImeInfoInquirer::GetInstance().IsInputMethod(userId, bundleName)) {
348             return;
349         }
350     }
351     MessageParcel *parcel = new (std::nothrow) MessageParcel();
352     if (parcel == nullptr) {
353         IMSA_HILOGE("parcel is nullptr!");
354         return;
355     }
356     if (!ITypesUtil::Marshal(*parcel, userId, bundleName)) {
357         IMSA_HILOGE("Failed to write message parcel!");
358         delete parcel;
359         return;
360     }
361     Message *msg = new (std::nothrow) Message(messageId, parcel);
362     if (msg == nullptr) {
363         IMSA_HILOGE("failed to create Message!");
364         delete parcel;
365         return;
366     }
367     MessageHandler::Instance()->SendMessage(msg);
368 }
369 
HandleBootCompleted(const EventFwk::CommonEventData & data)370 void ImCommonEventManager::EventSubscriber::HandleBootCompleted(const EventFwk::CommonEventData &data)
371 {
372     Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_BOOT_COMPLETED, nullptr);
373     if (msg == nullptr) {
374         return;
375     }
376     MessageHandler::Instance()->SendMessage(msg);
377 }
378 
OnScreenUnlock(const EventFwk::CommonEventData & data)379 void ImCommonEventManager::EventSubscriber::OnScreenUnlock(const EventFwk::CommonEventData &data)
380 {
381     MessageParcel *parcel = new (std::nothrow) MessageParcel();
382     if (parcel == nullptr) {
383         IMSA_HILOGE("parcel is nullptr!");
384         return;
385     }
386     auto const &want = data.GetWant();
387     int32_t userId = want.GetIntParam("userId", OsAccountAdapter::INVALID_USER_ID);
388     if (!ITypesUtil::Marshal(*parcel, userId)) {
389         IMSA_HILOGE("Failed to write message parcel!");
390         delete parcel;
391         return;
392     }
393     Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_SCREEN_UNLOCK, parcel);
394     if (msg == nullptr) {
395         IMSA_HILOGE("failed to create Message!");
396         delete parcel;
397         return;
398     }
399     MessageHandler::Instance()->SendMessage(msg);
400 }
401 
OnScreenLock(const EventFwk::CommonEventData & data)402 void ImCommonEventManager::EventSubscriber::OnScreenLock(const EventFwk::CommonEventData &data)
403 {
404     MessageParcel *parcel = new (std::nothrow) MessageParcel();
405     if (parcel == nullptr) {
406         IMSA_HILOGE("parcel is nullptr!");
407         return;
408     }
409     auto const &want = data.GetWant();
410     int32_t userId = want.GetIntParam("userId", OsAccountAdapter::INVALID_USER_ID);
411     if (!ITypesUtil::Marshal(*parcel, userId)) {
412         IMSA_HILOGE("Failed to write message parcel!");
413         delete parcel;
414         return;
415     }
416     Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_SCREEN_LOCK, parcel);
417     if (msg == nullptr) {
418         IMSA_HILOGE("failed to create Message!");
419         delete parcel;
420         return;
421     }
422     MessageHandler::Instance()->SendMessage(msg);
423 }
424 
SystemAbilityStatusChangeListener(std::function<void ()> func)425 ImCommonEventManager::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(std::function<void()> func)
426     : func_(std::move(func))
427 {
428 }
429 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)430 void ImCommonEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility(int32_t systemAbilityId,
431     const std::string &deviceId)
432 {
433     IMSA_HILOGD("systemAbilityId: %{public}d.", systemAbilityId);
434     if (systemAbilityId != COMMON_EVENT_SERVICE_ID && systemAbilityId != MULTIMODAL_INPUT_SERVICE_ID &&
435         systemAbilityId != WINDOW_MANAGER_SERVICE_ID && systemAbilityId != SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN &&
436         systemAbilityId != MEMORY_MANAGER_SA_ID && systemAbilityId != PASTEBOARD_SERVICE_ID) {
437         return;
438     }
439     if (func_ != nullptr) {
440         func_();
441     }
442 }
443 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)444 void ImCommonEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(int32_t systemAbilityId,
445     const std::string &deviceId)
446 {
447 }
448 
PublishPanelStatusChangeEvent(int32_t userId,const InputWindowStatus & status,const ImeWindowInfo & info)449 int32_t ImCommonEventManager::PublishPanelStatusChangeEvent(
450     int32_t userId, const InputWindowStatus &status, const ImeWindowInfo &info)
451 {
452     EventFwk::CommonEventPublishInfo publicInfo;
453     publicInfo.SetOrdered(false);
454     AAFwk::Want want;
455     want.SetAction(COMMON_EVENT_INPUT_PANEL_STATUS_CHANGED);
456     bool visible = (status == InputWindowStatus::SHOW);
457     std::vector<int32_t> panelRect = { info.windowInfo.left, info.windowInfo.top,
458         static_cast<int32_t>(info.windowInfo.width), static_cast<int32_t>(info.windowInfo.height) };
459     want.SetParam(COMMON_EVENT_PARAM_USER_ID, userId);
460     want.SetParam(COMMON_EVENT_PARAM_PANEL_STATE, visible);
461     want.SetParam(COMMON_EVENT_PARAM_PANEL_RECT, panelRect);
462     EventFwk::CommonEventData data;
463     data.SetWant(want);
464     return EventFwk::CommonEventManager::NewPublishCommonEvent(data, publicInfo);
465 }
466 
SubscribeManagerServiceCommon(const Handler & handler,int32_t saId)467 bool ImCommonEventManager::SubscribeManagerServiceCommon(const Handler &handler, int32_t saId)
468 {
469     auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
470     if (abilityManager == nullptr) {
471         IMSA_HILOGE("abilityManager is nullptr, saId: %{public}d", saId);
472         return false;
473     }
474     sptr<ISystemAbilityStatusChange> listener = new (std::nothrow) SystemAbilityStatusChangeListener([handler]() {
475         if (handler != nullptr) {
476             handler();
477         }
478     });
479     if (listener == nullptr) {
480         IMSA_HILOGE("failed to create listener, saId: %{public}d", saId);
481         return false;
482     }
483     int32_t ret = abilityManager->SubscribeSystemAbility(saId, listener);
484     if (ret != ERR_OK) {
485         IMSA_HILOGE("subscribe system ability failed, ret: %{public}d, saId: %{public}d", ret, saId);
486         return false;
487     }
488     return true;
489 }
490 } // namespace MiscServices
491 } // namespace OHOS