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