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 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_EVENT_SUBSCRIBE_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_EVENT_SUBSCRIBE_H 18 19 #include "account_error_no.h" 20 #include "account_info.h" 21 #ifdef HAS_CES_PART 22 #include "common_event_data.h" 23 #include "common_event_subscriber.h" 24 #include "common_event_subscribe_info.h" 25 #endif // HAS_CES_PART 26 27 namespace OHOS { 28 namespace AccountSA { 29 #ifdef HAS_CES_PART 30 struct AccountCommonEventCallback { 31 std::function<void(const std::int32_t callingUid)> OnPackageRemoved; 32 }; 33 34 class AccountEventSubscriberCallback final : public EventFwk::CommonEventSubscriber { 35 public: 36 explicit AccountEventSubscriberCallback( 37 const EventFwk::CommonEventSubscribeInfo &subscribeInfo, const AccountCommonEventCallback &callback); 38 ~AccountEventSubscriberCallback() = default; 39 40 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 41 42 private: 43 AccountCommonEventCallback callback_; 44 }; 45 class AccountEventSubscriber { 46 public: 47 explicit AccountEventSubscriber(const AccountCommonEventCallback &callback); 48 ~AccountEventSubscriber(); 49 bool CreateEventSubscribe(); 50 bool DestroyEventSubscribe(); 51 52 private: 53 AccountCommonEventCallback callback_; 54 std::shared_ptr<AccountEventSubscriberCallback> subscriber_ = nullptr; 55 }; 56 #endif // HAS_CES_PART 57 } // namespace AccountSA 58 } // namespace OHOS 59 60 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_ACCOUNT_EVENT_SUBSCRIBE_H