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