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 OHOS_ABILITY_RUNTIME_DATAOBS_MGR_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_PROXY_H 18 19 #include "dataobs_mgr_interface.h" 20 #include "iremote_proxy.h" 21 #include "dataobs_mgr_errors.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 /** 26 * @class DataObsManagerProxy 27 * DataObsManagerProxy. 28 */ 29 class DataObsManagerProxy : public IRemoteProxy<IDataObsMgr> { 30 public: DataObsManagerProxy(const sptr<IRemoteObject> & impl)31 explicit DataObsManagerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDataObsMgr>(impl) 32 {} 33 ~DataObsManagerProxy()34 virtual ~DataObsManagerProxy() 35 {} 36 37 /** 38 * Registers an observer to DataObsMgr specified by the given Uri. 39 * 40 * @param uri, Indicates the path of the data to operate. 41 * @param dataObserver, Indicates the IDataAbilityObserver object. 42 * 43 * @return Returns ERR_OK on success, others on failure. 44 */ 45 46 virtual int RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 47 int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, DataObsOption opt = DataObsOption()) override; 48 49 virtual int RegisterObserverFromExtension(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 50 int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, DataObsOption opt = DataObsOption()) override; 51 52 /** 53 * Deregisters an observer used for DataObsMgr specified by the given Uri. 54 * 55 * @param uri, Indicates the path of the data to operate. 56 * @param dataObserver, Indicates the IDataAbilityObserver object. 57 * 58 * @return Returns ERR_OK on success, others on failure. 59 */ 60 virtual int UnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 61 int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, DataObsOption opt = DataObsOption()) override; 62 63 /** 64 * Notifies the registered observers of a change to the data resource specified by Uri. 65 * 66 * @param uri, Indicates the path of the data to operate. 67 * 68 * @return Returns ERR_OK on success, others on failure. 69 */ 70 virtual int NotifyChange(const Uri &uri, int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, 71 DataObsOption opt = DataObsOption()) override; 72 73 /** 74 * Notifies the registered observers of a change to the data resource specified by Uri. 75 * 76 * @param uri, Indicates the path of the data to operate. 77 * 78 * @return Returns ERR_OK on success, others on failure. 79 */ 80 virtual int NotifyChangeFromExtension(const Uri &uri, int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, 81 DataObsOption opt = DataObsOption()) override; 82 83 virtual int CheckTrusts(uint32_t consumerToken, uint32_t providerToken) override; 84 85 /** 86 * Registers an observer to DataObsMgr specified by the given Uri. 87 * 88 * @param uri, Indicates the path of the data to operate. 89 * @param dataObserver, Indicates the IDataAbilityObserver object. 90 * @param isDescendants, Indicates the Whether to note the change of descendants. 91 * 92 * @return Returns SUCCESS on success, others on failure. 93 */ 94 virtual Status RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 95 bool isDescendants, DataObsOption opt = DataObsOption()) override; 96 97 /** 98 * Deregisters an observer used for DataObsMgr specified by the given Uri. 99 * 100 * @param uri, Indicates the path of the data to operate. 101 * @param dataObserver, Indicates the IDataAbilityObserver object. 102 * 103 * @return Returns SUCCESS on success, others on failure. 104 */ 105 virtual Status UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 106 DataObsOption opt = DataObsOption()) override; 107 108 /** 109 * Deregisters dataObserver used for DataObsMgr specified 110 * 111 * @param dataObserver, Indicates the IDataAbilityObserver object. 112 * 113 * @return Returns SUCCESS on success, others on failure. 114 */ 115 virtual Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver, 116 DataObsOption opt = DataObsOption()) override; 117 118 /** 119 * Notifies the registered observers of a change to the data resource specified by Uris. 120 * 121 * @param changeInfo Indicates the info of the data to operate. 122 * 123 * @return Returns SUCCESS on success, others on failure. 124 */ 125 virtual Status NotifyChangeExt(const ChangeInfo &changeInfo, DataObsOption opt = DataObsOption()) override; 126 127 /** 128 * Notifies the process observer with the given progress key and cancel observer. 129 * 130 * @param key Identifies the progress of a specific task. 131 132 * @param observer Observer for monitoring the ongoing process. 133 * 134 * @return Returns SUCCESS on success, others on failure. 135 */ 136 virtual Status NotifyProcessObserver(const std::string &key, const sptr<IRemoteObject> &observer, 137 DataObsOption opt = DataObsOption()) override; 138 139 private: 140 bool WriteInterfaceToken(MessageParcel &data); 141 bool WriteParam(MessageParcel &data, const Uri &uri, sptr<IDataAbilityObserver> dataObserver); 142 bool WriteObsOpt(MessageParcel &data, DataObsOption opt); 143 int SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 144 145 private: 146 static inline BrokerDelegator<DataObsManagerProxy> delegator_; 147 }; 148 } // namespace AAFwk 149 } // namespace OHOS 150 #endif // OHOS_ABILITY_RUNTIME_DATAOBS_MGR_PROXY_H 151