• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_MANAGER_H
17 #define FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_MANAGER_H
18 
19 #include "common_event_data.h"
20 #include "common_event_publish_info.h"
21 #include "common_event_subscriber.h"
22 
23 namespace OHOS {
24 namespace EventFwk {
25 class CommonEventManager {
26 public:
27     /**
28      * Publishes a standard common event.
29      *
30      * @param data Indicates the common event data.
31      * @return Returns true if success; false otherwise.
32      */
33     static bool PublishCommonEvent(const CommonEventData &data);
34 
35     /**
36      * Publishes a standard common event.
37      *
38      * @param data Indicates the common event data.
39      * @param userId Indicates the user ID.
40      * @return Returns true if success; false otherwise.
41      */
42     static bool PublishCommonEventAsUser(const CommonEventData &data, const int32_t &userId);
43 
44     /**
45      * Publishes a common event.
46      *
47      * @param data Indicates the common event data.
48      * @param publishInfo Indicates the publish info.
49      * @return Returns true if success; false otherwise.
50      */
51     static bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo);
52 
53     /**
54      * Publishes a common event.
55      *
56      * @param data Indicates the common event data.
57      * @param publishInfo Indicates the publish info.
58      * @return Returns ERR_OK if success; otherwise failed.
59      */
60     static int32_t NewPublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo);
61 
62     /**
63      * Publishes a common event.
64      *
65      * @param data Indicates the common event data.
66      * @param publishInfo Indicates the publish info.
67      * @param userId Indicates the user ID.
68      * @return Returns true if success; false otherwise.
69      */
70     static bool PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
71         const int32_t &userId);
72 
73     /**
74      * Publishes a common event.
75      *
76      * @param data Indicates the common event data.
77      * @param publishInfo Indicates the publish info.
78      * @param userId Indicates the user ID.
79      * @return Returns ERR_OK if success; otherwise failed.
80      */
81     static int32_t NewPublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
82         const int32_t &userId);
83 
84     /**
85      * Publishes a common event.
86      *
87      * @param data Indicates the common event data.
88      * @param publishInfo Indicates the publish info.
89      * @param subscriber Indicates the common event subscriber.
90      * @return Returns true if success; false otherwise.
91      */
92     static bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
93         const std::shared_ptr<CommonEventSubscriber> &subscriber);
94 
95     /**
96      * Publishes a common event.
97      *
98      * @param data Indicates the common event data.
99      * @param publishInfo Indicates the publish info.
100      * @param subscriber Indicates the common event subscriber.
101      * @param userId Indicates the user ID.
102      * @return Returns true if success; false otherwise.
103      */
104     static bool PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
105         const std::shared_ptr<CommonEventSubscriber> &subscriber, const int32_t &userId);
106 
107     /**
108      * Publishes a common event.
109      *
110      * @param data Indicates the common event data.
111      * @param publishInfo Indicates the publish info.
112      * @param subscriber Indicates the common event subscriber.
113      * @param userId Indicates the user ID.
114      * @return Returns ERR_OK if success; otherwise failed.
115      */
116     static int32_t NewPublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
117         const std::shared_ptr<CommonEventSubscriber> &subscriber, const int32_t &userId);
118 
119     /**
120      * Publishes a common event.
121      *
122      * @param data Indicates the common event data.
123      * @param publishInfo Indicates the publish info.
124      * @param subscriber Indicates the common event subscriber.
125      * @param uid Indicates the uid of application.
126      * @param callerToken Indicates the caller token.
127      * @return Returns true if success; false otherwise.
128      */
129     static bool PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
130         const std::shared_ptr<CommonEventSubscriber> &subscriber, const uid_t &uid, const int32_t &callerToken);
131 
132     /**
133      * Publishes a common event.
134      *
135      * @param data Indicates the common event data.
136      * @param publishInfo Indicates the publish info.
137      * @param subscriber Indicates the common event subscriber.
138      * @param uid Indicates the Uid of application.
139      * @param callerToken Indicates the caller token.
140      * @param userId Indicates the user ID.
141      * @return Returns true if success; false otherwise.
142      */
143     static bool PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
144         const std::shared_ptr<CommonEventSubscriber> &subscriber, const uid_t &uid, const int32_t &callerToken,
145         const int32_t &userId);
146 
147     /**
148      * Subscribes to common events.
149      *
150      * @param subscriber Indicates the common event subscriber.
151      * @return Returns true if success; false otherwise.
152      */
153     static bool SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber);
154 
155     /**
156      * Subscribes to common events.
157      *
158      * @param subscriber Indicates the common event subscriber.
159      * @return Returns ERR_OK if success; otherwise failed.
160      */
161     static int32_t NewSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber);
162 
163     /**
164      * Unsubscribes from common events.
165      *
166      * @param subscriber Indicates the common event subscriber.
167      * @return Returns true if success; false otherwise.
168      */
169     static bool UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber);
170 
171     /**
172      * Unsubscribes from common events.
173      *
174      * @param subscriber Indicates the common event subscriber.
175      * @return Returns ERR_OK if success; otherwise failed.
176      */
177     static int32_t NewUnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber);
178 
179     /**
180      * Gets the current sticky common event
181      *
182      * @param event Indicates the common event.
183      * @param data Indicates the common event data.
184      * @return Returns true if success; false otherwise.
185      */
186     static bool GetStickyCommonEvent(const std::string &event, CommonEventData &data);
187 
188     /**
189      * Freezes application.
190      *
191      * @param uid Indicates the uid of application.
192      * @return Returns true if successful; false otherwise.
193      */
194     static bool Freeze(const uid_t &uid);
195 
196     /**
197      * Unfreezes application.
198      *
199      * @param uid Indicates the uid of application.
200      * @return Returns true if successful; false otherwise.
201      */
202     static bool Unfreeze(const uid_t &uid);
203 
204     /**
205      * Unfreezes all frozen applications.
206      *
207      * @return Returns true if successful; false otherwise.
208      */
209     static bool UnfreezeAll();
210 
211     /**
212      * Remove sticky common event.
213      *
214      * @param event Name of the common event.
215      * @return Returns ERR_OK if success; otherwise failed.
216      */
217     static int32_t RemoveStickyCommonEvent(const std::string &event);
218 
219     /**
220      * Set Static Subscriber State.
221      *
222      * @param enable static subscriber state.
223      * @return Returns ERR_OK if success; otherwise failed.
224      */
225     static int32_t SetStaticSubscriberState(bool enable);
226 };
227 }  // namespace EventFwk
228 }  // namespace OHOS
229 
230 #endif  // FOUNDATION_EVENT_CESFWK_KITS_NATIVE_INCLUDE_COMMON_EVENT_MANAGER_H
231