• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "account_event_subscribe.h"
17 #include "account_info.h"
18 #include "account_log_wrapper.h"
19 #include "bundle_constants.h"
20 #ifdef HAS_CES_PART
21 #include "common_event_manager.h"
22 #include "common_event_subscriber.h"
23 #include "common_event_support.h"
24 #include "common_event_subscribe_info.h"
25 #include "matching_skills.h"
26 #endif // HAS_CES_PART
27 
28 namespace OHOS {
29 namespace AccountSA {
30 #ifdef HAS_CES_PART
AccountEventSubscriberCallback(const EventFwk::CommonEventSubscribeInfo & subscribeInfo,const AccountCommonEventCallback & callback)31 AccountEventSubscriberCallback::AccountEventSubscriberCallback(
32     const EventFwk::CommonEventSubscribeInfo &subscribeInfo, const AccountCommonEventCallback &callback)
33     : CommonEventSubscriber(subscribeInfo), callback_(callback)
34 {}
35 
OnReceiveEvent(const EventFwk::CommonEventData & data)36 void AccountEventSubscriberCallback::OnReceiveEvent(const EventFwk::CommonEventData &data)
37 {
38     auto want = data.GetWant();
39     std::string action = want.GetAction();
40     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) {
41         auto uid = want.GetIntParam(AppExecFwk::Constants::UID, -1);
42         callback_.OnPackageRemoved(uid);
43     }
44 }
45 
AccountEventSubscriber(const AccountCommonEventCallback & callback)46 AccountEventSubscriber::AccountEventSubscriber(const AccountCommonEventCallback &callback) : callback_(callback)
47 {
48     EventFwk::MatchingSkills matchingSkills;
49     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
50     EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
51     subscriber_ = std::make_shared<AccountEventSubscriberCallback>(subscribeInfo, callback_);
52 }
53 
~AccountEventSubscriber()54 AccountEventSubscriber::~AccountEventSubscriber()
55 {
56     EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber_);
57 }
58 
CreateEventSubscribe()59 bool AccountEventSubscriber::CreateEventSubscribe()
60 {
61     return EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber_);
62 }
63 
DestroyEventSubscribe()64 bool AccountEventSubscriber::DestroyEventSubscribe()
65 {
66     return EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber_);
67 }
68 #endif // HAS_CES_PART
69 } // namespace AccountSA
70 } // namespace OHOS