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 
52     /**
53      * @brief Init form infos and register form bundle event callback.
54      */
55     void InitFormInfosAndRegister();
56 
57 private:
58     void HandleUserIdRemoved(const int32_t userId); // multiuser
59     bool IsSameForm(const FormRecord &record, const FormInfo &formInfo);
60     void HandleBundleScanFinished();
61     void HandleUserSwitched(const EventFwk::CommonEventData &eventData);
62     void HandleAbilityUpdate(const AAFwk::Want& want, std::string &bundleName);
63     void HandlePackageDataCleared(std::string &bundleName, int32_t userId);
64     void HandleScreenUnlocked();
65     void HandleUserUnlocked();
66     void HandleScreenOn();
67     void HandleUserIdForms(int32_t currentUserId, int32_t lastUserId);
68     void RecycleForms(int32_t userId);
69 private:
70     std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr;
71     int32_t lastUserId_ = 0;
72 };
73 }  // namespace AppExecFwk
74 }  // namespace OHOS
75 
76 #endif // OHOS_FORM_FWK_FORM_SYS_EVENT_RECEIVER_H
77