1 /* 2 * Copyright (c) 2021-2022 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_ABILITY_SCHEDULE_PROXY_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_SCHEDULE_PROXY_H 18 19 #include "ability_scheduler_interface.h" 20 21 #include <iremote_proxy.h> 22 23 namespace OHOS { 24 namespace NativeRdb { 25 class AbsSharedResultSet; 26 class DataAbilityPredicates; 27 class ValuesBucket; 28 } // namespace NativeRdb 29 namespace AppExecFwk { 30 } // namespace AppExecFwk 31 namespace AAFwk { 32 /** 33 * @class AbilitySchedulerProxy 34 * AbilityScheduler proxy. 35 */ 36 class AbilitySchedulerProxy : public IRemoteProxy<IAbilityScheduler> { 37 public: AbilitySchedulerProxy(const sptr<IRemoteObject> & impl)38 explicit AbilitySchedulerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAbilityScheduler>(impl) 39 {} 40 ~AbilitySchedulerProxy()41 virtual ~AbilitySchedulerProxy() 42 {} 43 44 /* 45 * ScheduleAbilityTransaction, schedule ability to transform life state. 46 * 47 * @param Want, Special Want for service type's ability. 48 * @param stateInfo, The lifecycle state to be transformed 49 */ 50 void ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo) override; 51 52 /* 53 * SendResult, Send result to app when ability is terminated with result want. 54 * 55 * @param requestCode, the requestCode of the ability to start. 56 * @param resultCode, the resultCode of the ability to terminate. 57 * @param resultWant, the want of the ability to terminate. 58 */ 59 void SendResult(int requestCode, int resultCode, const Want &resultWant) override; 60 61 /* 62 * ScheduleConnectAbility, schedule service ability to connect. 63 * 64 * @param Want, Special Want for service type's ability. 65 */ 66 void ScheduleConnectAbility(const Want &want) override; 67 68 /* 69 * ScheduleDisconnectAbility, schedule service ability to disconnect. 70 */ 71 void ScheduleDisconnectAbility(const Want &want) override; 72 73 /* 74 * ScheduleCommandAbility, schedule service ability to command. 75 */ 76 void ScheduleCommandAbility(const Want &want, bool restart, int startId) override; 77 78 /* 79 * ScheduleSaveAbilityState, scheduling save ability state. 80 */ 81 void ScheduleSaveAbilityState() override; 82 83 /* 84 * ScheduleRestoreAbilityState, scheduling restore ability state. 85 */ 86 void ScheduleRestoreAbilityState(const PacMap &inState) override; 87 88 /** 89 * @brief Obtains the MIME types of files supported. 90 * 91 * @param uri Indicates the path of the files to obtain. 92 * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null. 93 * 94 * @return Returns the matched MIME types. If there is no match, null is returned. 95 */ 96 virtual std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) override; 97 98 /** 99 * @brief Opens a file in a specified remote path. 100 * 101 * @param uri Indicates the path of the file to open. 102 * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access 103 * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file, 104 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data, 105 * or "rwt" for read and write access that truncates any existing file. 106 * 107 * @return Returns the file descriptor. 108 */ 109 virtual int OpenFile(const Uri &uri, const std::string &mode) override; 110 111 /** 112 * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets 113 * inside of their .hap. 114 * 115 * @param uri Indicates the path of the file to open. 116 * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access 117 * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file, 118 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing 119 * data, or "rwt" for read and write access that truncates any existing file. 120 * 121 * @return Returns the RawFileDescriptor object containing file descriptor. 122 */ 123 virtual int OpenRawFile(const Uri &uri, const std::string &mode) override; 124 125 /** 126 * @brief Inserts a single data record into the database. 127 * 128 * @param uri Indicates the path of the data to operate. 129 * @param value Indicates the data record to insert. If this parameter is null, a blank row will be inserted. 130 * 131 * @return Returns the index of the inserted data record. 132 */ 133 virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override; 134 135 /** 136 * @brief Calls the method of the Data ability. 137 * 138 * @param uri Indicates the Data ability of the method to call. 139 * @param method Indicates the method to call. 140 * @param arg Indicates the parameter of the String type. 141 * @param pacMap Defines a PacMap object for storing a series of values. 142 * 143 * @return Returns the call result. 144 */ 145 virtual std::shared_ptr<AppExecFwk::PacMap> Call( 146 const Uri &uri, const std::string &method, const std::string &arg, const AppExecFwk::PacMap &pacMap) override; 147 148 /** 149 * @brief Updates data records in the database. 150 * 151 * @param uri Indicates the path of data to update. 152 * @param value Indicates the data to update. This parameter can be null. 153 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. 154 * 155 * @return Returns the number of data records updated. 156 */ 157 virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value, 158 const NativeRdb::DataAbilityPredicates &predicates) override; 159 160 /** 161 * @brief Deletes one or more data records from the database. 162 * 163 * @param uri Indicates the path of the data to operate. 164 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. 165 * 166 * @return Returns the number of data records deleted. 167 */ 168 virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override; 169 170 /** 171 * @brief Deletes one or more data records from the database. 172 * 173 * @param uri Indicates the path of data to query. 174 * @param columns Indicates the columns to query. If this parameter is null, all columns are queried. 175 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null. 176 * 177 * @return Returns the query result. 178 */ 179 virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query( 180 const Uri &uri, std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) override; 181 182 /** 183 * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be 184 * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG. 185 * 186 * @param uri Indicates the URI of the data. 187 * 188 * @return Returns the MIME type that matches the data specified by uri. 189 */ 190 std::string GetType(const Uri &uri) override; 191 192 /** 193 * @brief Reloads data in the database. 194 * 195 * @param uri Indicates the position where the data is to reload. This parameter is mandatory. 196 * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This 197 * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across 198 * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object. 199 * 200 * @return Returns true if the data is successfully reloaded; returns false otherwise. 201 */ 202 bool Reload(const Uri &uri, const PacMap &extras) override; 203 204 /** 205 * @brief Inserts multiple data records into the database. 206 * 207 * @param uri Indicates the path of the data to operate. 208 * @param values Indicates the data records to insert. 209 * 210 * @return Returns the number of data records inserted. 211 */ 212 int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) override; 213 214 /** 215 * @brief Registers an observer to DataObsMgr specified by the given Uri. 216 * 217 * @param uri, Indicates the path of the data to operate. 218 * @param dataObserver, Indicates the IDataAbilityObserver object. 219 * 220 * @return Return true if success. otherwise return false. 221 */ 222 bool ScheduleRegisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver) override; 223 224 /** 225 * @brief Deregisters an observer used for DataObsMgr specified by the given Uri. 226 * 227 * @param uri, Indicates the path of the data to operate. 228 * @param dataObserver, Indicates the IDataAbilityObserver object. 229 * 230 * @return Return true if success. otherwise return false. 231 */ 232 bool ScheduleUnregisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver) override; 233 234 /** 235 * @brief Notifies the registered observers of a change to the data resource specified by Uri. 236 * 237 * @param uri, Indicates the path of the data to operate. 238 * 239 * @return Return true if success. otherwise return false. 240 */ 241 bool ScheduleNotifyChange(const Uri &uri) override; 242 243 /** 244 * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used 245 * across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the 246 * context has changed. If you implement URI normalization for a Data ability, you must also implement 247 * denormalizeUri(ohos.utils.net.Uri) to enable URI denormalization. After this feature is enabled, URIs passed to 248 * any method that is called on the Data ability must require normalization verification and denormalization. The 249 * default implementation of this method returns null, indicating that this Data ability does not support URI 250 * normalization. 251 * 252 * @param uri Indicates the Uri object to normalize. 253 * 254 * @return Returns the normalized Uri object if the Data ability supports URI normalization; returns null otherwise. 255 */ 256 Uri NormalizeUri(const Uri &uri) override; 257 258 /** 259 * @brief Converts the given normalized uri generated by normalizeUri(ohos.utils.net.Uri) into a denormalized one. 260 * The default implementation of this method returns the original URI passed to it. 261 * 262 * @param uri uri Indicates the Uri object to denormalize. 263 * 264 * @return Returns the denormalized Uri object if the denormalization is successful; returns the original Uri passed 265 * to this method if there is nothing to do; returns null if the data identified by the original Uri cannot be found 266 * in the current environment. 267 */ 268 Uri DenormalizeUri(const Uri &uri) override; 269 270 /** 271 * @brief Performs batch operations on the database. 272 * 273 * @param operations Indicates a list of database operations on the database. 274 * @return Returns the result of each operation, in array. 275 */ 276 std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> ExecuteBatch( 277 const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> &operations) override; 278 279 /** 280 * ContinueAbility, call ContinueAbility() through proxy project, 281 * Notify continue ability. 282 * 283 * @param deviceId Target deviceId. 284 * @param versionCode Target bundle version. 285 * @return 286 */ 287 void ContinueAbility(const std::string& deviceId, uint32_t versionCode) override; 288 289 /** 290 * NotifyContinuationResult, call NotifyContinuationResult() through proxy project, 291 * Notify continuation result to ability. 292 * 293 * @param The continuation result. 294 * @return 295 */ 296 void NotifyContinuationResult(int32_t result) override; 297 298 /** 299 * Dump Ability Runner info. 300 * 301 * @param 302 * @return Ability Runner info. 303 */ 304 void DumpAbilityInfo(const std::vector<std::string> ¶ms, std::vector<std::string> &info) override; 305 void CallRequest() override; 306 307 #ifdef ABILITY_COMMAND_FOR_TEST 308 int BlockAbility() override; 309 #endif 310 311 private: 312 bool WriteInterfaceToken(MessageParcel &data); 313 314 private: 315 static inline BrokerDelegator<AbilitySchedulerProxy> delegator_; 316 }; 317 } // namespace AAFwk 318 } // namespace OHOS 319 #endif // OHOS_ABILITY_RUNTIME_ABILITY_SCHEDULE_PROXY_H 320