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