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