• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_INNER_COMMON_EVENT_MANAGER_H
17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_INNER_COMMON_EVENT_MANAGER_H
18 
19 #include "access_token_helper.h"
20 #include "common_event_control_manager.h"
21 #include "icommon_event.h"
22 #include "static_subscriber_manager.h"
23 
24 namespace OHOS {
25 namespace EventFwk {
26 class InnerCommonEventManager {
27 public:
28     InnerCommonEventManager();
29 
~InnerCommonEventManager()30     virtual ~InnerCommonEventManager() {};
31 
32     /**
33      * Publishes a common event.
34      *
35      * @param data Indicates the common event data.
36      * @param publishInfo Indicates the publish info.
37      * @param commonEventListener Indicates the common event subscriber.
38      * @param recordTime Indicates the time of record.
39      * @param pid Indicates the pid of application.
40      * @param uid Indicates the uid of application.
41      * @param callerToken Indicates the token of caller.
42      * @param userId Indicates the user ID.
43      * @param bundleName Indicates the name of bundle.
44      * @param service Indicates the common event service.
45      * @return Returns true if successful; false otherwise.
46      */
47     bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishinfo,
48         const sptr<IRemoteObject> &commonEventListener, const struct tm &recordTime, const pid_t &pid, const uid_t &uid,
49         const Security::AccessToken::AccessTokenID &callerToken, const int32_t &userId, const std::string &bundleName,
50         const sptr<IRemoteObject> &service = nullptr);
51 
52     /**
53      * Subscribes to common events.
54      *
55      * @param subscribeInfo Indicates the subscribe info.
56      * @param commonEventListener Indicates the common event subscriber.
57      * @param recordTime Indicates the time of record.
58      * @param pid Indicates the pid of application.
59      * @param uid Indicates the uid of application.
60      * @param callerToken Indicates the token of caller.
61      * @param bundleName Indicates the name of bundle.
62      * @return Returns true if successful; false otherwise.
63      */
64     bool SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
65         const sptr<IRemoteObject> &commonEventListener, const struct tm &recordTime, const pid_t &pid, const uid_t &uid,
66         const Security::AccessToken::AccessTokenID &callerToken, const std::string &bundleName);
67 
68     /**
69      * Unsubscribes from common events.
70      *
71      * @param commonEventListener Indicates the common event subscriber.
72      * @return Returns true if successful; false otherwise.
73      */
74     bool UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener);
75 
76     /**
77      * Gets the current sticky common event
78      *
79      * @param event Indicates the common event.
80      * @param eventData Indicates the common event data.
81      * @return Returns true if successful; false otherwise.
82      */
83     bool GetStickyCommonEvent(const std::string &event, CommonEventData &eventData);
84 
85     /**
86      * Dumps state of common event service.
87      *
88      * @param dumpType Indicates the dump type.
89      * @param event Specifies the information for the common event. Set null string ("") if you want to dump all.
90      * @param userId Indicates the user ID.
91      * @param state Indicates the state of common event service.
92      */
93     void DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
94         std::vector<std::string> &state);
95 
96     /**
97      * Finishes Receiver.
98      *
99      * @param proxy Indicates the receiver proxy.
100      * @param code Indicates the code of a common event.
101      * @param data Indicates the data of a common event.
102      * @param abortEvent Indicates Whether to cancel the current common event.
103      */
104     void FinishReceiver(
105         const sptr<IRemoteObject> &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent);
106 
107     /**
108      * Freezes application.
109      *
110      * @param uid Indicates the uid of application.
111      */
112     void Freeze(const uid_t &uid);
113 
114     /**
115      * Unfreezes application.
116      *
117      * @param uid Indicates the uid of application.
118      */
119     void Unfreeze(const uid_t &uid);
120 
121     /**
122      * Unfreezes all frozen applications.
123      */
124     void UnfreezeAll();
125 
126     /**
127      * dump event for hidumper.
128      *
129      * @param args Indicates the dump options.
130      * @param result the result of dump
131      */
132     void HiDump(const std::vector<std::u16string> &args, std::string &result);
133 private:
134     bool ProcessStickyEvent(const CommonEventRecord &record);
135     bool PublishStickyEvent(const std::shared_ptr<CommonEventSubscribeInfo> &sp,
136         const std::shared_ptr<EventSubscriberRecord> &subscriberRecord);
137     bool CheckUserId(const pid_t &pid, const uid_t &uid, const Security::AccessToken::AccessTokenID &callerToken,
138         bool &isSubsystem, bool &isSystemApp, bool &isProxy, int32_t &userId);
139     void SendSubscribeHiSysEvent(int32_t userId, const std::string &subscriberName, int32_t pid, int32_t uid,
140         const std::vector<std::string> &events);
141     void SendUnSubscribeHiSysEvent(const sptr<IRemoteObject> &commonEventListener);
142     void SendPublishHiSysEvent(int32_t userId, const std::string &publisherName, int32_t pid, int32_t uid,
143         const std::string &events, bool succeed);
144 
145 private:
146     std::shared_ptr<CommonEventControlManager> controlPtr_;
147     std::shared_ptr<StaticSubscriberManager> staticSubscriberManager_;
148     DISALLOW_COPY_AND_MOVE(InnerCommonEventManager);
149     time_t sysEventTime = 0;
150 };
151 }  // namespace EventFwk
152 }  // namespace OHOS
153 #endif  // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_INNER_COMMON_EVENT_MANAGER_H
154