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 #ifndef OHOS_FORM_FWK_FORM_SYS_EVENT_RECEIVER_H 17 #define OHOS_FORM_FWK_FORM_SYS_EVENT_RECEIVER_H 18 19 #include "common_event_subscriber.h" 20 #include "common_event_subscribe_info.h" 21 #include "form_event_handler.h" 22 #include "form_event_util.h" 23 #include "form_serial_queue.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 /** 28 * @class FormSysEventReceiver 29 * Receive system common event. 30 */ 31 class FormSysEventReceiver : public EventFwk::CommonEventSubscriber, 32 public std::enable_shared_from_this<FormSysEventReceiver> { 33 public: 34 FormSysEventReceiver() = default; 35 FormSysEventReceiver(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); 36 virtual ~FormSysEventReceiver() = default; 37 /** 38 * @brief System common event receiver. 39 * @param eventData Common event data. 40 */ 41 virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; 42 43 /** 44 * @brief SetSerialQueue. 45 * @param serialQueue serial queue 46 */ SetSerialQueue(const std::shared_ptr<FormSerialQueue> & serialQueue)47 inline void SetSerialQueue(const std::shared_ptr<FormSerialQueue> &serialQueue) 48 { 49 serialQueue_ = serialQueue; 50 } 51 private: 52 void HandleUserIdRemoved(const int32_t userId); // multiuser 53 bool IsSameForm(const FormRecord &record, const FormInfo &formInfo); 54 void HandleBundleScanFinished(); 55 void HandleUserSwitched(const EventFwk::CommonEventData &eventData); 56 void OnReceiveEventForAbilityUpdate(const AAFwk::Want& want, std::string &bundleName); 57 void OnReceiveEventForUserRemoved(int32_t userId); 58 void OnReceiveEventForPackageDataCleared(std::string &bundleName, int32_t userId); 59 void OnReceiveEventForUserUnlocked(); 60 private: 61 FormEventUtil formEventHelper_; 62 std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr; 63 }; 64 } // namespace AppExecFwk 65 } // namespace OHOS 66 67 #endif // OHOS_FORM_FWK_FORM_SYS_EVENT_RECEIVER_H 68