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