1 /* 2 * Copyright (c) 2021 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_INTERFACE_H 17 #define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INTERFACE_H 18 19 #include <vector> 20 21 #include <ipc_types.h> 22 #include <iremote_broker.h> 23 24 #include "data_ability_observer_interface.h" 25 #include "dataobs_mgr_errors.h" 26 #include "uri.h" 27 28 namespace OHOS { 29 namespace AAFwk { 30 using Uri = OHOS::Uri; 31 constexpr const char* DATAOBS_MANAGER_SERVICE_NAME = "DataObsMgrService"; 32 33 struct DataObsOption { 34 private: 35 bool isSystem = false; 36 uint32_t firstCallerTokenID = 0; 37 public: DataObsOptionDataObsOption38 DataObsOption() {} DataObsOptionDataObsOption39 DataObsOption(bool isSystem):isSystem(isSystem) {} IsSystemDataObsOption40 bool IsSystem() 41 { 42 return isSystem; 43 } FirstCallerTokenIDDataObsOption44 uint32_t FirstCallerTokenID() 45 { 46 return firstCallerTokenID; 47 } SetFirstCallerTokenIDDataObsOption48 void SetFirstCallerTokenID(uint32_t token) 49 { 50 firstCallerTokenID = token; 51 } 52 }; 53 54 /** 55 * @class IDataObsMgr 56 * IDataObsMgr interface is used to access dataobs manager services. 57 */ 58 class IDataObsMgr : public OHOS::IRemoteBroker { 59 public: 60 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.DataObsMgr") 61 62 enum { 63 TRANS_HEAD, 64 REGISTER_OBSERVER = TRANS_HEAD, 65 UNREGISTER_OBSERVER, 66 NOTIFY_CHANGE, 67 REGISTER_OBSERVER_EXT, 68 UNREGISTER_OBSERVER_EXT, 69 UNREGISTER_OBSERVER_ALL_EXT, 70 NOTIFY_CHANGE_EXT, 71 NOTIFY_PROCESS, 72 REGISTER_OBSERVER_FROM_EXTENSION, 73 NOTIFY_CHANGE_FROM_EXTENSION, 74 CHECK_TRUSTS, 75 TRANS_BUTT, 76 }; 77 78 static constexpr int DATAOBS_DEFAULT_CURRENT_USER = -1; 79 80 /** 81 * Registers an observer to DataObsMgr specified by the given Uri. 82 * 83 * @param uri, Indicates the path of the data to operate. 84 * @param dataObserver, Indicates the IDataAbilityObserver object. 85 * 86 * @return Returns ERR_OK on success, others on failure. 87 */ 88 virtual int RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 89 int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, 90 DataObsOption opt = DataObsOption()) = 0; 91 92 /** 93 * Registers an observer to DataObsMgr specified by the given Uri. 94 * 95 * @param uri, Indicates the path of the data to operate. 96 * @param dataObserver, Indicates the IDataAbilityObserver object. 97 * 98 * @return Returns ERR_OK on success, others on failure. 99 */ 100 virtual int RegisterObserverFromExtension(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 101 int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, DataObsOption opt = DataObsOption()) = 0; 102 103 /** 104 * Deregisters an observer used for DataObsMgr specified by the given Uri. 105 * 106 * @param uri, Indicates the path of the data to operate. 107 * @param dataObserver, Indicates the IDataAbilityObserver object. 108 * 109 * @return Returns ERR_OK on success, others on failure. 110 */ 111 virtual int UnregisterObserver(const Uri &uri, 112 sptr<IDataAbilityObserver> dataObserver, int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, 113 DataObsOption opt = DataObsOption()) = 0; 114 115 /** 116 * Notifies the registered observers of a change to the data resource specified by Uri. 117 * 118 * @param uri, Indicates the path of the data to operate. 119 * 120 * @return Returns ERR_OK on success, others on failure. 121 */ 122 virtual int NotifyChange(const Uri &uri, int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, 123 DataObsOption opt = DataObsOption()) = 0; 124 125 /** 126 * Notifies the registered observers of a change to the data resource specified by Uri. 127 * 128 * @param uri, Indicates the path of the data to operate. 129 * 130 * @return Returns ERR_OK on success, others on failure. 131 */ 132 virtual int NotifyChangeFromExtension(const Uri &uri, int32_t userId = DATAOBS_DEFAULT_CURRENT_USER, 133 DataObsOption opt = DataObsOption()) = 0; 134 135 virtual ErrCode CheckTrusts(uint32_t consumerToken, uint32_t providerToken) = 0; 136 137 /** 138 * Registers an observer to DataObsMgr specified by the given Uri. 139 * 140 * @param uri, Indicates the path of the data to operate. 141 * @param dataObserver, Indicates the IDataAbilityObserver object. 142 * @param isDescendants, Indicates the Whether to note the change of descendants. 143 * 144 * @return Returns SUCCESS on success, others on failure. 145 */ 146 virtual Status RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, bool isDescendants, 147 DataObsOption opt = DataObsOption()) = 0; 148 149 /** 150 * Deregisters an observer used for DataObsMgr specified by the given Uri. 151 * 152 * @param uri, Indicates the path of the data to operate. 153 * @param dataObserver, Indicates the IDataAbilityObserver object. 154 * 155 * @return Returns SUCCESS on success, others on failure. 156 */ 157 virtual Status UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, 158 DataObsOption opt = DataObsOption()) = 0; 159 160 /** 161 * Deregisters dataObserver used for DataObsMgr specified 162 * 163 * @param dataObserver, Indicates the IDataAbilityObserver object. 164 * 165 * @return Returns SUCCESS on success, others on failure. 166 */ 167 virtual Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver, 168 DataObsOption opt = DataObsOption()) = 0; 169 170 /** 171 * Notifies the registered observers of a change to the data resource specified by Uris. 172 * 173 * @param changeInfo Indicates the info of the data to operate. 174 * 175 * @return Returns SUCCESS on success, others on failure. 176 */ 177 virtual Status NotifyChangeExt(const ChangeInfo &changeInfo, DataObsOption opt = DataObsOption()) = 0; 178 179 /** 180 * Notifies the process observer with the given progress key and cancel observer. 181 * 182 * @param key Identifies the progress of a specific task. 183 184 * @param observer Observer for monitoring the ongoing process. 185 * 186 * @return Returns SUCCESS on success, others on failure. 187 */ 188 virtual Status NotifyProcessObserver(const std::string &key, const sptr<IRemoteObject> &observer, 189 DataObsOption opt = DataObsOption()) = 0; 190 }; 191 } // namespace AAFwk 192 } // namespace OHOS 193 #endif // OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INTERFACE_H 194