• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_INNERKITS_INCLUDE_COMMON_EVENT_STUB_H
17 #define FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_STUB_H
18 
19 #include "common_event_service_ipc_interface_code.h"
20 #include "icommon_event.h"
21 #include "iremote_stub.h"
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace EventFwk {
26 class CommonEventStub : public IRemoteStub<ICommonEvent> {
27 public:
28     CommonEventStub();
29 
30     virtual ~CommonEventStub();
31 
32     /**
33      * Processes the remote Request.
34      *
35      * @param code Indicates the code to send.
36      * @param data Indicates the message to send.
37      * @param reply Indicates the message to reply.
38      * @param option Indicates the message option.
39      * @return Returns ERR_NONE if success, otherwise ERR_CODE.
40      */
41     int OnRemoteRequest(
42         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
43 
44     /**
45      * Publishes a common event.
46      *
47      * @param event Indicates the common event data.
48      * @param publishInfo Indicates the publish info.
49      * @param commonEventListener Indicates the last subscriber to receive the event.
50      * @param userId Indicates the user ID.
51      * @return Returns ERR_OK if successful; otherwise failed.
52      */
53     int32_t PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
54         const sptr<IRemoteObject> &commonEventListener, const int32_t &userId) override;
55 
56     /**
57      * Publishes a common event.
58      *
59      * @param event Indicates the common event data.
60      * @param publishInfo Indicates the publish info.
61      * @param commonEventListener Indicates the last subscriber to receive the event.
62      * @param uid Indicates the uid.
63      * @param callerToken Indicates the caller token.
64      * @param userId Indicates the user ID.
65      * @return Returns true if successful; false otherwise.
66      */
67     bool PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
68         const sptr<IRemoteObject> &commonEventListener, const uid_t &uid, const int32_t &callerToken,
69         const int32_t &userId) override;
70 
71     /**
72      * Subscribes to common events.
73      *
74      * @param subscribeInfo Indicates the subscribe information.
75      * @param commonEventListener Indicates the subscriber object.
76      * @param instanceKey Indicates the instance key
77      * @return Returns ERR_OK if successful; otherwise failed.
78      */
79     int32_t SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
80         const sptr<IRemoteObject> &commonEventListener, const int32_t instanceKey = 0) override;
81 
82     /**
83      * Unsubscribes from common events.
84      *
85      * @param commonEventListener Indicates the subscriber object.
86      * @return Returns ERR_OK if successful; otherwise failed.
87      */
88     int32_t UnsubscribeCommonEvent(const sptr<IRemoteObject> &commonEventListener) override;
89 
90     /**
91      * Synchronized, unsubscribes from common events.
92      *
93      * @param commonEventListener Indicates the subscriber object
94      * @return Returns true if successful; false otherwise.
95      */
96     int32_t UnsubscribeCommonEventSync(const sptr<IRemoteObject> &commonEventListener) override;
97 
98     /**
99      * Gets the current sticky common event.
100      *
101      * @param event Indicates the common event.
102      * @param eventData Indicates the common event data.
103      * @return Returns true if successful; false otherwise.
104      */
105     bool GetStickyCommonEvent(const std::string &event, CommonEventData &eventData) override;
106 
107     /**
108      * Dumps the state for common event service.
109      *
110      * @param dumpType Indicates the dump type.
111      * @param event Indicates the specified event.
112      * @param userId Indicates the user id.
113      * @param state Indicates the output result.
114      * @return Returns true if successful; false otherwise.
115      */
116     bool DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
117         std::vector<std::string> &state) override;
118 
119     /**
120      * Finishes the receiver for the ordered common event.
121      *
122      * @param proxy Indicates the current subscriber object.
123      * @param code Indicates the result code.
124      * @param receiverData Indicates the result data.
125      * @param abortEvent Indicates whether the current ordered common event should be aborted.
126      * @return Returns true if successful; false otherwise.
127      */
128     bool FinishReceiver(const sptr<IRemoteObject> &proxy, const int32_t &code,
129         const std::string &receiverData, const bool &abortEvent) override;
130 
131     /**
132      * Freezes the specified process.
133      *
134      * @param uid Indicates the uid of frozen process.
135      * @return Returns true if successful; false otherwise.
136      */
137     bool Freeze(const uid_t &uid) override;
138 
139     /**
140      * Unfreezes the specified process.
141      *
142      * @param uid Indicates the uid of unfrozen process.
143      * @return Returns true if successful; false otherwise.
144      */
145     bool Unfreeze(const uid_t &uid) override;
146 
147     /**
148      * Unfreezes all frozen applications.
149      *
150      * @return Returns true if successful; false otherwise.
151      */
152     bool UnfreezeAll() override;
153 
154     /**
155      * Remove sticky common event.
156      *
157      * @param event Name of the common event.
158      * @return Returns ERR_OK if success; otherwise failed.
159      */
160     int32_t RemoveStickyCommonEvent(const std::string &event) override;
161 
162     /**
163      * Set Static Subscriber State.
164      *
165      * @param enable static subscriber state.
166      * @return Returns ERR_OK if success; otherwise failed.
167      */
168     int32_t SetStaticSubscriberState(bool enable) override;
169 
170     /**
171      * Set static subscriber state.
172      *
173      * @param events Static subscriber event name.
174      * @param enable Static subscriber state.
175      * @return Returns ERR_OK if success; otherwise failed.
176      */
177     int32_t SetStaticSubscriberState(const std::vector<std::string> &events, bool enable) override;
178 
179     /**
180     * Set freeze status of process.
181     *
182     * @param pidList Indicates the list of process id.
183     * @param isFreeze Indicates wheather the process is freezed.
184     * @return Returns true if successful; false otherwise.
185     */
186     bool SetFreezeStatus(std::set<int> pidList, bool isFreeze) override;
187 
188 private:
189     DISALLOW_COPY_AND_MOVE(CommonEventStub);
190 };
191 }  // namespace EventFwk
192 }  // namespace OHOS
193 
194 #endif  // FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_STUB_H
195